BezdarSQL 1.0__tar.gz → 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
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
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,52 @@ 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=(), 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
+ for indexx, fil in enumerate(filter_on):
57
+ if indexx > 1:
58
+ request += f'and {fil.owner.__tablename__}.{fil.name}={filter_on[fil].owner.__tablename__}.{filter_on[fil].name} '
59
+ else:
60
+ request += f'{fil.owner.__tablename__}.{fil.name}={filter_on[fil].owner.__tablename__}.{filter_on[fil].name} '
61
+
62
+ try:
63
+ with psycopg2.connect(
64
+ host=host,
65
+ port=port,
66
+ user=user,
67
+ database=db_name,
68
+ password=password,
69
+ ) as connection:
70
+ connection.autocommit = True
71
+ with connection.cursor() as cursor:
72
+ cursor.execute(request + ';')
73
+
74
+ if count >= 0:
75
+ results = cursor.fetchmany(count)
76
+ elif count == -1:
77
+ results = cursor.fetchall()
78
+
79
+ objects = []
80
+ for result in results:
81
+ for index, table in enumerate(tables):
82
+ attrsintable = [i for i in table.__dict__ if not '__' in i]
83
+ obj = table()
84
+ for index, attr in enumerate(attrsintable):
85
+ obj.__dict__[attr] = result[index]
86
+ objects.append(obj)
87
+ result = result[len(attrsintable):]
88
+
89
+ return objects
90
+
91
+ except Exception as _e:
92
+ raise _e
93
+
94
+
51
95
  def insert(table_obj):
52
96
  request = f'insert into {table_obj.__tablename__} ('
53
97
  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',
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