sqlthon 0.0.9__tar.gz → 0.0.10__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.9
3
+ Version: 0.0.10
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.9'
7
+ version = '0.0.10'
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.9'
8
+ __version__ = '0.0.10'
9
9
  __author__ = "SAUMS"
10
10
  __email__ = "saums1391@gmail.com"
11
11
  __description__ = "Operate With SQLite3 Buy Simple"
@@ -59,9 +59,10 @@ def _compile(expr):
59
59
 
60
60
 
61
61
  class Connect:
62
- __slots__ = ("_con", "_cur", "_changes")
62
+ __slots__ = ("_con", "_cur", "_changes", "_path")
63
63
  def __init__(self, database_path: str) -> None:
64
64
  from sqlite3 import connect as _cn
65
+ self._path = database_path
65
66
  self._con = _cn(database_path)
66
67
  self._cur = self._con.cursor()
67
68
  self._changes: list = []
@@ -98,6 +99,9 @@ class Connect:
98
99
  def copy_table(self, table_name: str, new_name_table: str) -> None:
99
100
  self._changes.append((f"CREATE TABLE {new_name_table} AS SELECT * FROM {table_name}"),)
100
101
 
102
+ def get_tables(self) -> list:
103
+ return [i[0] for i in self.run_query("SELECT name FROM sqlite_master WHERE type='table'")]
104
+
101
105
  # ____________| COLUMN |____________
102
106
  def add_column(self, table_name: str, column_name: str, column_type: str, limits: list=[]) -> None:
103
107
  if limits:
@@ -204,6 +208,19 @@ class Connect:
204
208
  def exist_view(self, view_name: str) -> bool:
205
209
  return view_name in [i[0] for i in self.run_query("SELECT name FROM sqlite_master WHERE type='view'")]
206
210
 
211
+ # ____________| BACKUP |_________
212
+ def backup_database(self, backup_path: str) -> None:
213
+ from shutil import copy2
214
+ self._con.commit()
215
+ copy2(self._path, backup_path)
216
+
217
+ # ____________| PANDAS |_________
218
+ def to_dataframe(self, table_name: str) -> "pd.DataFrame":
219
+ import pandas as pd
220
+ columns = self.get_columns(table_name)
221
+ result = self.run_query(f"SELECT * FROM {table_name}")
222
+ return pd.DataFrame(result, columns=columns)
223
+
207
224
  # ____________| OTHER |_________
208
225
 
209
226
  def run_query(self, code: str, parameters: tuple=()) -> list:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sqlthon
3
- Version: 0.0.9
3
+ Version: 0.0.10
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