Browse Source

wok 不是吧又一天过去了

nandHyf 1 year ago
parent
commit
8a470b1d2b
6 changed files with 76 additions and 35 deletions
  1. 21 14
      Stateful.py
  2. BIN
      dev.db
  3. 2 2
      dev_config.toml
  4. 10 4
      direct.py
  5. 17 11
      t.py
  6. 26 4
      try.txt

+ 21 - 14
Stateful.py

@@ -4,7 +4,7 @@ import tomlkit, sqlite3
 # uid related
 
 # ----- Toml Methods -----
-def GetTomlDoc(tomlName):
+def GetTomlDoc(tomlName:str):
     try:
         with open(tomlName, "rb") as t:
             doc = tomlkit.load(t)
@@ -20,7 +20,7 @@ def GetTomlDoc(tomlName):
         exit()
     
 
-def MatchTomlKey(tomlName, key, table=None) -> str:
+def MatchTomlKey(tomlName:str, key:str, table:str=None) -> str:
     doc = GetTomlDoc(tomlName)
 
     if table == None:
@@ -32,7 +32,7 @@ def MatchTomlKey(tomlName, key, table=None) -> str:
 
 
 # no differernt between ↑ MatchTomlKey() ↑ except receives and returns in list
-def MatchTomlKeys(tomlName, keys, table=None) -> list:
+def MatchTomlKeys(tomlName:str, keys:list, table:str=None) -> list:
     doc = GetTomlDoc(tomlName)
 
     if table == None:
@@ -61,7 +61,7 @@ def MatchTomlKeys(tomlName, keys, table=None) -> list:
         return rl
     
 
-def MatchTomlTable(tomlName, tableName, returnType="list"):
+def MatchTomlTable(tomlName:str, tableName:str, returnType:str="list"):
     d = GetTomlDoc(tomlName).unwrap()
 
     if returnType == "list":
@@ -72,19 +72,20 @@ def MatchTomlTable(tomlName, tableName, returnType="list"):
     
 
 # ----- Sqlite Methods -----
-def Exec_one(dbPath, commands):
+def Exec_one(dbPath:str, commands:list):
     con = sqlite3.connect(dbPath)
     cur = con.cursor()
 
     cur.execute(commands)
     con.commit()
     re = cur.fetchall()
+    cur.close()
     con.close()
 
     return re
 
 
-def IsExist(exec_commands, returnBool=True):
+def IsExist(exec_commands:list, returnBool:bool=True):
     # [todo 4] 这里面的.capitalize()后面需要根据config.toml里面的内容判断
     # 可能也不用, 因为KBCLEV的表名和本身并无关系
     tableName = str(exec_commands[1]).capitalize()
@@ -129,8 +130,8 @@ def GenModel():# Controller里面还有一个一样的方法
     # exec
     pass
 
-
-class Cursor():
+#      ↓ 'OC' == 'Operating Cursor'
+class OC():
     def __init__(self, currentPath, previousPath, dbType, dbPath, tableName, columnName, newColumnName) -> None:
         self.cp = currentPath
         self.pp = previousPath
@@ -156,13 +157,19 @@ class Cursor():
         return res
 
 
-    def add(self, addObj="board", addType="new"):
-        # get values
-        v1 = MatchTomlTable(self.table)
-        
+    def add(self, addType="board"):
+        if addType == "board":
+            sqls = "INSERT INTO Board VALUES(null, '{name}', 'alive');".format(name=self.name)
+    
+        elif addType == "class":
+
+            sqls = "INSERT INTO Class VALUES(null, '{name}', '{usingBoard}', 'alive');".format(name=self.name, usingBoard=self.pc)
+
+        elif addType == "event":
+
+            sqls = "INSERT INTO Event VALUES(null, '{name}', );"
+
 
-        # 
-        sqls = "INSERT INTO {table} VALUES({values})".format(table=self.table, values=)
         res = Exec_one(self.dp, sqls)
 
 

BIN
dev.db


+ 2 - 2
dev_config.toml

@@ -37,7 +37,7 @@ c4 = "status"
 
 
 # ----- App Configuration -----
-SafeMode = false
+StrictMode = false
 LLM_callable = false
 
 DBType = "sqlite3"
@@ -53,4 +53,4 @@ DisplayTimeZone = "utc+8"
 # status: alive/deleted
 #                                           ↓ Don't foget to write the method(s) for it
 # ListStyle: tree/md_table/LLM_md_table/<customName>
-# [todo 4] SafeMode/StrickMode: 1. Have to be full length commands; 2. err when not exist
+# [todo 4] StrickMode: 1. Have to be full length commands; 2. err when not exist

+ 10 - 4
direct.py

@@ -1,5 +1,5 @@
 import sqlite3
-
+import Stateful
 
 def Operate_sqlite3(dbPath, commands):
 
@@ -23,7 +23,13 @@ def Operate_sqlite3(dbPath, commands):
 
 
 if __name__ == "__main__":
-    while(1):
+    # while(1):
         # syi = input("sql: ").split()
-        sy_i = input("sql: ")
-        Operate_sqlite3("dev.db", sy_i)
+        # sy_i = input("sql: ")
+        # Operate_sqlite3("dev.db", sy_i)
+
+    data = [
+    ('null', 'CL2', 'KB2', 'alive')
+    ]
+
+    sqls = ""

+ 17 - 11
t.py

@@ -10,23 +10,29 @@ def MatchTomlTable(tomlName, tableName, returnType="list"):
     elif returnType == "dict":
         return d
 
-
-def add(args=[]):
-    table = "Class"
-    
-    v1 = MatchTomlTable(tomlName, 'Class')[1:]
+# [todo 4] rebuild
+def add(cp, addType, contents):
+    if addType == "board":
+        sqls = "INSERT INTO Board VALUES(null, '{name}', 'alive');".format(name=self.name)
+        
     
+    elif addType == "class":
+        sqls = "INSERT INTO Class VALUES(null, '{name}', )"
+
+    elif addType == "event":
+        pass
+
+
+    sqls = ""
 
-    
 
-    sqls = "INSERT INTO {table} VALUES({values})".format(table=table, values=sqls_v)
-    # res = Stateful.Exec_one(dp, sqls)
-    print(sqls)
+    Stateful.Exec_one(dp, sqls)
 
 
 if __name__ == "__main__":
     tomlName = "dev_config.toml"
     dp = "dev.db"
     # res = MatchTomlTable(tomlName, "Board")
-    res = add()
-    print(res)
+    contents = []
+    cp = ""
+    res = add(cp, "class", )

+ 26 - 4
try.txt

@@ -57,9 +57,31 @@ CREATE TABLE Stucked(id INTEGER PRIMARY KEY AUTOINCREMENT, boardId, eventId, stu
     CL2 ie in KB, -> ok
     CL2 ne in KB, -> err
 
-/KB/CL/EV: add event <EV> -> err
-/KB/CL/EV: add event <EV> to <KB>
-/KB/CL/EV: add event <EV> to <KB2>
-/KB/CL/EV: add event <EV> to <CL>
+/KB/CL/EV: add event <EV2> -> err
+/KB/CL/EV: add event <EV> to <KB> -> okz
+/KB/CL/EV: add event <EV> to <KB2> -> ok
+/KB/CL/EV: add event <EV> to <CL> -> ok
 /KB/CL/EV: add event <EV> to <CL2>
+    whereis CL2
 /KB/CL/EV: add event <EV2> to <KB>/<CL>
+
+/: any thing
+
+/KB:
+    KB -> ok
+    CL -> ok
+    EV -> ok
+
+/KB/CL:
+    KB -> ok
+    CL -> ok
+    EV -> ok
+
+/KB/CL/EV:
+    KB -> ok
+    CL -> ok
+    EV -> ok
+
+等等, 后端的add不需要检查这些啊?!
+
+add board <KB1>, <KB2>, <KB3>, <KB4>