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.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sqlthon
3
- Version: 0.0.12
3
+ Version: 0.0.14
4
4
  Summary: A simple package for SQLite3 operations
5
5
  Author-email: SAUMS <mohamnown@gmail.com>
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "sqlthon"
7
- version = '0.0.12'
7
+ version = '0.0.14'
8
8
  description = "A simple package for SQLite3 operations"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.8"
@@ -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.12'
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
- copy2(self._path, backup_path)
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
- self._con.commit()
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
- with self._con:
288
- for sql_code in self._changes:
289
- self._cur.execute(*sql_code)
290
- self._changes.clear()
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()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sqlthon
3
- Version: 0.0.12
3
+ Version: 0.0.14
4
4
  Summary: A simple package for SQLite3 operations
5
5
  Author-email: SAUMS <mohamnown@gmail.com>
6
6
  License: MIT
File without changes
File without changes