saveRow and readRow genericized and working
This commit is contained in:
+113
-16
@@ -46,20 +46,117 @@ def loadSave(action, outputs):
|
||||
print(f"Data loaded by {action.name} from {action.savepath}")
|
||||
return outputs
|
||||
|
||||
def buildSave2(action, outputs):
|
||||
|
||||
database.execute("""
|
||||
CREATE TABLE IF NOT EXISTS message_mapping (
|
||||
rmass_message_id INTEGER PRIMARY KEY,
|
||||
matrix_event_id TEXT NOT NULL UNIQUE
|
||||
)
|
||||
""")
|
||||
database = sqlite3.connect("rmmanager.db")
|
||||
|
||||
database.execute(
|
||||
"INSERT INTO message_mapping VALUES (?, ?)",
|
||||
(action.savedata[savename], outputs["event_id"])
|
||||
)
|
||||
def saveRow(action, outputs, resolved):
|
||||
if hasattr(action, "saverow"):
|
||||
table = action.saverow["table"]
|
||||
|
||||
database.commit()
|
||||
database.close()
|
||||
columns = action.saverow["columns"]
|
||||
column_list = []
|
||||
column_creation = []
|
||||
for item in columns:
|
||||
for key, value in item.items():
|
||||
column_list.append(key)
|
||||
columnattr = ""
|
||||
columnattr = key + " " + value
|
||||
|
||||
print(columnattr)
|
||||
column_creation.append(columnattr)
|
||||
|
||||
rowitems = action.saverow["rowitems"]
|
||||
|
||||
values = []
|
||||
for item in rowitems:
|
||||
if "outputs" in item:
|
||||
value = outputs[item["outputs"]]
|
||||
elif "resolved" in item:
|
||||
value = resolved[item["resolved"]]
|
||||
|
||||
values.append(value)
|
||||
|
||||
database = sqlite3.connect("savedata/rmmanager.db")
|
||||
|
||||
columnitems = ", ".join(column_creation)
|
||||
|
||||
database.execute(f"""
|
||||
CREATE TABLE IF NOT EXISTS {table} (
|
||||
{columnitems}
|
||||
)
|
||||
""")
|
||||
|
||||
column_names = ", ".join(column_list)
|
||||
placeholders = ", ".join(["?"] * len(values))
|
||||
|
||||
database.execute(
|
||||
f"INSERT INTO {table} ({column_names}) VALUES ({placeholders})",
|
||||
tuple(values)
|
||||
)
|
||||
|
||||
database.commit()
|
||||
database.close()
|
||||
|
||||
|
||||
|
||||
def readRow(action, resolved, outputs):
|
||||
result = None
|
||||
if hasattr(action, "readrow"):
|
||||
table = action.readrow["table"]
|
||||
|
||||
columns = action.readrow["columns"]
|
||||
column_list = []
|
||||
column_creation = []
|
||||
for item in columns:
|
||||
for key, value in item.items():
|
||||
column_list.append(key)
|
||||
columnattr = ""
|
||||
columnattr = key + " " + value
|
||||
|
||||
print(columnattr)
|
||||
column_creation.append(columnattr)
|
||||
|
||||
rowsearchvalue = action.readrow["rowsearchvalue"]
|
||||
searchcolumn = action.readrow["searchcolumn"]
|
||||
|
||||
values = []
|
||||
for item in rowsearchvalue:
|
||||
if "outputs" in item:
|
||||
value = outputs[item["outputs"]]
|
||||
elif "resolved" in item:
|
||||
value = resolved[item["resolved"]]
|
||||
|
||||
values.append(value)
|
||||
|
||||
database = sqlite3.connect("savedata/rmmanager.db")
|
||||
|
||||
columnitems = ", ".join(column_creation)
|
||||
|
||||
database.execute(f"""
|
||||
CREATE TABLE IF NOT EXISTS {table} (
|
||||
{columnitems}
|
||||
)
|
||||
""")
|
||||
|
||||
cursor = database.execute(
|
||||
f"""
|
||||
SELECT * FROM {table}
|
||||
WHERE {searchcolumn} = ?
|
||||
""",
|
||||
(value,)
|
||||
)
|
||||
print("DEBUG RESOLVED TARGET ITEM")
|
||||
print(value)
|
||||
|
||||
result = cursor.fetchone()
|
||||
print(result)
|
||||
|
||||
|
||||
try:
|
||||
target = result[action.readrow["columnnumber"]]
|
||||
except TypeError:
|
||||
target = None
|
||||
print("Message ID not found in database")
|
||||
|
||||
outputs["databasetarget"] = target
|
||||
|
||||
print("READROW TEST")
|
||||
print(target)
|
||||
return resolved, outputs
|
||||
Reference in New Issue
Block a user