odbms 0.3.0__tar.gz → 0.3.2__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.1
2
2
  Name: odbms
3
- Version: 0.3.0
3
+ Version: 0.3.2
4
4
  Summary: Database client for Mysql, MongoDB and Sqlite
5
5
  Author: Amos Amissah
6
6
  Author-email: theonlyamos@gmail.com
@@ -5,7 +5,7 @@ import sys
5
5
 
6
6
  Database = None
7
7
 
8
- VERSION = "0.2.9"
8
+ VERSION = "0.3.2"
9
9
 
10
10
  def main(args):
11
11
  global parser
@@ -26,7 +26,7 @@ class Model():
26
26
  @classmethod
27
27
  def create_table(cls):
28
28
  """
29
- Create the database table for the model (Only for non-MongoDB databases).
29
+ Create the database table for the model (Only for relational databases).
30
30
  """
31
31
  if DBMS.Database.dbms != 'mongodb':
32
32
  excluded = ['created_at', 'updated_at', 'id']
@@ -62,10 +62,10 @@ class Model():
62
62
  param_type = param.annotation
63
63
 
64
64
  column_type = cls.get_column_type(param_type)
65
- if column_type:
66
- if param_name not in excluded:
67
- column_def = f"{param_name} {column_type}"
68
- columns.append(column_def)
65
+
66
+ if param_name not in excluded:
67
+ column_def = f"{param_name} {column_type}"
68
+ columns.append(column_def)
69
69
 
70
70
  columns += additional_columns.get(DBMS.Database.dbms, [])
71
71
  columns_str = ', '.join(columns)
@@ -103,10 +103,11 @@ class Model():
103
103
  int: "INTEGER",
104
104
  float: "REAL",
105
105
  bool: "BOOLEAN",
106
- list: "TEXT"
106
+ list: "TEXT",
107
+ dict: "TEXT"
107
108
  # Add more mappings as needed
108
109
  }
109
- return type_mapping.get(attr_type, "")
110
+ return type_mapping.get(attr_type, "TEXT")
110
111
 
111
112
  def save(self):
112
113
  '''
@@ -127,7 +128,7 @@ class Model():
127
128
  return DBMS.Database.insert(self.TABLE_NAME, Model.normalise(data, 'params'))
128
129
 
129
130
  # Update the existing record in database
130
- del data['password']
131
+ data.pop('id', None)
131
132
  return DBMS.Database.update(self.TABLE_NAME, self.normalise({'id': self.id}, 'params'), self.normalise(data, 'params'))
132
133
 
133
134
  @staticmethod
@@ -327,7 +328,9 @@ class Model():
327
328
  @return List[Model]
328
329
  '''
329
330
 
330
- return cls(**cls.normalise(DBMS.Database.find_one(cls.TABLE_NAME, cls.normalise(params, 'params'), projection))) # type: ignore
331
+ result = cls.normalise(DBMS.Database.find_one(cls.TABLE_NAME, cls.normalise(params, 'params'), projection))
332
+
333
+ return cls(**result) if len(result.keys()) else None
331
334
 
332
335
  @classmethod
333
336
  def query(cls, column: str, search: str):
@@ -433,9 +436,11 @@ class Model():
433
436
  '''
434
437
 
435
438
  data = self.__dict__.copy()
439
+
440
+ data['created_at'] = data['created_at'].strftime("%a %b %d %Y %H:%M:%S")
441
+ data['updated_at'] = data['updated_at'].strftime("%a %b %d %Y %H:%M:%S")
436
442
 
437
- if 'password' in data.keys():
438
- del data['password']
443
+ data.pop('password', None)
439
444
 
440
445
  return data
441
446
 
@@ -480,13 +485,32 @@ class Model():
480
485
  if optype == 'params':
481
486
  if 'id' in content.keys():
482
487
  content['id'] = str(content['id'])
483
- for key, value in content.items():
484
- if type(value) == list:
485
- content[key] = '::'.join([str(v) for v in value])
486
-
487
- elif type(value) == datetime:
488
- content[key] = value.strftime("%a %b %d %Y %H:%M:%S")
489
- elif type(value) == dict:
490
- content[key] = json.dumps(value) # type: ignore
488
+ for key, value in content.items():
489
+ if type(value) == list:
490
+ content[key] = '::'.join([str(v) for v in value])
491
+
492
+ elif type(value) == datetime:
493
+ content[key] = value.strftime("%a %b %d %Y %H:%M:%S")
494
+ elif type(value) == dict:
495
+ content[key] = json.dumps(value) # type: ignore
496
+ else:
497
+ init_signatures = inspect.signature(cls.__init__)
498
+
499
+ init_parameters = [param for param in init_signatures.parameters.values()
500
+ if param.name != 'self']
501
+
502
+ all_parameters = init_parameters
503
+ type_mapping = [str, int, float, bool, list, dict]
504
+ for param in all_parameters:
505
+ param_name = param.name
506
+ param_type = param.annotation
507
+
508
+ if param_type in type_mapping:
509
+ if param_type is dict:
510
+ content[param_name] = json.loads(content[param_name])
511
+ elif param_type is list:
512
+ content[param_name] = content[param_name].split('::')
513
+ else:
514
+ content[param_name] = param_type(content[param_name])
491
515
 
492
- return content
516
+ return content
@@ -77,7 +77,7 @@ class SqliteDB(ORM):
77
77
 
78
78
  @staticmethod
79
79
  def find(table: str, params: dict = {}, columns: list = ['*']):
80
- query = f'SELECT {', '.join(columns)} FROM {table}'
80
+ query = f'SELECT {", ".join(columns)} FROM {table}'
81
81
 
82
82
  if len(params.keys()):
83
83
  query += ' WHERE '
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: odbms
3
- Version: 0.3.0
3
+ Version: 0.3.2
4
4
  Summary: Database client for Mysql, MongoDB and Sqlite
5
5
  Author: Amos Amissah
6
6
  Author-email: theonlyamos@gmail.com
@@ -1,7 +1,7 @@
1
1
  from importlib.metadata import entry_points
2
2
  from setuptools import setup, find_packages
3
3
 
4
- VERSION = '0.3.0'
4
+ VERSION = '0.3.2'
5
5
 
6
6
  with open('README.md', 'rt') as file:
7
7
  description = file.read()
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes