Browse Source

- 脑子跟不上函数的跳转了

NandHyf 1 year ago
parent
commit
0b609354ed
6 changed files with 46 additions and 35 deletions
  1. 4 3
      Controller.py
  2. 27 29
      Stateful.py
  3. 0 1
      View.py
  4. BIN
      __pycache__/Stateful.cpython-311.pyc
  5. 2 2
      debug_backlog.txt
  6. 13 0
      dev_config.toml

+ 4 - 3
Controller.py

@@ -25,8 +25,9 @@ class Client():
         # do while or for (1)
         while(1):
             app_command = input(currentPath + "/: ", ).split(" ")
-            # Syntax check
-
+            # Input exception check
+            
+            # Add DBType && Path
             app_command.append(dbPath)
             app_command.append(dbType)
             Stateful.TransitHandler(app_command)
@@ -43,7 +44,7 @@ class Client():
 
         # ↑↑↑ test code here ↑↑↑
 
-        # Normalized Start Process
+        # 2. Normalized Start Process
         startState = Stateful.TransitHandler(['list', 'board', dbPath, dbType])
         print(startState)
         Client.TransitCommand()

+ 27 - 29
Stateful.py

@@ -12,10 +12,9 @@ def generate_uid(kw):
     return(uid)
 
 
-# ----- Methods binding command to model -----
-
+# ----- Methods binding app command to model -----
 # Toml
-def getTomlDoc(tomlName):
+def GetTomlDoc(tomlName):
     try:
         with open(tomlName, "rb") as t:
             doc = tomlkit.load(t)
@@ -31,8 +30,8 @@ def getTomlDoc(tomlName):
         exit()
     
 
-def matchTomlKey(tomlName, key, table=None) -> str:
-    doc = getTomlDoc(tomlName)
+def MatchTomlKey(tomlName, key, table=None) -> str:
+    doc = GetTomlDoc(tomlName)
 
     if table == None:
         return str(doc.item(key))
@@ -42,8 +41,9 @@ def matchTomlKey(tomlName, key, table=None) -> str:
         return str(d[table][key])
 
 
-def matchTomlKeys(tomlName, keys, table=None) -> list:
-    doc = getTomlDoc(tomlName)
+# no differernt between ↑ MatchTomlKey() ↑ except receives and returns in list
+def MatchTomlKeys(tomlName, keys, table=None) -> list:
+    doc = GetTomlDoc(tomlName)
 
     if table == None:
         # rl == 'r'eturn 'l'ist
@@ -69,25 +69,15 @@ def matchTomlKeys(tomlName, keys, table=None) -> list:
 
 
 # Sqlite3
-def operate_sqlite3(dbPath, command):
-    con = sqlite3.connect(dbPath)
-    cur = con.cursor()
+def Operate_sqlite3(dbPath, dbType, match_commands):
+    matchedSyntax = MatchTomlKeys("dev_config.toml", match_commands, dbType)
 
-    # list -> .TABLES
-    if command[0] == "list" and command[1] == "board":
-        cur.execute("SELECT name FROM sqlite_master WHERE type='table';")
-        print(cur.fetchall())
-    # add -> CREATE
-    elif command[0] == "add" and command[1] == "board":
-        cur.execute('''        ''')
+    s = " "
 
-    # add -> INSERT INTO
-
-    # edit -> UPDATE
-
-    # delete -> UPDATE(status -> 'deleted')
+    con = sqlite3.connect(dbPath)
+    cur = con.cursor()
     
-    cur.close()
+    con.close()
 
 
 # Markdown
@@ -100,13 +90,13 @@ def operate_sqlite3(dbPath, command):
 
 
 # ----- Transit Command Handler -----
-def TransitHandler(transit_command):
-    dbType = transit_command[-1]
-    dbPath = transit_command[-2]
-    exec_command = transit_command[0:-2]
+def TransitHandler(transit_commands):
+    dbType = transit_commands[-1]
+    dbPath = transit_commands[-2]
+    match_commands = transit_commands[0:-2]
 
     if dbType == "sqlite3":
-        operate_sqlite3(dbPath, exec_command)
+        Operate_sqlite3(dbPath, dbType, match_commands)
 
     elif dbType == "csv":
         pass
@@ -122,4 +112,12 @@ def TransitHandler(transit_command):
 
     else:
         input("error 1: could not found correct Data Base")
-        exit()
+        exit()
+
+
+if __name__ == "__main__":
+    
+    a_c = ['add', 'board']
+    e_c = ['add', 'board']
+    Operate_sqlite3("test.db", "sqlite3", e_c)
+    

+ 0 - 1
View.py

@@ -1 +0,0 @@
-

BIN
__pycache__/Stateful.cpython-311.pyc


+ 2 - 2
debug_backlog.txt

@@ -1,11 +1,11 @@
 # ----- config.toml -----
-1. DBPath 是否支持填写路径/绝对路径/相对路径
+1. DBPath 是否支持填写路径/绝对路径/相对路径: 第一版只支持当前目录吧, 后面再说其他目录和multi的情况
 
 # ----- Controller.py -----
 1. app_command 输入不合法字符的异常处理
 2. 原本该在Focus模式工作的SELECT出现在全局命令里的异常处理
 
 # ----- Stateful.py -----
-1. 读取toml文件时候没有匹配到键的异常处理 
+1. 读取toml文件时候没有匹配到键的异常处理: 已解决(通过table=None的参数)
 
 # ----- Alt.py -----

+ 13 - 0
clean_config.toml → dev_config.toml

@@ -8,7 +8,20 @@ displayTime = "utc+8"
 
 # ----- App Command to DB Syntax Translation -----
 [sqlite3]
+# app_command[0] -> command1
+"/" = "SELECT name FROM sqlite_master WHERE type='table';"
 list = "SELECT"
 add = "INSERT INTO"
 edit = "UPDATE"
 delete = "UPDATE" # change stauts to "deleted"
+
+# app_command[1] -> obj1
+board = "TABLE {boardName} "
+class = ""
+event = ""
+
+# app_command[2] -> tag1
+"-name" = ""
+"-d" = ""
+"-ddl" = ""
+to = ""