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:
|
else:
|
||||||
commit_after_done = False
|
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)
|
json_row = cur.getJsonRow(relative_path)
|
||||||
|
|
||||||
# Check matched mappings in schema
|
# Check matched mappings in schema
|
||||||
|
@ -248,12 +249,18 @@ class Db(object):
|
||||||
(data.get(key), current_keyvalue_id[key])
|
(data.get(key), current_keyvalue_id[key])
|
||||||
)
|
)
|
||||||
|
|
||||||
"""
|
# Insert data to json table for easier joins
|
||||||
for key in map.get("to_keyvalue", []):
|
if map.get("to_json_table"):
|
||||||
cur.execute("INSERT OR REPLACE INTO keyvalue ?",
|
directory, file_name = re.match("^(.*?)/*([^/]*)$", relative_path).groups()
|
||||||
{"key": key, "value": data.get(key), "json_id": json_row["json_id"]}
|
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
|
# Insert data to tables
|
||||||
for table_settings in map.get("to_table", []):
|
for table_settings in map.get("to_table", []):
|
||||||
|
|
Loading…
Reference in a new issue