sqlthon 0.0.11__tar.gz → 0.0.13__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.11
3
+ Version: 0.0.13
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.11'
7
+ version = '0.0.13'
8
8
  description = "A simple package for SQLite3 operations"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.8"
@@ -0,0 +1,21 @@
1
+ """
2
+ A Simple Package For SQLite3 Operations.
3
+
4
+ ||||| |||| || |||||| || || |||||| || ||
5
+ || || || || || || || || || ||| ||
6
+ |||| || || || || |||||| || || ||||||
7
+ || |||| || || || || || || || |||
8
+ ||||| || |||||| || || || |||||| || ||
9
+
10
+ Github: https://Github.com/saums-1391/sqlthon
11
+ Channel: https://ble.ir/saums_channel
12
+
13
+ """
14
+
15
+ from .core import Connect, Field
16
+
17
+ __all__ = ['Connect', 'Field']
18
+ __version__ = '0.0.13'
19
+ __author__ = "SAUMS"
20
+ __email__ = "saums1391@gmail.com"
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):
@@ -79,7 +79,7 @@ class Connect:
79
79
  try:
80
80
  limits = column[2]
81
81
  query += f"{name} {type} {" ".join(limits)}"
82
- except IndexError:
82
+ except:
83
83
  query += f"{name} {type}"
84
84
 
85
85
  query += ", "
@@ -139,8 +139,8 @@ class Connect:
139
139
  query += f" GROUP BY {", ".join(bundle)}"
140
140
  if filter_bundle:
141
141
  __: tuple = _compile(filter_bundle)
142
- query += f" HAVING {_[0]}"
143
- param += _[1]
142
+ query += f" HAVING {__[0]}"
143
+ param += __[1]
144
144
  del __
145
145
 
146
146
  if sort:
@@ -250,10 +250,16 @@ class Connect:
250
250
  records = []
251
251
  for row in reader:
252
252
  records.append(tuple(row))
253
+ if records:
254
+ self.add_records(table_name, tuple(records))
253
255
 
254
- self.add_records(table_name, tuple(records))
255
-
256
-
256
+ def to_csv(self, table_name: str, csv_path: str) -> None:
257
+ import csv as _csv
258
+ with open(csv_path, "w", newline="", encoding="utf-8") as f:
259
+ writer = _csv.writer(f)
260
+ writer.writerow(self.get_columns(table_name))
261
+ for row in self.find_record(table_name):
262
+ writer.writerow(row)
257
263
  # ____________| OTHER |_________
258
264
  def last_id(self) -> int:
259
265
  return self.run_query("SELECT last_insert_rowid()")[0][0]
@@ -269,7 +275,8 @@ class Connect:
269
275
  # ____________| BASIC |_________
270
276
  def run_query(self, code: str, parameters: tuple=()) -> list:
271
277
  self._cur.execute(code, parameters)
272
- self._con.commit()
278
+ if not "SELECT" in code:
279
+ self._con.commit()
273
280
  return self._cur.fetchall()
274
281
 
275
282
  def optimize(self) -> None:
@@ -278,10 +285,20 @@ class Connect:
278
285
  self._con.commit()
279
286
 
280
287
  def save_to_database(self) -> None:
281
- with self._con:
282
- for sql_code in self._changes:
283
- self._cur.execute(*sql_code)
284
- self._changes.clear()
288
+ try:
289
+ with self._con:
290
+ for sql_code in self._changes:
291
+ self._cur.execute(*sql_code)
292
+ finally:
293
+ self._changes.clear()
285
294
 
286
295
  def close(self):
287
- self._con.close()
296
+ self._con.close()
297
+
298
+ # ____________| MAGICALS |_________
299
+ def __enter__(self) -> "Connect":
300
+ return self
301
+
302
+ def __exit__(self, exc_type, exc_value, exc_tb) -> None:
303
+ self.save_to_database()
304
+ self.close()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sqlthon
3
- Version: 0.0.11
3
+ Version: 0.0.13
4
4
  Summary: A simple package for SQLite3 operations
5
5
  Author-email: SAUMS <mohamnown@gmail.com>
6
6
  License: MIT
@@ -1,11 +0,0 @@
1
- """
2
- Sqlthon - A Simple Package For SQLite3 Operations.
3
- """
4
-
5
- from .core import Connect, Field
6
-
7
- __all__ = ['Connect', 'Field']
8
- __version__ = '0.0.11'
9
- __author__ = "SAUMS"
10
- __email__ = "saums1391@gmail.com"
11
- __description__ = "Operate With SQLite3 Buy Simple"
File without changes
File without changes