sqlthon 0.0.7__tar.gz → 0.0.9__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.7
3
+ Version: 0.0.9
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.7'
7
+ version = '0.0.9'
8
8
  description = "A simple package for SQLite3 operations"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.8"
@@ -5,7 +5,7 @@ Sqlthon - A Simple Package For SQLite3 Operations.
5
5
  from .core import Connect, Field
6
6
 
7
7
  __all__ = ['Connect', 'Field']
8
- __version__ = '0.0.7'
8
+ __version__ = '0.0.9'
9
9
  __author__ = "SAUMS"
10
10
  __email__ = "saums1391@gmail.com"
11
11
  __description__ = "Operate With SQLite3 Buy Simple"
@@ -1,4 +1,5 @@
1
1
  class Field:
2
+ __slots__ = ("name",)
2
3
  def __init__(self, name):
3
4
  self.name = name
4
5
 
@@ -11,6 +12,7 @@ class Field:
11
12
 
12
13
 
13
14
  class _Expression:
15
+ __slots__ = ("left", "op", "right")
14
16
  def __init__(self, left, op, right):
15
17
  self.left = left
16
18
  self.op = op
@@ -23,6 +25,7 @@ class _Expression:
23
25
 
24
26
 
25
27
  class _Aggregate:
28
+ __slots__ = ("func", "column")
26
29
  def __init__(self, func, column="*"):
27
30
  self.func = func
28
31
  self.column = column
@@ -90,7 +93,7 @@ class Connect:
90
93
  self._changes.append((f"DROP TABLE {table_name}",))
91
94
 
92
95
  def exist_table(self, table_name: str) -> bool:
93
- return table_name in [i[0] for i in self.run_code("SELECT name FROM sqlite_master WHERE type='table'")]
96
+ return table_name in [i[0] for i in self.run_query("SELECT name FROM sqlite_master WHERE type='table'")]
94
97
 
95
98
  def copy_table(self, table_name: str, new_name_table: str) -> None:
96
99
  self._changes.append((f"CREATE TABLE {new_name_table} AS SELECT * FROM {table_name}"),)
@@ -110,10 +113,10 @@ class Connect:
110
113
  self._changes.append((f"ALTER TABLE {table_name} RENAME COLUMN {old_name_column} TO {new_name_column}",))
111
114
 
112
115
  def exist_column(self, table_name: str, column_name: str) -> bool:
113
- return column_name in [i[1] for i in self.run_code(f"PRAGMA table_info({table_name})")]
116
+ return column_name in [i[1] for i in self.run_query(f"PRAGMA table_info({table_name})")]
114
117
 
115
118
  def get_columns(self, table_name: str) -> list:
116
- return [i[1] for i in self.run_code(f"PRAGMA table_info({table_name})")]
119
+ return [i[1] for i in self.run_query(f"PRAGMA table_info({table_name})")]
117
120
 
118
121
  # ____________| RECORD |____________
119
122
  def find_record(self, table_name: str, columns: None | tuple=None, compound: None | tuple=None, condition: None | _Expression=None, bundle: None | tuple=None, filter_bundle: None | tuple=None, sort: None | tuple=None, several: None | int=None, jump: int=0, unique: bool=False):
@@ -151,6 +154,10 @@ class Connect:
151
154
 
152
155
  def add_record(self, table_name: str, record_info: tuple) -> None:
153
156
  self._changes.append((f"INSERT INTO {table_name} VALUES({', '.join(['?']*len(record_info))})", record_info))
157
+
158
+ def add_records(self, table_name: str, info_records: tuple) -> None:
159
+ self._cur.executemany(f"INSERT INTO {table_name} VALUES ({", ".join(["?"]*len(info_records[0]))})", info_records)
160
+ self._con.commit()
154
161
 
155
162
  def delete_record(self, table_name, condition=None):
156
163
  query = f"DELETE FROM {table_name}"
@@ -178,7 +185,7 @@ class Connect:
178
185
  self._changes.append((query, params))
179
186
 
180
187
  def count_record(self, table_name: str) -> int:
181
- return self.run_code(f"SELECT COUNT(*) FROM {table_name}")[0][0]
188
+ return self.run_query(f"SELECT COUNT(*) FROM {table_name}")[0][0]
182
189
 
183
190
  # ____________| INDEX |_________
184
191
  def add_index(self, table_name: str, column_name: str, unique: bool=False) -> None:
@@ -195,22 +202,20 @@ class Connect:
195
202
  self._changes.append((f"DROP VIEW {view_name}",))
196
203
 
197
204
  def exist_view(self, view_name: str) -> bool:
198
- return view_name in [i[0] for i in self.run_code("SELECT name FROM sqlite_master WHERE type='view'")]
205
+ return view_name in [i[0] for i in self.run_query("SELECT name FROM sqlite_master WHERE type='view'")]
206
+
199
207
  # ____________| OTHER |_________
200
208
 
201
- def run_code(self, code: str, parameters: tuple=()) -> list | None:
209
+ def run_query(self, code: str, parameters: tuple=()) -> list:
202
210
  self._cur.execute(code, parameters)
203
211
  self._con.commit()
204
- try:
205
- return self._cur.fetchall()
206
- except:
207
- return None
212
+ return self._cur.fetchall()
208
213
 
209
214
  def close(self):
210
215
  self._con.close()
211
216
 
212
217
 
213
- def save_to_data_base(self) -> None:
218
+ def save_to_database(self) -> None:
214
219
  with self._con:
215
220
  for sql_code in self._changes:
216
221
  self._cur.execute(*sql_code)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sqlthon
3
- Version: 0.0.7
3
+ Version: 0.0.9
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
File without changes