@@ -38,36 +38,23 @@ def __init__(self, **kwargs):
38
38
super ().__init__ (** kwargs )
39
39
self ._engine = sa .create_engine (f"sqlite:///{ self .database_path } " , future = True )
40
40
41
+ def __finalize__ (self ):
42
+ super ().__finalize__ ()
43
+ self ._set_sqlite_max_vars ()
44
+
41
45
def __repr__ (self ):
42
46
return f"<SQLiteSyncer conn_string='{ self .engine .url } '>"
43
47
44
- def insert_on_conflict (self , data : TableRows , * , table : sa .Table ) -> Union [sa .Insert , sa .Update ]:
45
- """UPSERT."""
46
- stmt = insert (table ).values (data )
47
-
48
- if table .columns == table .primary_key :
49
- set_ = {c .key : getattr (stmt .excluded , c .key ) for c in table .columns }
50
- else :
51
- set_ = {c .key : getattr (stmt .excluded , c .key ) for c in table .columns if c .key not in table .primary_key }
52
-
53
- stmt = stmt .on_conflict_do_update (
54
- index_elements = table .primary_key ,
55
- set_ = set_ ,
56
- )
57
- return stmt
58
-
59
- # @contextlib.contextmanager
60
- # def pragma_speedy_insert(self):
61
- # """ """
62
- # self.session.execute("PRAGMA journal_mode = OFF;")
63
- # self.session.execute("PRAGMA synchronous = 0;")
64
- # self.session.execute("PRAGMA locking_mode = EXCLUSIVE;")
65
- # self.session.execute("PRAGMA temp_store = MEMORY;")
66
- # yield
67
- # self.session.execute("PRAGMA journal_mode = ON;")
68
- # self.session.execute("PRAGMA synchronous = 0;")
69
- # self.session.execute("PRAGMA locking_mode = EXCLUSIVE;")
70
- # self.session.execute("PRAGMA temp_store = MEMORY;")
48
+ def _set_sqlite_max_vars (self ) -> None :
49
+ """Fetch the maximum number of variables that SQLite supports."""
50
+ r = self .session .execute (sa .text ("PRAGMA compile_options;" ))
51
+
52
+ for option in r .mappings ().all ():
53
+ override = option ["compile_options" ]
54
+ name , _ , value = override .partition ("=" )
55
+
56
+ if name == "MAX_VARIABLE_NUMBER" :
57
+ const .SQLITE_MAX_VARIABLES = int (value )
71
58
72
59
def read_stream (self , tablename : str , * , batch : int = 100_000 ) -> Iterator [TableRows ]:
73
60
"""Read rows from a SQLite database."""
0 commit comments