sqlthon 0.0.12__tar.gz → 0.0.14__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.
Potentially problematic release.
This version of sqlthon might be problematic. Click here for more details.
- {sqlthon-0.0.12 → sqlthon-0.0.14}/PKG-INFO +1 -1
- {sqlthon-0.0.12 → sqlthon-0.0.14}/pyproject.toml +1 -1
- {sqlthon-0.0.12 → sqlthon-0.0.14}/src/sqlthon/__init__.py +1 -1
- {sqlthon-0.0.12 → sqlthon-0.0.14}/src/sqlthon/core.py +42 -9
- {sqlthon-0.0.12 → sqlthon-0.0.14}/src/sqlthon.egg-info/PKG-INFO +1 -1
- {sqlthon-0.0.12 → sqlthon-0.0.14}/README.md +0 -0
- {sqlthon-0.0.12 → sqlthon-0.0.14}/setup.cfg +0 -0
- {sqlthon-0.0.12 → sqlthon-0.0.14}/src/sqlthon/keywords.py +0 -0
- {sqlthon-0.0.12 → sqlthon-0.0.14}/src/sqlthon.egg-info/SOURCES.txt +0 -0
- {sqlthon-0.0.12 → sqlthon-0.0.14}/src/sqlthon.egg-info/dependency_links.txt +0 -0
- {sqlthon-0.0.12 → sqlthon-0.0.14}/src/sqlthon.egg-info/top_level.txt +0 -0
|
@@ -15,7 +15,7 @@ Channel: https://ble.ir/saums_channel
|
|
|
15
15
|
from .core import Connect, Field
|
|
16
16
|
|
|
17
17
|
__all__ = ['Connect', 'Field']
|
|
18
|
-
__version__ = '0.0.
|
|
18
|
+
__version__ = '0.0.14'
|
|
19
19
|
__author__ = "SAUMS"
|
|
20
20
|
__email__ = "saums1391@gmail.com"
|
|
21
21
|
__description__ = "Operate With SQLite3 Buy Simple"
|
|
@@ -45,7 +45,7 @@ def _compile(expr):
|
|
|
45
45
|
if isinstance(expr.left, _Expression) or isinstance(expr.right, _Expression):
|
|
46
46
|
left_sql, left_params = _compile(expr.left)
|
|
47
47
|
right_sql, right_params = _compile(expr.right)
|
|
48
|
-
sql = f"{left_sql} {expr.op} {right_sql}"
|
|
48
|
+
sql = f"({left_sql}) {expr.op} ({right_sql})"
|
|
49
49
|
params = left_params + right_params
|
|
50
50
|
return sql, params
|
|
51
51
|
elif isinstance(expr.left, _Aggregate):
|
|
@@ -59,13 +59,14 @@ def _compile(expr):
|
|
|
59
59
|
|
|
60
60
|
|
|
61
61
|
class Connect:
|
|
62
|
-
__slots__ = ("_con", "_cur", "_changes", "_path")
|
|
62
|
+
__slots__ = ("_con", "_cur", "_changes", "_path", "_turbo")
|
|
63
63
|
def __init__(self, database_path: str) -> None:
|
|
64
64
|
from sqlite3 import connect as _cn
|
|
65
65
|
self._path = database_path
|
|
66
66
|
self._con = _cn(database_path)
|
|
67
67
|
self._cur = self._con.cursor()
|
|
68
68
|
self._changes: list = []
|
|
69
|
+
self._turbo: bool = False
|
|
69
70
|
del _cn
|
|
70
71
|
|
|
71
72
|
# ____________| TABLE |____________
|
|
@@ -221,10 +222,13 @@ class Connect:
|
|
|
221
222
|
return view_name in [i[0] for i in self.run_query("SELECT name FROM sqlite_master WHERE type='view'")]
|
|
222
223
|
|
|
223
224
|
# ____________| BACKUP |_________
|
|
224
|
-
def backup_database(self, backup_path: str) -> None:
|
|
225
|
+
def backup_database(self, backup_path: str | None=None) -> None:
|
|
225
226
|
from shutil import copy2
|
|
226
227
|
self._con.commit()
|
|
227
|
-
|
|
228
|
+
if backup_path:
|
|
229
|
+
copy2(self._path, backup_path)
|
|
230
|
+
else:
|
|
231
|
+
copy2(self._path, "".join(self._path.split(".")[:-1]))
|
|
228
232
|
|
|
229
233
|
# ____________| PANDAS |_________
|
|
230
234
|
def to_dataframe(self, table_name: str) -> "pd.DataFrame":
|
|
@@ -260,6 +264,32 @@ class Connect:
|
|
|
260
264
|
writer.writerow(self.get_columns(table_name))
|
|
261
265
|
for row in self.find_record(table_name):
|
|
262
266
|
writer.writerow(row)
|
|
267
|
+
|
|
268
|
+
# ____________| TURBO |_________
|
|
269
|
+
def on_turbo(self) -> None:
|
|
270
|
+
if self._turbo:
|
|
271
|
+
return
|
|
272
|
+
|
|
273
|
+
self._cur.execute("PRAGMA journal_mode = WAL")
|
|
274
|
+
self._cur.execute("PRAGMA synchronous = OFF")
|
|
275
|
+
self._cur.execute("PRAGMA cache_size = -64000")
|
|
276
|
+
self._cur.execute("PRAGMA temp_store = MEMORY")
|
|
277
|
+
self._turbo = True
|
|
278
|
+
|
|
279
|
+
def off_turbo(self) -> None:
|
|
280
|
+
if not self._turbo:
|
|
281
|
+
return
|
|
282
|
+
|
|
283
|
+
self._cur.execute("PRAGMA synchronous = FULL")
|
|
284
|
+
self._cur.execute("PRAGMA journal_mode = DELETE")
|
|
285
|
+
self._cur.execute("PRAGMA cache_size = -2000")
|
|
286
|
+
self._cur.execute("PRAGMA temp_store = DEFAULT")
|
|
287
|
+
self._turbo = False
|
|
288
|
+
|
|
289
|
+
@property
|
|
290
|
+
def is_turbo(self) -> bool:
|
|
291
|
+
return self._turbo
|
|
292
|
+
|
|
263
293
|
# ____________| OTHER |_________
|
|
264
294
|
def last_id(self) -> int:
|
|
265
295
|
return self.run_query("SELECT last_insert_rowid()")[0][0]
|
|
@@ -275,7 +305,8 @@ class Connect:
|
|
|
275
305
|
# ____________| BASIC |_________
|
|
276
306
|
def run_query(self, code: str, parameters: tuple=()) -> list:
|
|
277
307
|
self._cur.execute(code, parameters)
|
|
278
|
-
|
|
308
|
+
if not "SELECT" in code:
|
|
309
|
+
self._con.commit()
|
|
279
310
|
return self._cur.fetchall()
|
|
280
311
|
|
|
281
312
|
def optimize(self) -> None:
|
|
@@ -284,10 +315,12 @@ class Connect:
|
|
|
284
315
|
self._con.commit()
|
|
285
316
|
|
|
286
317
|
def save_to_database(self) -> None:
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
self.
|
|
290
|
-
|
|
318
|
+
try:
|
|
319
|
+
with self._con:
|
|
320
|
+
for sql_code in self._changes:
|
|
321
|
+
self._cur.execute(*sql_code)
|
|
322
|
+
finally:
|
|
323
|
+
self._changes.clear()
|
|
291
324
|
|
|
292
325
|
def close(self):
|
|
293
326
|
self._con.close()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|