sqlthon 0.0.14__tar.gz → 0.0.15__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sqlthon
3
- Version: 0.0.14
3
+ Version: 0.0.15
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.14'
7
+ version = '0.0.15'
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.14'
18
+ __version__ = '0.0.15'
19
19
  __author__ = "SAUMS"
20
20
  __email__ = "saums1391@gmail.com"
21
21
  __description__ = "Operate With SQLite3 Buy Simple"
@@ -9,6 +9,26 @@ class Field:
9
9
  def __le__(self, value): return _Expression(self, "<=", value)
10
10
  def __eq__(self, value): return _Expression(self, "=", value)
11
11
  def __ne__(self, value): return _Expression(self, "!=", value)
12
+ def __invert__(self): return _Expression(self, "NOT", None)
13
+ def not_like(self, value): return _Expression(self, "NOT LIKE", value)
14
+ def like(self, value):
15
+ return _Expression(self, "LIKE", value)
16
+ def startswith(self, value):
17
+ return _Expression(self, "LIKE", f"{value}%")
18
+ def endswith(self, value):
19
+ return _Expression(self, "LIKE", f"%{value}")
20
+ def contains(self, value):
21
+ return _Expression(self, "LIKE", f"%{value}%")
22
+ def in_(self, value):
23
+ return _Expression(self, "IN", value)
24
+ def not_in(self, value):
25
+ return _Expression(self, "NOT IN", value)
26
+ def between(self, value):
27
+ return _Expression(self, "BETWEEN", value)
28
+ def is_null(self):
29
+ return _Expression(self, "IS NULL", None)
30
+ def is_not_null(self):
31
+ return _Expression(self, "IS NOT NULL", None)
12
32
 
13
33
 
14
34
  class _Expression:
@@ -48,6 +68,18 @@ def _compile(expr):
48
68
  sql = f"({left_sql}) {expr.op} ({right_sql})"
49
69
  params = left_params + right_params
50
70
  return sql, params
71
+ elif expr.op in ("IN", "NOT IN"):
72
+ placeholders = ", ".join(["?"] * len(expr.right))
73
+ sql = f'"{expr.left.name}" {expr.op} ({placeholders})'
74
+ params = tuple(expr.right)
75
+ return sql, params
76
+ elif expr.op == "BETWEEN":
77
+ sql = f'"{expr.left.name}" BETWEEN ? AND ?'
78
+ params = tuple(expr.right)
79
+ return sql, params
80
+ elif expr.op in ("IS NULL", "IS NOT NULL"):
81
+ sql = f'"{expr.left.name}" {expr.op}'
82
+ return sql, ()
51
83
  elif isinstance(expr.left, _Aggregate):
52
84
  sql = f"{expr.left} {expr.op} ?"
53
85
  params = (expr.right,)
@@ -59,14 +91,13 @@ def _compile(expr):
59
91
 
60
92
 
61
93
  class Connect:
62
- __slots__ = ("_con", "_cur", "_changes", "_path", "_turbo")
94
+ __slots__ = ("_con", "_cur", "_changes", "_path")
63
95
  def __init__(self, database_path: str) -> None:
64
96
  from sqlite3 import connect as _cn
65
97
  self._path = database_path
66
98
  self._con = _cn(database_path)
67
99
  self._cur = self._con.cursor()
68
100
  self._changes: list = []
69
- self._turbo: bool = False
70
101
  del _cn
71
102
 
72
103
  # ____________| TABLE |____________
@@ -265,31 +296,6 @@ class Connect:
265
296
  for row in self.find_record(table_name):
266
297
  writer.writerow(row)
267
298
 
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
-
293
299
  # ____________| OTHER |_________
294
300
  def last_id(self) -> int:
295
301
  return self.run_query("SELECT last_insert_rowid()")[0][0]
@@ -305,7 +311,7 @@ class Connect:
305
311
  # ____________| BASIC |_________
306
312
  def run_query(self, code: str, parameters: tuple=()) -> list:
307
313
  self._cur.execute(code, parameters)
308
- if not "SELECT" in code:
314
+ if not code.upper().startswith("SELECT"):
309
315
  self._con.commit()
310
316
  return self._cur.fetchall()
311
317
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sqlthon
3
- Version: 0.0.14
3
+ Version: 0.0.15
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