BezdarSQL 1.0__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.
- bezdarsql-1.0/BezdarSQL.egg-info/PKG-INFO +7 -0
- bezdarsql-1.0/BezdarSQL.egg-info/SOURCES.txt +10 -0
- bezdarsql-1.0/BezdarSQL.egg-info/dependency_links.txt +1 -0
- bezdarsql-1.0/BezdarSQL.egg-info/not-zip-safe +1 -0
- bezdarsql-1.0/BezdarSQL.egg-info/top_level.txt +1 -0
- bezdarsql-1.0/PKG-INFO +7 -0
- bezdarsql-1.0/bezdarsql/__init__.py +137 -0
- bezdarsql-1.0/bezdarsql/base.py +10 -0
- bezdarsql-1.0/bezdarsql/config.py +9 -0
- bezdarsql-1.0/setup.cfg +4 -0
- bezdarsql-1.0/setup.py +8 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
setup.cfg
|
|
2
|
+
setup.py
|
|
3
|
+
BezdarSQL.egg-info/PKG-INFO
|
|
4
|
+
BezdarSQL.egg-info/SOURCES.txt
|
|
5
|
+
BezdarSQL.egg-info/dependency_links.txt
|
|
6
|
+
BezdarSQL.egg-info/not-zip-safe
|
|
7
|
+
BezdarSQL.egg-info/top_level.txt
|
|
8
|
+
bezdarsql/__init__.py
|
|
9
|
+
bezdarsql/base.py
|
|
10
|
+
bezdarsql/config.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
bezdarsql
|
bezdarsql-1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
from .config import *
|
|
2
|
+
import psycopg2
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def select(table, value='*', filter_by=None, count=1):
|
|
6
|
+
request = f'select {value} from {table.__tablename__}'
|
|
7
|
+
filters = filter_by
|
|
8
|
+
if filters:
|
|
9
|
+
request += ' where '
|
|
10
|
+
for index, fil in enumerate(filters):
|
|
11
|
+
if index > 1:
|
|
12
|
+
request += f'and {fil}={filters[fil]} '
|
|
13
|
+
else:
|
|
14
|
+
request += f'{fil}={filters[fil]} '
|
|
15
|
+
else:
|
|
16
|
+
request += ';'
|
|
17
|
+
|
|
18
|
+
try:
|
|
19
|
+
with psycopg2.connect(
|
|
20
|
+
host=host,
|
|
21
|
+
port=port,
|
|
22
|
+
user=user,
|
|
23
|
+
database=db_name,
|
|
24
|
+
password=password,
|
|
25
|
+
) as connection:
|
|
26
|
+
connection.autocommit = True
|
|
27
|
+
with connection.cursor() as cursor:
|
|
28
|
+
cursor.execute(request + ';')
|
|
29
|
+
|
|
30
|
+
if count >= 0:
|
|
31
|
+
results = cursor.fetchmany(count)
|
|
32
|
+
elif count == -1:
|
|
33
|
+
results = cursor.fetchall()
|
|
34
|
+
|
|
35
|
+
attrsintable = [i for i in table.__dict__ if not '__' in i]
|
|
36
|
+
attrs = {}
|
|
37
|
+
objects = []
|
|
38
|
+
for result in results:
|
|
39
|
+
for index, attr in enumerate(attrsintable):
|
|
40
|
+
attrs[attr] = result[index]
|
|
41
|
+
obj = table()
|
|
42
|
+
obj.__dict__.update(attrs)
|
|
43
|
+
objects.append(obj)
|
|
44
|
+
|
|
45
|
+
return objects
|
|
46
|
+
|
|
47
|
+
except Exception as _e:
|
|
48
|
+
raise _e
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def insert(table_obj):
|
|
52
|
+
request = f'insert into {table_obj.__tablename__} ('
|
|
53
|
+
attrs = [i for i in table_obj.__dict__ if '__' not in i]
|
|
54
|
+
for index, attr in enumerate(attrs):
|
|
55
|
+
value = getattr(table_obj, attr)
|
|
56
|
+
if hasattr(value, 'autoincrement'):
|
|
57
|
+
if not value.autoincrement:
|
|
58
|
+
request += f'{attr}' + (', ' if not index + 1 == len(attrs) else '')
|
|
59
|
+
else:
|
|
60
|
+
request += f'{attr}' + (', ' if not index + 1 == len(attrs) else '')
|
|
61
|
+
|
|
62
|
+
request += ') values ('
|
|
63
|
+
for index, attr in enumerate(attrs):
|
|
64
|
+
value = getattr(table_obj, attr)
|
|
65
|
+
if hasattr(value, 'autoincrement'):
|
|
66
|
+
if not value.autoincrement:
|
|
67
|
+
request += repr(value) + (', ' if not index + 1 == len(attrs) else ');')
|
|
68
|
+
else:
|
|
69
|
+
request += repr(value) + (', ' if not index + 1 == len(attrs) else ');')
|
|
70
|
+
|
|
71
|
+
try:
|
|
72
|
+
with psycopg2.connect(
|
|
73
|
+
host=host,
|
|
74
|
+
port=port,
|
|
75
|
+
user=user,
|
|
76
|
+
database=db_name,
|
|
77
|
+
password=password,
|
|
78
|
+
) as connection:
|
|
79
|
+
connection.autocommit = True
|
|
80
|
+
with connection.cursor() as cursor:
|
|
81
|
+
cursor.execute(request)
|
|
82
|
+
return True
|
|
83
|
+
|
|
84
|
+
except Exception as _e:
|
|
85
|
+
print('error', _e)
|
|
86
|
+
return False
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def update(table, **kwargs):
|
|
90
|
+
request = f'update {table.__tablename__} set '
|
|
91
|
+
values = kwargs['values']
|
|
92
|
+
for index, value in enumerate(values):
|
|
93
|
+
request += f'{value}={repr(values[value])} ' + (', ' if index + 1 != len(values) else 'where ')
|
|
94
|
+
|
|
95
|
+
where_s = kwargs['where']
|
|
96
|
+
for index, where in enumerate(where_s):
|
|
97
|
+
request += f'{where}={repr(where_s[where])} ' + (', ' if index + 1 != len(where_s) else ';')
|
|
98
|
+
|
|
99
|
+
try:
|
|
100
|
+
with psycopg2.connect(
|
|
101
|
+
host=host,
|
|
102
|
+
port=port,
|
|
103
|
+
user=user,
|
|
104
|
+
database=db_name,
|
|
105
|
+
password=password,
|
|
106
|
+
) as connection:
|
|
107
|
+
connection.autocommit = True
|
|
108
|
+
with connection.cursor() as cursor:
|
|
109
|
+
cursor.execute(request)
|
|
110
|
+
return True
|
|
111
|
+
|
|
112
|
+
except Exception as _e:
|
|
113
|
+
print('error', _e)
|
|
114
|
+
return False
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def delete(table, **kwargs):
|
|
118
|
+
request = f'delete from {table.__tablename__} where '
|
|
119
|
+
where_s = kwargs['where']
|
|
120
|
+
for index, where in enumerate(where_s):
|
|
121
|
+
request += f'{where}={repr(where_s[where])} ' + ('and ' if index + 1 != len(where_s) else ';')
|
|
122
|
+
|
|
123
|
+
try:
|
|
124
|
+
with psycopg2.connect(
|
|
125
|
+
host=host,
|
|
126
|
+
port=port,
|
|
127
|
+
user=user,
|
|
128
|
+
database=db_name,
|
|
129
|
+
password=password,
|
|
130
|
+
) as connection:
|
|
131
|
+
connection.autocommit = True
|
|
132
|
+
with connection.cursor() as cursor:
|
|
133
|
+
cursor.execute(request)
|
|
134
|
+
return True
|
|
135
|
+
except Exception as _e:
|
|
136
|
+
print('error', _e)
|
|
137
|
+
return False
|
bezdarsql-1.0/setup.cfg
ADDED