sqlthon 0.0.1__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.1/PKG-INFO +24 -0
- sqlthon-0.0.1/README.md +8 -0
- sqlthon-0.0.1/pyproject.toml +31 -0
- sqlthon-0.0.1/setup.cfg +4 -0
- sqlthon-0.0.1/src/sqlthon/__init__.py +11 -0
- sqlthon-0.0.1/src/sqlthon/core.py +106 -0
- sqlthon-0.0.1/src/sqlthon.egg-info/PKG-INFO +24 -0
- sqlthon-0.0.1/src/sqlthon.egg-info/SOURCES.txt +8 -0
- sqlthon-0.0.1/src/sqlthon.egg-info/dependency_links.txt +1 -0
- sqlthon-0.0.1/src/sqlthon.egg-info/top_level.txt +1 -0
sqlthon-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sqlthon
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: A simple package for SQLite3 operations
|
|
5
|
+
Author-email: SAUMS <mohamnown@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/SAUMS-1391/sqlthon
|
|
8
|
+
Project-URL: Repository, https://github.com/SAUMS-1391/sqlthon
|
|
9
|
+
Project-URL: Documentation, https://sqlthon.readthedocs.io/
|
|
10
|
+
Project-URL: Issues, https://github.com/SAUMS-1391/sqlthon/issues
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Requires-Python: >=3.8
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
|
|
17
|
+
# Sqlthon
|
|
18
|
+
|
|
19
|
+
A simple package for SQLite3 operations.
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pip install sqlthon
|
sqlthon-0.0.1/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "sqlthon"
|
|
7
|
+
version = "0.0.1"
|
|
8
|
+
description = "A simple package for SQLite3 operations"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.8"
|
|
11
|
+
license = {text = "MIT"}
|
|
12
|
+
authors = [
|
|
13
|
+
{name = "SAUMS", email = "mohamnown@gmail.com"}
|
|
14
|
+
]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"License :: OSI Approved :: MIT License",
|
|
18
|
+
"Operating System :: OS Independent",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
[project.urls]
|
|
22
|
+
Homepage = "https://github.com/SAUMS-1391/sqlthon"
|
|
23
|
+
Repository = "https://github.com/SAUMS-1391/sqlthon"
|
|
24
|
+
Documentation = "https://sqlthon.readthedocs.io/"
|
|
25
|
+
Issues = "https://github.com/SAUMS-1391/sqlthon/issues"
|
|
26
|
+
|
|
27
|
+
[tool.setuptools]
|
|
28
|
+
package-dir = {"" = "src"}
|
|
29
|
+
|
|
30
|
+
[tool.setuptools.packages.find]
|
|
31
|
+
where = ["src"]
|
sqlthon-0.0.1/setup.cfg
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import sqlite3 as sq
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class DB:
|
|
5
|
+
__slots__ = ("_con", "_cur", "_changes")
|
|
6
|
+
def __init__(self, path: str) -> None:
|
|
7
|
+
self._con = sq.connect(path)
|
|
8
|
+
self._cur = self._con.cursor()
|
|
9
|
+
self._changes = []
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Column:
|
|
13
|
+
__slots__ = ("_name", "_type", "_limits")
|
|
14
|
+
def __init__(self, name_column: str, type: str="", limits: list=[]):
|
|
15
|
+
self._name = name_column
|
|
16
|
+
self._type = " "+type if type else ""
|
|
17
|
+
self._limits = limits
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def add_table(self, name_table: str, *columns: Column, if_not_exist: bool=False) -> None:
|
|
21
|
+
text = "CREATE TABLE "
|
|
22
|
+
if if_not_exist:
|
|
23
|
+
text += "IF NOT EXISTS "
|
|
24
|
+
text += f"{name_table} ("
|
|
25
|
+
for column in columns:
|
|
26
|
+
text += column._name + column._type
|
|
27
|
+
if column._limits:
|
|
28
|
+
text += " " + str(column._limits).replace("[", "").replace("'", "").replace("]", "").replace(",", "")
|
|
29
|
+
text += ", "
|
|
30
|
+
text = f"{text[:-2]})"
|
|
31
|
+
|
|
32
|
+
self._changes.append((text,))
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def add_record(self, name_table: str, *record: list) -> None:
|
|
36
|
+
self._changes.append((f"INSERT INTO {name_table} VALUES ({"?, "*(len(record)-1)}?)", record))
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def find_table(self, word: str="") -> list:
|
|
40
|
+
self._cur.execute("SELECT name FROM sqlite_master WHERE type='table'")
|
|
41
|
+
tables = [tup[0] for tup in self._cur.fetchall()]
|
|
42
|
+
return [table for table in tables if word in table]
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def find_record(self, name_table: str, columns: list|str="*", where: dict|str="") -> list:
|
|
46
|
+
text = "SELECT "
|
|
47
|
+
if type(columns) == list:
|
|
48
|
+
columns = str(columns).replace("[", "").replace("]", "").replace("'", "")
|
|
49
|
+
text += columns+" FROM "+name_table
|
|
50
|
+
if where:
|
|
51
|
+
equal = " WHERE " + str(list(where.keys())).replace("]", ", ").replace("[", "").replace("'", "").replace(", ", "=? and ")[:-5]
|
|
52
|
+
where = tuple(where.values())
|
|
53
|
+
try:
|
|
54
|
+
text += equal
|
|
55
|
+
except:
|
|
56
|
+
pass
|
|
57
|
+
|
|
58
|
+
self._cur.execute(text, where)
|
|
59
|
+
return self._cur.fetchall()
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def delete_table(self, name_table: str):
|
|
63
|
+
self._changes.append((f"DROP TABLE {name_table}",))
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def delete_record(self, name_table: str, info_record: dict={}) -> None:
|
|
67
|
+
text = f"DELETE FROM {name_table}"
|
|
68
|
+
if info_record:
|
|
69
|
+
text += " WHERE "
|
|
70
|
+
equal = tuple(info_record.values())
|
|
71
|
+
info_record = str(list(info_record.keys())).replace("[", "").replace("'", "").replace("]", ", ").replace(", ", "=? ").replace(" ", " AND ")[:-5]
|
|
72
|
+
try:
|
|
73
|
+
equal
|
|
74
|
+
self._changes.append((text+info_record, equal))
|
|
75
|
+
except:
|
|
76
|
+
self._changes.append((text,))
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def edit_record(self, name_table: str, new_record: dict, old_record: dict) -> None:
|
|
80
|
+
text = "UPDATE "+name_table+" SET "
|
|
81
|
+
equal = tuple(old_record.values())+tuple(new_record.values())
|
|
82
|
+
old_record = str(list(old_record.keys())).replace("[", "").replace("'", "").replace("]", ", ").replace(", ", "=? ").replace(" ", ", ")[:-2]
|
|
83
|
+
new_record = str(list(new_record.keys())).replace("[", "").replace("'", "").replace("]", ", ").replace(", ", "=? ").replace(" ", " AND ")[:-4]
|
|
84
|
+
|
|
85
|
+
text += old_record+" WHERE "+new_record
|
|
86
|
+
self._changes.append((text, equal))
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def run_code(self, code: str, parameters: tuple=()) -> list | None:
|
|
90
|
+
self._cur.execute(code, parameters)
|
|
91
|
+
self._con.commit()
|
|
92
|
+
try:
|
|
93
|
+
return self._cur.fetchall()
|
|
94
|
+
except:
|
|
95
|
+
pass
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def close(self):
|
|
99
|
+
self._con.close()
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def save_to_data_base(self) -> None:
|
|
103
|
+
with self._con:
|
|
104
|
+
for sql_code in self._changes:
|
|
105
|
+
self._cur.execute(*sql_code)
|
|
106
|
+
self._changes.clear()
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sqlthon
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: A simple package for SQLite3 operations
|
|
5
|
+
Author-email: SAUMS <mohamnown@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/SAUMS-1391/sqlthon
|
|
8
|
+
Project-URL: Repository, https://github.com/SAUMS-1391/sqlthon
|
|
9
|
+
Project-URL: Documentation, https://sqlthon.readthedocs.io/
|
|
10
|
+
Project-URL: Issues, https://github.com/SAUMS-1391/sqlthon/issues
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Requires-Python: >=3.8
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
|
|
17
|
+
# Sqlthon
|
|
18
|
+
|
|
19
|
+
A simple package for SQLite3 operations.
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pip install sqlthon
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
sqlthon
|