sqlthon 0.0.13__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.
- {sqlthon-0.0.13 → sqlthon-0.0.15}/PKG-INFO +1 -1
- {sqlthon-0.0.13 → sqlthon-0.0.15}/pyproject.toml +1 -1
- {sqlthon-0.0.13 → sqlthon-0.0.15}/src/sqlthon/__init__.py +1 -1
- {sqlthon-0.0.13 → sqlthon-0.0.15}/src/sqlthon/core.py +39 -3
- {sqlthon-0.0.13 → sqlthon-0.0.15}/src/sqlthon.egg-info/PKG-INFO +1 -1
- {sqlthon-0.0.13 → sqlthon-0.0.15}/README.md +0 -0
- {sqlthon-0.0.13 → sqlthon-0.0.15}/setup.cfg +0 -0
- {sqlthon-0.0.13 → sqlthon-0.0.15}/src/sqlthon/keywords.py +0 -0
- {sqlthon-0.0.13 → sqlthon-0.0.15}/src/sqlthon.egg-info/SOURCES.txt +0 -0
- {sqlthon-0.0.13 → sqlthon-0.0.15}/src/sqlthon.egg-info/dependency_links.txt +0 -0
- {sqlthon-0.0.13 → sqlthon-0.0.15}/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.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,)
|
|
@@ -221,10 +253,13 @@ class Connect:
|
|
|
221
253
|
return view_name in [i[0] for i in self.run_query("SELECT name FROM sqlite_master WHERE type='view'")]
|
|
222
254
|
|
|
223
255
|
# ____________| BACKUP |_________
|
|
224
|
-
def backup_database(self, backup_path: str) -> None:
|
|
256
|
+
def backup_database(self, backup_path: str | None=None) -> None:
|
|
225
257
|
from shutil import copy2
|
|
226
258
|
self._con.commit()
|
|
227
|
-
|
|
259
|
+
if backup_path:
|
|
260
|
+
copy2(self._path, backup_path)
|
|
261
|
+
else:
|
|
262
|
+
copy2(self._path, "".join(self._path.split(".")[:-1]))
|
|
228
263
|
|
|
229
264
|
# ____________| PANDAS |_________
|
|
230
265
|
def to_dataframe(self, table_name: str) -> "pd.DataFrame":
|
|
@@ -260,6 +295,7 @@ class Connect:
|
|
|
260
295
|
writer.writerow(self.get_columns(table_name))
|
|
261
296
|
for row in self.find_record(table_name):
|
|
262
297
|
writer.writerow(row)
|
|
298
|
+
|
|
263
299
|
# ____________| OTHER |_________
|
|
264
300
|
def last_id(self) -> int:
|
|
265
301
|
return self.run_query("SELECT last_insert_rowid()")[0][0]
|
|
@@ -275,7 +311,7 @@ class Connect:
|
|
|
275
311
|
# ____________| BASIC |_________
|
|
276
312
|
def run_query(self, code: str, parameters: tuple=()) -> list:
|
|
277
313
|
self._cur.execute(code, parameters)
|
|
278
|
-
if not "SELECT"
|
|
314
|
+
if not code.upper().startswith("SELECT"):
|
|
279
315
|
self._con.commit()
|
|
280
316
|
return self._cur.fetchall()
|
|
281
317
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|