valk-db 0.1.0__py3-none-any.whl

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.
valk_db/__init__.py ADDED
@@ -0,0 +1,5 @@
1
+ """
2
+ Valk DB - A Python database library.
3
+ """
4
+
5
+ __version__ = "0.1.0"
valk_db/main.py ADDED
@@ -0,0 +1,69 @@
1
+ import sqlite3, re
2
+
3
+ class Database():
4
+ """Create a Database and manage it. In all table, an 'id' column will be create.
5
+
6
+ # Args:
7
+ - name (str): The name of the DB (without .db at the end)
8
+
9
+ - rows (list): A list of dict, just like that : [{"name": "email", "type": "int NOT NULL"}]
10
+
11
+ - path (str) (optionnal): The Path where the Database will me created, leave blank will create it in the same folder as your current file
12
+
13
+ # Raises:
14
+ - TypeError: This error is raised when you give an incorrect variable
15
+
16
+ - ValueError: This error is raised when you put a wrong variable
17
+
18
+ """
19
+ def __init__(self, name: str, rows: list, path: str = ""):
20
+
21
+ if not isinstance(name, str): raise TypeError("The name of the Database need to be a string.")
22
+ if not isinstance(rows, list): raise TypeError("Rows of the Database need to be a list.")
23
+ if not isinstance(path, str): raise TypeError("The path of the Database need to be a string.")
24
+
25
+ self.name = name if ".db" in name else name + ".db"
26
+ self.rows = rows
27
+ self.path = self.name if not path else path + f"/{self.name}"
28
+
29
+ self.conn = sqlite3.connect(self.path)
30
+ self.cursor = self.conn.cursor()
31
+
32
+ command = f"""CREATE TABLE IF NOT EXISTS {name.replace(".db", "")} (
33
+ id INTEGER PRIMARY KEY AUTOINCREMENT
34
+ """
35
+
36
+ for row in rows:
37
+ if not "name" in row: raise ValueError(f"You forgot to give the name of the column on this row:\n{row}")
38
+ if not "type" in row: raise ValueError(f"You forgot to give the type of the column on this row:\n{row}")
39
+
40
+ if not isinstance(row["name"], str): raise TypeError(f"The name of the column need to be a string.\nRow: {row}")
41
+ if not isinstance(row["type"], str): raise TypeError(f"The type of the column need to be a string.\nRow: {row}")
42
+
43
+ if not re.match(r"^[a-zA-Z0-9_]+$", row["name"]):
44
+ raise ValueError(
45
+ f"Invalid column name '{row['name']}'. Use only letters, numbers and"
46
+ " underscores."
47
+ )
48
+
49
+ command += f",\n{row['name']} {row['type']}"
50
+
51
+ command += ")"
52
+ self.cursor.commit(command)
53
+
54
+ def execute(self, command: str, params: tuple = ()) -> bool | str:
55
+ """Execute a SQL Command on the Database.
56
+
57
+ # Args:
58
+ - command (str): The SQL Command to run
59
+
60
+ - params (tuple) (optionnal): The parameters to add when the command is run
61
+
62
+ # Returns:
63
+ - bool: Return if the command has been run successfully or not
64
+
65
+ - str: If the command didn't run correctly, return the error
66
+ """
67
+
68
+
69
+
@@ -0,0 +1,27 @@
1
+ Metadata-Version: 2.4
2
+ Name: valk_db
3
+ Version: 0.1.0
4
+ Project-URL: Homepage, https://valk-solutions/projects/valk_db
5
+ Project-URL: Repository, https://github.com/ValkPy/valk_db
6
+ Author-email: ValkPy <valk.py.dev@gmail.com>
7
+ License-File: LICENSE
8
+ Requires-Python: >=3.8
9
+ Description-Content-Type: text/markdown
10
+
11
+ # Valk DB
12
+
13
+ A simple and efficient Python library.
14
+
15
+ ## Installation
16
+
17
+ pip install valk_db
18
+
19
+ ## Quick Start
20
+
21
+ import valk_db
22
+
23
+ # Usage example coming soon...
24
+
25
+ ## License
26
+
27
+ [MIT](LICENSE)
@@ -0,0 +1,6 @@
1
+ valk_db/__init__.py,sha256=EWh5zkwGIlLQfJaGJhY0z5EWB41hjK9ew2N1VJIEbJM,71
2
+ valk_db/main.py,sha256=36rgBkwOtyE4zZH3R7RqE_yKDKTCiSMTAFjCzoFuRsc,2911
3
+ valk_db-0.1.0.dist-info/METADATA,sha256=A65slA77DTHPIyaBbfAQfGqxXk8HNN8KUiacS5o3QLE,483
4
+ valk_db-0.1.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
5
+ valk_db-0.1.0.dist-info/licenses/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ valk_db-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.27.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
File without changes