Allow to store field in json table
This commit is contained in:
parent
0ddc1e47ba
commit
f21fdb23b6
1 changed files with 15 additions and 8 deletions
21
src/Db/Db.py
21
src/Db/Db.py
|
@ -221,7 +221,8 @@ class Db(object):
|
|||
else:
|
||||
commit_after_done = False
|
||||
|
||||
# Row for current json file
|
||||
# Row for current json file if required
|
||||
if filter(lambda map: "to_keyvalue" in map or "to_table" in map, matched_maps):
|
||||
json_row = cur.getJsonRow(relative_path)
|
||||
|
||||
# Check matched mappings in schema
|
||||
|
@ -248,12 +249,18 @@ class Db(object):
|
|||
(data.get(key), current_keyvalue_id[key])
|
||||
)
|
||||
|
||||
"""
|
||||
for key in map.get("to_keyvalue", []):
|
||||
cur.execute("INSERT OR REPLACE INTO keyvalue ?",
|
||||
{"key": key, "value": data.get(key), "json_id": json_row["json_id"]}
|
||||
)
|
||||
"""
|
||||
# Insert data to json table for easier joins
|
||||
if map.get("to_json_table"):
|
||||
directory, file_name = re.match("^(.*?)/*([^/]*)$", relative_path).groups()
|
||||
data_json_row = dict(cur.getJsonRow(directory + "/" + map.get("file_name", file_name)))
|
||||
changed = False
|
||||
for key in map["to_json_table"]:
|
||||
if data.get(key) != data_json_row.get(key):
|
||||
changed = True
|
||||
if changed:
|
||||
# Add the custom col values
|
||||
data_json_row.update({key: val for key, val in data.iteritems() if key in map["to_json_table"]})
|
||||
cur.execute("INSERT OR REPLACE INTO json ?", data_json_row)
|
||||
|
||||
# Insert data to tables
|
||||
for table_settings in map.get("to_table", []):
|
||||
|
|
Loading…
Reference in a new issue