dizen-db 1148__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.
dizen_db-1148/PKG-INFO ADDED
@@ -0,0 +1,7 @@
1
+ Metadata-Version: 2.4
2
+ Name: dizen_db
3
+ Version: 1148
4
+ Summary: Table creator ORM
5
+ Author: mrdili131 / Dilmuhammad
6
+ Dynamic: author
7
+ Dynamic: summary
File without changes
@@ -0,0 +1,38 @@
1
+ # helpers
2
+ def not_null(string):
3
+ string = string + ' NOT NULL'
4
+ return string
5
+
6
+ def defaulter(string, val):
7
+ string = string + f' DEFAULT {val}'
8
+ return string
9
+
10
+
11
+ # Fields
12
+ class CharField():
13
+ def __init__(self,max_length=50,default=None,null=True):
14
+ self.max_length = max_length
15
+ self.default = default
16
+ self.null = null
17
+
18
+ def get_query(self):
19
+ self.q = f"VARCHAR({self.max_length})"
20
+ if not self.null:
21
+ self.q = not_null(self.q)
22
+ if self.default is not None:
23
+ self.q = defaulter(self.q,self.default)
24
+ return self.q
25
+
26
+
27
+ class IntegerField():
28
+ def __init__(self,default=None,null=True):
29
+ self.default = default
30
+ self.null = null
31
+
32
+ def get_query(self):
33
+ self.q = f"INTEGER"
34
+ if not self.null:
35
+ self.q = not_null(self.q)
36
+ if self.default:
37
+ self.q = defaulter(self.q,self.default)
38
+ return self.q
@@ -0,0 +1,59 @@
1
+ import sqlite3
2
+ from .fields import *
3
+
4
+ con = sqlite3.connect("database.db")
5
+ cur = con.cursor()
6
+
7
+
8
+ # Models
9
+ class Model:
10
+ def __init__(self):
11
+ self.table_name = self.__class__.__name__.lower()
12
+ self.query = f"CREATE TABLE {self.table_name}(\nid INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE NOT NULL,\n"
13
+
14
+ def save(self):
15
+ for key, value in self.__class__.__dict__.items():
16
+ if '_' not in key:
17
+ q = f'{key} {value.get_query()}'
18
+ self.query += q + ',\n'
19
+ self.query += ');'
20
+ index = self.query.rfind(",")
21
+ if index != -1:
22
+ self.query = self.query[:index] + self.query[index+1:]
23
+ print(f"\n{self.query}\n")
24
+ try:
25
+ res = cur.execute(self.query)
26
+ con.commit()
27
+ except:
28
+ print("Syntax error. Deleting current table. Run one more.")
29
+ cur.execute(f"DROP TABLE {self.table_name};")
30
+
31
+ def get(self,d_attr,attr):
32
+ try:
33
+ d_attr = str(d_attr)
34
+ attr = str(attr)
35
+ res = cur.execute(f"SELECT * FROM {self.table_name} WHERE {d_attr} = '{attr}'")
36
+ return res.fetchone()
37
+ except:
38
+ print(f"Could not get {d_attr} with {attr} from {self.table_name}")
39
+ return None
40
+
41
+ def all(self):
42
+ try:
43
+ res = cur.execute(f"SELECT * FROM {self.table_name}")
44
+ return res.fetchall()
45
+ except:
46
+ print(f"Could not get from {self.table_name}")
47
+ return None
48
+
49
+
50
+ # init
51
+
52
+ def create_table(all_models = []):
53
+ print("Creating table ...")
54
+ try:
55
+ if len(all_models) > 0:
56
+ for i in all_models:
57
+ i().save()
58
+ except:
59
+ print("Could not create tables. Syntax error or you already have this table")
@@ -0,0 +1,7 @@
1
+ Metadata-Version: 2.4
2
+ Name: dizen_db
3
+ Version: 1148
4
+ Summary: Table creator ORM
5
+ Author: mrdili131 / Dilmuhammad
6
+ Dynamic: author
7
+ Dynamic: summary
@@ -0,0 +1,8 @@
1
+ setup.py
2
+ dizen_db/__init__.py
3
+ dizen_db/fields.py
4
+ dizen_db/models.py
5
+ dizen_db.egg-info/PKG-INFO
6
+ dizen_db.egg-info/SOURCES.txt
7
+ dizen_db.egg-info/dependency_links.txt
8
+ dizen_db.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ dizen_db
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
dizen_db-1148/setup.py ADDED
@@ -0,0 +1,10 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ setup(
4
+ name="dizen_db",
5
+ version="1148",
6
+ packages=find_packages(),
7
+ description="Table creator ORM",
8
+ author="mrdili131 / Dilmuhammad",
9
+ install_requires=[]
10
+ )