|
@@ -1,12 +1,9 @@
|
|
-import Alt
|
|
|
|
-import uuid
|
|
|
|
-import tomlkit, sqlite3
|
|
|
|
|
|
+import Alt, WithSqlite
|
|
|
|
+import tomlkit
|
|
|
|
|
|
-# Place for uid
|
|
|
|
|
|
+# Placeholder for uid related
|
|
|
|
|
|
-
|
|
|
|
-# ----- Methods binding app command to model -----
|
|
|
|
-# Toml
|
|
|
|
|
|
+# Toml Methods
|
|
def GetTomlDoc(tomlName):
|
|
def GetTomlDoc(tomlName):
|
|
try:
|
|
try:
|
|
with open(tomlName, "rb") as t:
|
|
with open(tomlName, "rb") as t:
|
|
@@ -64,55 +61,17 @@ def MatchTomlKeys(tomlName, keys, table=None) -> list:
|
|
return rl
|
|
return rl
|
|
|
|
|
|
|
|
|
|
-# Sqlite3
|
|
|
|
-def Exist_in_sqlite3(tableName, columnName=None, recordName=None):
|
|
|
|
- if columnName == None:
|
|
|
|
- s = "SELECT name FROM sqlite_master WHERE type='table' AND name='{tableName}';".format(tableName = tableName)
|
|
|
|
-
|
|
|
|
- if columnName != None:
|
|
|
|
- s = "SELECT * FROM {tableName} WHERE {columnName}={recordName}".format(tableName = tableName, columnName = columnName, recordName = recordName)
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-def Operate_sqlite3(dbPath, match_commands):
|
|
|
|
- matchedSyntax = MatchTomlKeys("dev_config.toml", match_commands, "sqlite3")
|
|
|
|
-
|
|
|
|
- # 需要检查的类型
|
|
|
|
- # Board, 禁止重复
|
|
|
|
- # Class, 重复就update一个引用关系
|
|
|
|
- # Event, 同一个Board里面不允许重复, 不同Board里可以重复
|
|
|
|
-
|
|
|
|
- s = "".join(matchedSyntax).format(tableName = match_commands[1], objName = match_commands[2])
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- con = sqlite3.connect(dbPath)
|
|
|
|
- cur = con.cursor()
|
|
|
|
-
|
|
|
|
- # is_exist()
|
|
|
|
- res = cur.execute(s).fetchall()
|
|
|
|
- # ret = res.fetchall()
|
|
|
|
- # if res = None:
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- con.close()
|
|
|
|
- return res
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-# Markdown
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-# csv
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-# MongoDB
|
|
|
|
-
|
|
|
|
-
|
|
|
|
# ----- Transit Command Handler -----
|
|
# ----- Transit Command Handler -----
|
|
-def PackHandler(app_commands):
|
|
|
|
|
|
+def Handler(app_commands):
|
|
dbType = app_commands[-1]
|
|
dbType = app_commands[-1]
|
|
dbPath = app_commands[-2]
|
|
dbPath = app_commands[-2]
|
|
|
|
+ # 检查dbPath是否是dbType, 否的话报错并exit()
|
|
|
|
+
|
|
|
|
+ exec_commands = app_commands[0:-2]
|
|
|
|
|
|
if dbType == "sqlite3":
|
|
if dbType == "sqlite3":
|
|
- return Operate_sqlite3(dbPath, app_commands)
|
|
|
|
|
|
+ WithSqlite.Regular(dbPath, exec_commands)
|
|
|
|
+
|
|
|
|
|
|
elif dbType == "csv":
|
|
elif dbType == "csv":
|
|
pass
|
|
pass
|
|
@@ -139,5 +98,5 @@ if __name__ == "__main__":
|
|
e_c = ['add', 'board']
|
|
e_c = ['add', 'board']
|
|
|
|
|
|
# Operate_sqlite3("test.db", a_c1)
|
|
# Operate_sqlite3("test.db", a_c1)
|
|
- PackHandler(a_c2)
|
|
|
|
|
|
+ Handler(a_c2)
|
|
|
|
|