BezdarSQL 1.0__tar.gz → 1.1.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: BezdarSQL
3
- Version: 1.0
3
+ Version: 1.1.1
4
4
  Summary: My little SQL ORM for the ones who called bezdars
5
5
  Author-email: boliklevik@gmail.com
6
6
  Dynamic: author-email
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: BezdarSQL
3
- Version: 1.0
3
+ Version: 1.1.1
4
4
  Summary: My little SQL ORM for the ones who called bezdars
5
5
  Author-email: boliklevik@gmail.com
6
6
  Dynamic: author-email
@@ -9,9 +9,9 @@ def select(table, value='*', filter_by=None, count=1):
9
9
  request += ' where '
10
10
  for index, fil in enumerate(filters):
11
11
  if index > 1:
12
- request += f'and {fil}={filters[fil]} '
12
+ request += f'and {fil.owner.__tablename__}.{fil.name}={repr(filters[fil])} '
13
13
  else:
14
- request += f'{fil}={filters[fil]} '
14
+ request += f'{fil.owner.__tablename__}.{fil.name}={repr(filters[fil])} '
15
15
  else:
16
16
  request += ';'
17
17
 
@@ -33,13 +33,11 @@ def select(table, value='*', filter_by=None, count=1):
33
33
  results = cursor.fetchall()
34
34
 
35
35
  attrsintable = [i for i in table.__dict__ if not '__' in i]
36
- attrs = {}
37
36
  objects = []
38
37
  for result in results:
39
- for index, attr in enumerate(attrsintable):
40
- attrs[attr] = result[index]
41
38
  obj = table()
42
- obj.__dict__.update(attrs)
39
+ for index, attr in enumerate(attrsintable):
40
+ obj.__dict__[attr] = result[index]
43
41
  objects.append(obj)
44
42
 
45
43
  return objects
@@ -48,6 +46,59 @@ def select(table, value='*', filter_by=None, count=1):
48
46
  raise _e
49
47
 
50
48
 
49
+ def select_join(tables, value='*', filter_on=None, filter_by=None, count=1):
50
+ request = f'select {value} from '
51
+ for index, table in enumerate(tables):
52
+ if index == 0:
53
+ request += f'{table.__tablename__} '
54
+ else:
55
+ request += f'join {table.__tablename__} on '
56
+ if filter_on:
57
+ for indexx, fil in enumerate(filter_on):
58
+ if indexx > 1:
59
+ request += f'and {fil.owner.__tablename__}.{fil.name}={filter_on[fil].owner.__tablename__}.{filter_on[fil].name} '
60
+ else:
61
+ request += f'{fil.owner.__tablename__}.{fil.name}={filter_on[fil].owner.__tablename__}.{filter_on[fil].name} '
62
+ elif filter_by:
63
+ for index, fil in enumerate(filter_by):
64
+ if index > 1:
65
+ request += f'and {fil.owner.__tablename__}.{fil.name}={repr(filter_by[fil])} '
66
+ else:
67
+ request += f'{fil.owner.__tablename__}.{fil.name}={repr(filter_by[fil])} '
68
+
69
+ try:
70
+ with psycopg2.connect(
71
+ host=host,
72
+ port=port,
73
+ user=user,
74
+ database=db_name,
75
+ password=password,
76
+ ) as connection:
77
+ connection.autocommit = True
78
+ with connection.cursor() as cursor:
79
+ cursor.execute(request + ';')
80
+
81
+ if count >= 0:
82
+ results = cursor.fetchmany(count)
83
+ elif count == -1:
84
+ results = cursor.fetchall()
85
+
86
+ objects = []
87
+ for result in results:
88
+ for index, table in enumerate(tables):
89
+ attrsintable = [i for i in table.__dict__ if not '__' in i]
90
+ obj = table()
91
+ for index, attr in enumerate(attrsintable):
92
+ obj.__dict__[attr] = result[index]
93
+ objects.append(obj)
94
+ result = result[len(attrsintable):]
95
+
96
+ return objects
97
+
98
+ except Exception as _e:
99
+ raise _e
100
+
101
+
51
102
  def insert(table_obj):
52
103
  request = f'insert into {table_obj.__tablename__} ('
53
104
  attrs = [i for i in table_obj.__dict__ if '__' not in i]
@@ -5,6 +5,12 @@ class Column:
5
5
  def __init__(self, **kwargs):
6
6
  self.autoincrement = kwargs.get('autoincrement')
7
7
 
8
+
9
+ def __set_name__(self, owner, name):
10
+ self.owner = owner
11
+ self.name = name
12
+
13
+
8
14
  @dataclasses.dataclass
9
15
  class Base:
10
- __tablename__ = None
16
+ __tablename__ = None
@@ -1,7 +1,7 @@
1
1
  from setuptools import setup
2
2
 
3
3
  setup(name='BezdarSQL',
4
- version='1.0',
4
+ version='1.1.1',
5
5
  description='My little SQL ORM for the ones who called bezdars',
6
6
  packages=['bezdarsql'],
7
7
  author_email='boliklevik@gmail.com',
File without changes
File without changes