Fix map command overwrite
This commit is contained in:
parent
7baeb8e10f
commit
5893bbc199
1 changed files with 9 additions and 9 deletions
18
src/Db/Db.py
18
src/Db/Db.py
|
@ -256,13 +256,13 @@ class Db(object):
|
||||||
commit_after_done = False
|
commit_after_done = False
|
||||||
|
|
||||||
# Row for current json file if required
|
# Row for current json file if required
|
||||||
if filter(lambda map: "to_keyvalue" in map or "to_table" in map, matched_maps):
|
if filter(lambda dbmap: "to_keyvalue" in dbmap or "to_table" in dbmap, matched_maps):
|
||||||
json_row = cur.getJsonRow(relative_path)
|
json_row = cur.getJsonRow(relative_path)
|
||||||
|
|
||||||
# Check matched mappings in schema
|
# Check matched mappings in schema
|
||||||
for map in matched_maps:
|
for dbmap in matched_maps:
|
||||||
# Insert non-relational key values
|
# Insert non-relational key values
|
||||||
if map.get("to_keyvalue"):
|
if dbmap.get("to_keyvalue"):
|
||||||
# Get current values
|
# Get current values
|
||||||
res = cur.execute("SELECT * FROM keyvalue WHERE json_id = ?", (json_row["json_id"],))
|
res = cur.execute("SELECT * FROM keyvalue WHERE json_id = ?", (json_row["json_id"],))
|
||||||
current_keyvalue = {}
|
current_keyvalue = {}
|
||||||
|
@ -271,7 +271,7 @@ class Db(object):
|
||||||
current_keyvalue[row["key"]] = row["value"]
|
current_keyvalue[row["key"]] = row["value"]
|
||||||
current_keyvalue_id[row["key"]] = row["keyvalue_id"]
|
current_keyvalue_id[row["key"]] = row["keyvalue_id"]
|
||||||
|
|
||||||
for key in map["to_keyvalue"]:
|
for key in dbmap["to_keyvalue"]:
|
||||||
if key not in current_keyvalue: # Keyvalue not exist yet in the db
|
if key not in current_keyvalue: # Keyvalue not exist yet in the db
|
||||||
cur.execute(
|
cur.execute(
|
||||||
"INSERT INTO keyvalue ?",
|
"INSERT INTO keyvalue ?",
|
||||||
|
@ -284,20 +284,20 @@ class Db(object):
|
||||||
)
|
)
|
||||||
|
|
||||||
# Insert data to json table for easier joins
|
# Insert data to json table for easier joins
|
||||||
if map.get("to_json_table"):
|
if dbmap.get("to_json_table"):
|
||||||
directory, file_name = re.match("^(.*?)/*([^/]*)$", relative_path).groups()
|
directory, file_name = re.match("^(.*?)/*([^/]*)$", relative_path).groups()
|
||||||
data_json_row = dict(cur.getJsonRow(directory + "/" + map.get("file_name", file_name)))
|
data_json_row = dict(cur.getJsonRow(directory + "/" + dbmap.get("file_name", file_name)))
|
||||||
changed = False
|
changed = False
|
||||||
for key in map["to_json_table"]:
|
for key in dbmap["to_json_table"]:
|
||||||
if data.get(key) != data_json_row.get(key):
|
if data.get(key) != data_json_row.get(key):
|
||||||
changed = True
|
changed = True
|
||||||
if changed:
|
if changed:
|
||||||
# Add the custom col values
|
# Add the custom col values
|
||||||
data_json_row.update({key: val for key, val in data.iteritems() if key in map["to_json_table"]})
|
data_json_row.update({key: val for key, val in data.iteritems() if key in dbmap["to_json_table"]})
|
||||||
cur.execute("INSERT OR REPLACE INTO json ?", data_json_row)
|
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 dbmap.get("to_table", []):
|
||||||
if isinstance(table_settings, dict): # Custom settings
|
if isinstance(table_settings, dict): # Custom settings
|
||||||
table_name = table_settings["table"] # Table name to insert datas
|
table_name = table_settings["table"] # Table name to insert datas
|
||||||
node = table_settings.get("node", table_name) # Node keyname in data json file
|
node = table_settings.get("node", table_name) # Node keyname in data json file
|
||||||
|
|
Loading…
Reference in a new issue