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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sqlthon
3
- Version: 0.0.13
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.13'
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.13'
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
- copy2(self._path, backup_path)
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" in code:
314
+ if not code.upper().startswith("SELECT"):
279
315
  self._con.commit()
280
316
  return self._cur.fetchall()
281
317
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sqlthon
3
- Version: 0.0.13
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