sqloader 0.2.6__tar.gz → 0.2.8__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {sqloader-0.2.6/sqloader.egg-info → sqloader-0.2.8}/PKG-INFO +1 -1
- {sqloader-0.2.6 → sqloader-0.2.8}/pyproject.toml +1 -1
- {sqloader-0.2.6 → sqloader-0.2.8}/setup.py +1 -1
- {sqloader-0.2.6 → sqloader-0.2.8}/sqloader/mysql_async.py +3 -0
- {sqloader-0.2.6 → sqloader-0.2.8}/sqloader/postgresql.py +12 -1
- {sqloader-0.2.6 → sqloader-0.2.8}/sqloader/postgresql_async.py +3 -0
- {sqloader-0.2.6 → sqloader-0.2.8}/sqloader/sqlite3.py +250 -235
- {sqloader-0.2.6 → sqloader-0.2.8}/sqloader/sqlite3_async.py +3 -0
- {sqloader-0.2.6 → sqloader-0.2.8/sqloader.egg-info}/PKG-INFO +1 -1
- {sqloader-0.2.6 → sqloader-0.2.8}/LICENSE +0 -0
- {sqloader-0.2.6 → sqloader-0.2.8}/README.md +0 -0
- {sqloader-0.2.6 → sqloader-0.2.8}/setup.cfg +0 -0
- {sqloader-0.2.6 → sqloader-0.2.8}/sqloader/__init__.py +0 -0
- {sqloader-0.2.6 → sqloader-0.2.8}/sqloader/__main__.py +0 -0
- {sqloader-0.2.6 → sqloader-0.2.8}/sqloader/_async_prototype.py +0 -0
- {sqloader-0.2.6 → sqloader-0.2.8}/sqloader/_prototype.py +0 -0
- {sqloader-0.2.6 → sqloader-0.2.8}/sqloader/init.py +0 -0
- {sqloader-0.2.6 → sqloader-0.2.8}/sqloader/migrator.py +0 -0
- {sqloader-0.2.6 → sqloader-0.2.8}/sqloader/mysql.py +0 -0
- {sqloader-0.2.6 → sqloader-0.2.8}/sqloader/sqloader.py +0 -0
- {sqloader-0.2.6 → sqloader-0.2.8}/sqloader.egg-info/SOURCES.txt +0 -0
- {sqloader-0.2.6 → sqloader-0.2.8}/sqloader.egg-info/dependency_links.txt +0 -0
- {sqloader-0.2.6 → sqloader-0.2.8}/sqloader.egg-info/requires.txt +0 -0
- {sqloader-0.2.6 → sqloader-0.2.8}/sqloader.egg-info/top_level.txt +0 -0
- {sqloader-0.2.6 → sqloader-0.2.8}/tests/test_fetch_aliases.py +0 -0
- {sqloader-0.2.6 → sqloader-0.2.8}/tests/test_migrator.py +0 -0
- {sqloader-0.2.6 → sqloader-0.2.8}/tests/test_mysql.py +0 -0
- {sqloader-0.2.6 → sqloader-0.2.8}/tests/test_postgresql.py +0 -0
- {sqloader-0.2.6 → sqloader-0.2.8}/tests/test_sqlite.py +0 -0
- {sqloader-0.2.6 → sqloader-0.2.8}/tests/test_sqloader.py +0 -0
|
@@ -89,6 +89,9 @@ class AsyncMySqlWrapper(AsyncDatabasePrototype):
|
|
|
89
89
|
print(f"Last query: {query}")
|
|
90
90
|
raise
|
|
91
91
|
|
|
92
|
+
async def execute_query(self, query, params=None, commit=True):
|
|
93
|
+
return await self.execute(query, params, commit)
|
|
94
|
+
|
|
92
95
|
async def fetchone(self, query, params=None):
|
|
93
96
|
return await self.fetch_one(query, params)
|
|
94
97
|
|
|
@@ -49,6 +49,8 @@ class PostgreSQLWrapper(DatabasePrototype):
|
|
|
49
49
|
self.log(query)
|
|
50
50
|
if params is not None:
|
|
51
51
|
self.log(params)
|
|
52
|
+
if params is not None and not isinstance(params, (tuple, list, dict)):
|
|
53
|
+
params = (params,)
|
|
52
54
|
cursor.execute(query, params)
|
|
53
55
|
if commit:
|
|
54
56
|
conn.commit()
|
|
@@ -66,6 +68,9 @@ class PostgreSQLWrapper(DatabasePrototype):
|
|
|
66
68
|
self.pool.putconn(conn)
|
|
67
69
|
query_semaphore.release()
|
|
68
70
|
|
|
71
|
+
def execute_query(self, query, params=None, commit=True):
|
|
72
|
+
return self.execute(query, params, commit)
|
|
73
|
+
|
|
69
74
|
def fetchone(self, query, params=None):
|
|
70
75
|
return self.fetch_one(query, params)
|
|
71
76
|
|
|
@@ -80,6 +85,8 @@ class PostgreSQLWrapper(DatabasePrototype):
|
|
|
80
85
|
self.log(query)
|
|
81
86
|
if params is not None:
|
|
82
87
|
self.log(params)
|
|
88
|
+
if params is not None and not isinstance(params, (tuple, list, dict)):
|
|
89
|
+
params = (params,)
|
|
83
90
|
cursor.execute(query, params)
|
|
84
91
|
result = cursor.fetchone()
|
|
85
92
|
conn.rollback() # Close the implicit transaction before returning to pool
|
|
@@ -111,6 +118,8 @@ class PostgreSQLWrapper(DatabasePrototype):
|
|
|
111
118
|
self.log(query)
|
|
112
119
|
if params is not None:
|
|
113
120
|
self.log(params)
|
|
121
|
+
if params is not None and not isinstance(params, (tuple, list, dict)):
|
|
122
|
+
params = (params,)
|
|
114
123
|
cursor.execute(query, params)
|
|
115
124
|
result = cursor.fetchall()
|
|
116
125
|
conn.rollback() # Close the implicit transaction before returning to pool
|
|
@@ -156,6 +165,8 @@ class PostgreSQLTransaction(Transaction):
|
|
|
156
165
|
self.cursor = self.conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor)
|
|
157
166
|
|
|
158
167
|
def execute(self, query, params=None):
|
|
168
|
+
if params is not None and not isinstance(params, (tuple, list, dict)):
|
|
169
|
+
params = (params,)
|
|
159
170
|
return self.cursor.execute(query, params)
|
|
160
171
|
|
|
161
172
|
def fetchall(self):
|
|
@@ -188,4 +199,4 @@ class PostgreSQLTransaction(Transaction):
|
|
|
188
199
|
self.rollback()
|
|
189
200
|
else:
|
|
190
201
|
self.commit()
|
|
191
|
-
self.close()
|
|
202
|
+
self.close()
|
|
@@ -119,6 +119,9 @@ class AsyncPostgreSQLWrapper(AsyncDatabasePrototype):
|
|
|
119
119
|
print(f"Last query: {q}")
|
|
120
120
|
raise
|
|
121
121
|
|
|
122
|
+
async def execute_query(self, query, params=None, commit=True):
|
|
123
|
+
return await self.execute(query, params, commit)
|
|
124
|
+
|
|
122
125
|
async def fetchone(self, query, params=None):
|
|
123
126
|
return await self.fetch_one(query, params)
|
|
124
127
|
|
|
@@ -1,235 +1,250 @@
|
|
|
1
|
-
import sqlite3
|
|
2
|
-
import threading
|
|
3
|
-
from ._prototype import DatabasePrototype, Transaction, SQLITE
|
|
4
|
-
from pathlib import Path
|
|
5
|
-
|
|
6
|
-
query_semaphore = None
|
|
7
|
-
|
|
8
|
-
db_lock = threading.Lock()
|
|
9
|
-
|
|
10
|
-
class SQLiteWrapper(DatabasePrototype):
|
|
11
|
-
db_type = SQLITE
|
|
12
|
-
|
|
13
|
-
def __init__(self, db_name, memory_mode=False, max_parallel_queries=5):
|
|
14
|
-
self.db_name = db_name
|
|
15
|
-
self.memory_mode = memory_mode
|
|
16
|
-
|
|
17
|
-
if not memory_mode:
|
|
18
|
-
# Auto-create parent directories for the database file
|
|
19
|
-
Path(self.db_name).parent.mkdir(parents=True, exist_ok=True)
|
|
20
|
-
|
|
21
|
-
global query_semaphore
|
|
22
|
-
query_semaphore = threading.Semaphore(max_parallel_queries)
|
|
23
|
-
|
|
24
|
-
if self.memory_mode:
|
|
25
|
-
# In-memory mode: single persistent connection + Lock (serialized access)
|
|
26
|
-
self.conn = sqlite3.connect(":memory:", check_same_thread=False)
|
|
27
|
-
self.conn.row_factory = sqlite3.Row
|
|
28
|
-
self.cursor = self.conn.cursor()
|
|
29
|
-
# To restore from a file, use:
|
|
30
|
-
# backup_conn = sqlite3.connect(db_name)
|
|
31
|
-
# backup_conn.backup(self.conn)
|
|
32
|
-
# backup_conn.close()
|
|
33
|
-
else:
|
|
34
|
-
# File mode: new connection per query via semaphore; no persistent conn needed
|
|
35
|
-
self.conn = None
|
|
36
|
-
self.cursor = None
|
|
37
|
-
|
|
38
|
-
def _execute_memory(self, query, params=None, commit=True):
|
|
39
|
-
"""In-memory mode: single connection + Lock (serialized)."""
|
|
40
|
-
with db_lock:
|
|
41
|
-
try:
|
|
42
|
-
if params is None:
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
self.cursor.execute(query
|
|
46
|
-
|
|
47
|
-
self.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
conn.
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
cursor.execute(query)
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
def
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
self.
|
|
218
|
-
|
|
219
|
-
def
|
|
220
|
-
self.
|
|
221
|
-
|
|
222
|
-
def
|
|
223
|
-
self.
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
self.
|
|
1
|
+
import sqlite3
|
|
2
|
+
import threading
|
|
3
|
+
from ._prototype import DatabasePrototype, Transaction, SQLITE
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
query_semaphore = None
|
|
7
|
+
|
|
8
|
+
db_lock = threading.Lock()
|
|
9
|
+
|
|
10
|
+
class SQLiteWrapper(DatabasePrototype):
|
|
11
|
+
db_type = SQLITE
|
|
12
|
+
|
|
13
|
+
def __init__(self, db_name, memory_mode=False, max_parallel_queries=5):
|
|
14
|
+
self.db_name = db_name
|
|
15
|
+
self.memory_mode = memory_mode
|
|
16
|
+
|
|
17
|
+
if not memory_mode:
|
|
18
|
+
# Auto-create parent directories for the database file
|
|
19
|
+
Path(self.db_name).parent.mkdir(parents=True, exist_ok=True)
|
|
20
|
+
|
|
21
|
+
global query_semaphore
|
|
22
|
+
query_semaphore = threading.Semaphore(max_parallel_queries)
|
|
23
|
+
|
|
24
|
+
if self.memory_mode:
|
|
25
|
+
# In-memory mode: single persistent connection + Lock (serialized access)
|
|
26
|
+
self.conn = sqlite3.connect(":memory:", check_same_thread=False)
|
|
27
|
+
self.conn.row_factory = sqlite3.Row
|
|
28
|
+
self.cursor = self.conn.cursor()
|
|
29
|
+
# To restore from a file, use:
|
|
30
|
+
# backup_conn = sqlite3.connect(db_name)
|
|
31
|
+
# backup_conn.backup(self.conn)
|
|
32
|
+
# backup_conn.close()
|
|
33
|
+
else:
|
|
34
|
+
# File mode: new connection per query via semaphore; no persistent conn needed
|
|
35
|
+
self.conn = None
|
|
36
|
+
self.cursor = None
|
|
37
|
+
|
|
38
|
+
def _execute_memory(self, query, params=None, commit=True):
|
|
39
|
+
"""In-memory mode: single connection + Lock (serialized)."""
|
|
40
|
+
with db_lock:
|
|
41
|
+
try:
|
|
42
|
+
if params is not None and not isinstance(params, (tuple, list, dict)):
|
|
43
|
+
params = (params,)
|
|
44
|
+
if params is None:
|
|
45
|
+
self.cursor.execute(query)
|
|
46
|
+
else:
|
|
47
|
+
self.cursor.execute(query, params)
|
|
48
|
+
if commit:
|
|
49
|
+
self.conn.commit()
|
|
50
|
+
return self.cursor.lastrowid
|
|
51
|
+
except sqlite3.DatabaseError as e:
|
|
52
|
+
print(f"Error executing query: {e}")
|
|
53
|
+
self.conn.rollback()
|
|
54
|
+
raise e
|
|
55
|
+
|
|
56
|
+
def _execute_file(self, query, params=None, commit=True):
|
|
57
|
+
"""File mode: semaphore + new connection per query (limited parallelism)."""
|
|
58
|
+
query_semaphore.acquire()
|
|
59
|
+
try:
|
|
60
|
+
conn = sqlite3.connect(self.db_name, check_same_thread=False)
|
|
61
|
+
conn.row_factory = sqlite3.Row
|
|
62
|
+
cursor = conn.cursor()
|
|
63
|
+
try:
|
|
64
|
+
if params is not None and not isinstance(params, (tuple, list, dict)):
|
|
65
|
+
params = (params,)
|
|
66
|
+
if params is None:
|
|
67
|
+
cursor.execute(query)
|
|
68
|
+
else:
|
|
69
|
+
cursor.execute(query, params)
|
|
70
|
+
if commit:
|
|
71
|
+
conn.commit()
|
|
72
|
+
return cursor.lastrowid
|
|
73
|
+
except sqlite3.DatabaseError as e:
|
|
74
|
+
print(f"Error executing query (file mode): {e}")
|
|
75
|
+
conn.rollback()
|
|
76
|
+
raise e
|
|
77
|
+
finally:
|
|
78
|
+
cursor.close()
|
|
79
|
+
conn.close()
|
|
80
|
+
finally:
|
|
81
|
+
query_semaphore.release()
|
|
82
|
+
|
|
83
|
+
def execute(self, query, params=None, commit=True):
|
|
84
|
+
if self.memory_mode:
|
|
85
|
+
return self._execute_memory(query, params, commit)
|
|
86
|
+
else:
|
|
87
|
+
return self._execute_file(query, params, commit)
|
|
88
|
+
|
|
89
|
+
def execute_query(self, query, params=None, commit=True):
|
|
90
|
+
return self.execute(query, params, commit)
|
|
91
|
+
|
|
92
|
+
def fetchone(self, query, params=None):
|
|
93
|
+
return self.fetch_one(query, params)
|
|
94
|
+
|
|
95
|
+
def fetch_one(self, query, params=None):
|
|
96
|
+
if self.memory_mode:
|
|
97
|
+
with db_lock:
|
|
98
|
+
try:
|
|
99
|
+
if params is not None and not isinstance(params, (tuple, list, dict)):
|
|
100
|
+
params = (params,)
|
|
101
|
+
if params is None:
|
|
102
|
+
self.cursor.execute(query)
|
|
103
|
+
else:
|
|
104
|
+
self.cursor.execute(query, params)
|
|
105
|
+
return self.cursor.fetchone()
|
|
106
|
+
except sqlite3.DatabaseError as e:
|
|
107
|
+
print(f"Error fetching data (memory mode, fetch_one): {e}")
|
|
108
|
+
raise e
|
|
109
|
+
else:
|
|
110
|
+
# File mode: open a new connection for the fetch
|
|
111
|
+
query_semaphore.acquire()
|
|
112
|
+
try:
|
|
113
|
+
conn = sqlite3.connect(self.db_name, check_same_thread=False)
|
|
114
|
+
conn.row_factory = sqlite3.Row
|
|
115
|
+
cursor = conn.cursor()
|
|
116
|
+
try:
|
|
117
|
+
if params is not None and not isinstance(params, (tuple, list, dict)):
|
|
118
|
+
params = (params,)
|
|
119
|
+
if params is None:
|
|
120
|
+
cursor.execute(query)
|
|
121
|
+
else:
|
|
122
|
+
cursor.execute(query, params)
|
|
123
|
+
return cursor.fetchone()
|
|
124
|
+
except sqlite3.DatabaseError as e:
|
|
125
|
+
print(f"Error fetching data (file mode, fetch_one): {e}")
|
|
126
|
+
raise e
|
|
127
|
+
finally:
|
|
128
|
+
cursor.close()
|
|
129
|
+
conn.close()
|
|
130
|
+
finally:
|
|
131
|
+
query_semaphore.release()
|
|
132
|
+
|
|
133
|
+
def fetchall(self, query, params=None):
|
|
134
|
+
return self.fetch_all(query, params)
|
|
135
|
+
|
|
136
|
+
def fetch_all(self, query, params=None):
|
|
137
|
+
if self.memory_mode:
|
|
138
|
+
with db_lock:
|
|
139
|
+
try:
|
|
140
|
+
if params is not None and not isinstance(params, (tuple, list, dict)):
|
|
141
|
+
params = (params,)
|
|
142
|
+
if params is None:
|
|
143
|
+
self.cursor.execute(query)
|
|
144
|
+
else:
|
|
145
|
+
self.cursor.execute(query, params)
|
|
146
|
+
return self.cursor.fetchall()
|
|
147
|
+
except sqlite3.DatabaseError as e:
|
|
148
|
+
print(f"Error fetching data (memory mode, fetch_all): {e}")
|
|
149
|
+
raise e
|
|
150
|
+
else:
|
|
151
|
+
query_semaphore.acquire()
|
|
152
|
+
try:
|
|
153
|
+
conn = sqlite3.connect(self.db_name, check_same_thread=False)
|
|
154
|
+
conn.row_factory = sqlite3.Row
|
|
155
|
+
cursor = conn.cursor()
|
|
156
|
+
try:
|
|
157
|
+
if params is not None and not isinstance(params, (tuple, list, dict)):
|
|
158
|
+
params = (params,)
|
|
159
|
+
if params is None:
|
|
160
|
+
cursor.execute(query)
|
|
161
|
+
else:
|
|
162
|
+
cursor.execute(query, params)
|
|
163
|
+
return cursor.fetchall()
|
|
164
|
+
except sqlite3.DatabaseError as e:
|
|
165
|
+
print(f"Error fetching data (file mode, fetch_all): {e}")
|
|
166
|
+
raise e
|
|
167
|
+
finally:
|
|
168
|
+
cursor.close()
|
|
169
|
+
conn.close()
|
|
170
|
+
finally:
|
|
171
|
+
query_semaphore.release()
|
|
172
|
+
|
|
173
|
+
def rollback(self):
|
|
174
|
+
if self.memory_mode:
|
|
175
|
+
with db_lock:
|
|
176
|
+
self.conn.rollback()
|
|
177
|
+
else:
|
|
178
|
+
# File mode uses per-query connections; no persistent connection to rollback
|
|
179
|
+
pass
|
|
180
|
+
|
|
181
|
+
def commit(self):
|
|
182
|
+
if self.memory_mode:
|
|
183
|
+
with db_lock:
|
|
184
|
+
self.conn.commit()
|
|
185
|
+
else:
|
|
186
|
+
# File mode uses per-query connections; commit is handled inside each call
|
|
187
|
+
pass
|
|
188
|
+
|
|
189
|
+
def close(self):
|
|
190
|
+
if self.memory_mode:
|
|
191
|
+
with db_lock:
|
|
192
|
+
self.cursor.close()
|
|
193
|
+
self.conn.close()
|
|
194
|
+
else:
|
|
195
|
+
# File mode has no persistent connection to close
|
|
196
|
+
pass
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def begin_transaction(self):
|
|
200
|
+
"""Returns a transaction context manager backed by a dedicated connection."""
|
|
201
|
+
return SQLiteTransaction(self)
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
class SQLiteTransaction:
|
|
205
|
+
def __init__(self, wrapper: SQLiteWrapper):
|
|
206
|
+
self.wrapper = wrapper
|
|
207
|
+
self.conn = sqlite3.connect(
|
|
208
|
+
wrapper.db_name,
|
|
209
|
+
check_same_thread=False
|
|
210
|
+
)
|
|
211
|
+
self.conn.row_factory = sqlite3.Row
|
|
212
|
+
self.cursor = self.conn.cursor()
|
|
213
|
+
|
|
214
|
+
def execute(self, query, params=None):
|
|
215
|
+
if params is None:
|
|
216
|
+
return self.cursor.execute(query)
|
|
217
|
+
return self.cursor.execute(query, params)
|
|
218
|
+
|
|
219
|
+
def fetchall(self):
|
|
220
|
+
return self.cursor.fetchall()
|
|
221
|
+
|
|
222
|
+
def fetch_all(self):
|
|
223
|
+
return self.fetchall()
|
|
224
|
+
|
|
225
|
+
def fetchone(self):
|
|
226
|
+
return self.cursor.fetchone()
|
|
227
|
+
|
|
228
|
+
def fetch_one(self):
|
|
229
|
+
return self.fetchone()
|
|
230
|
+
|
|
231
|
+
def commit(self):
|
|
232
|
+
self.conn.commit()
|
|
233
|
+
|
|
234
|
+
def rollback(self):
|
|
235
|
+
self.conn.rollback()
|
|
236
|
+
|
|
237
|
+
def close(self):
|
|
238
|
+
self.cursor.close()
|
|
239
|
+
self.conn.close()
|
|
240
|
+
|
|
241
|
+
def __enter__(self):
|
|
242
|
+
return self
|
|
243
|
+
|
|
244
|
+
def __exit__(self, exc_type, exc_val, traceback):
|
|
245
|
+
# Rollback on exception, commit otherwise
|
|
246
|
+
if exc_type:
|
|
247
|
+
self.rollback()
|
|
248
|
+
else:
|
|
249
|
+
self.commit()
|
|
250
|
+
self.close()
|
|
@@ -94,6 +94,9 @@ class AsyncSQLiteWrapper(AsyncDatabasePrototype):
|
|
|
94
94
|
await self._conn.rollback()
|
|
95
95
|
raise
|
|
96
96
|
|
|
97
|
+
async def execute_query(self, query, params=None, commit=True):
|
|
98
|
+
return await self.execute(query, params, commit)
|
|
99
|
+
|
|
97
100
|
async def fetchone(self, query, params=None):
|
|
98
101
|
return await self.fetch_one(query, params)
|
|
99
102
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|