@@ -30,48 +30,53 @@ class field(enum.Enum):
3030 TARGET = '"target"'
3131 KEY = '"key"'
3232 VALUE = '"value"'
33+ TYPE = '"type"'
3334
3435 @override
3536 def first_time_setup (self ) -> None :
3637 query = f"""
3738 CREATE TABLE IF NOT EXISTS "{ self .TABLE_NAME } " (
3839 { self .field .SCOPE .value } TEXT NOT NULL,
40+ { self .field .TYPE .value } TEXT NOT NULL,
3941 { self .field .TARGET .value } TEXT NOT NULL,
4042 { self .field .KEY .value } TEXT NOT NULL,
4143 { self .field .VALUE .value } TEXT,
4244 PRIMARY KEY(
4345 { self .field .SCOPE .value } ,
4446 { self .field .TARGET .value } ,
47+ { self .field .TYPE .value } ,
4548 { self .field .KEY .value }
4649 ) ON CONFLICT REPLACE
4750 );
4851 """
4952 self .sqlite .execute (query )
5053
51- def set (self , scope : str , target : str , key : str , value ) -> None :
54+ def set (self , scope : str , target : str , key : str , value , typ : str ) -> None :
5255 value_str = json .dumps (value )
5356 query = f"""
5457 INSERT INTO { self .TABLE_NAME }
5558 (
5659 { self .field .SCOPE .value } ,
5760 { self .field .TARGET .value } ,
5861 { self .field .KEY .value } ,
62+ { self .field .TYPE .value } ,
5963 { self .field .VALUE .value }
6064 )
61- VALUES (?, ?, ?, ?)
65+ VALUES (?, ?, ?, ?, ? )
6266 """
63- self .sqlite .execute (query , (scope , target , key , value_str ))
67+ self .sqlite .execute (query , (scope , target , key , typ , value_str ))
6468
65- def get (self , scope : str , target : str , key : str ):
69+ def get (self , scope : str , target : str , key : str , typ : str ):
6670 result : list [tuple [Any ]] | None = self .sqlite .execute_and_fetch (
6771 query = f"""
6872 SELECT { self .field .VALUE .value }
6973 FROM { self .TABLE_NAME }
7074 WHERE { self .field .SCOPE .value } = ?
7175 AND { self .field .TARGET .value } = ?
76+ AND { self .field .TYPE .value } = ?
7277 AND { self .field .KEY .value } = ?
7378 """ ,
74- values = (scope , target , key ),
79+ values = (scope , target , typ , key ),
7580 )
7681 json_str = self .unwrap_result (result , only_first_field = True )
7782 if json_str is not None :
@@ -113,6 +118,7 @@ def query_sorted_data(
113118 FROM { self .TABLE_NAME }
114119 WHERE { self .field .SCOPE .value } = ?
115120 AND { self .field .KEY .value } = ?
121+ AND { self .field .TYPE .value } = "sorted"
116122 AND JSON_VALID({ self .field .VALUE .value } )
117123 AND { int_casted_skeleton } IS NOT NULL
118124 { value_bound_suffix }
0 commit comments