odbms 0.3.1__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.
- {odbms-0.3.1/odbms.egg-info → odbms-0.3.2}/PKG-INFO +1 -1
- {odbms-0.3.1 → odbms-0.3.2}/odbms/app.py +1 -1
- {odbms-0.3.1 → odbms-0.3.2}/odbms/model.py +44 -20
- {odbms-0.3.1 → odbms-0.3.2/odbms.egg-info}/PKG-INFO +1 -1
- {odbms-0.3.1 → odbms-0.3.2}/setup.py +1 -1
- {odbms-0.3.1 → odbms-0.3.2}/LICENSE +0 -0
- {odbms-0.3.1 → odbms-0.3.2}/MANIFEST.in +0 -0
- {odbms-0.3.1 → odbms-0.3.2}/README.md +0 -0
- {odbms-0.3.1 → odbms-0.3.2}/odbms/__init__.py +0 -0
- {odbms-0.3.1 → odbms-0.3.2}/odbms/database.py +0 -0
- {odbms-0.3.1 → odbms-0.3.2}/odbms/dbms.py +0 -0
- {odbms-0.3.1 → odbms-0.3.2}/odbms/orms/__init__.py +0 -0
- {odbms-0.3.1 → odbms-0.3.2}/odbms/orms/base.py +0 -0
- {odbms-0.3.1 → odbms-0.3.2}/odbms/orms/mongodb.py +0 -0
- {odbms-0.3.1 → odbms-0.3.2}/odbms/orms/mysqldb.py +0 -0
- {odbms-0.3.1 → odbms-0.3.2}/odbms/orms/postgresqldb.py +0 -0
- {odbms-0.3.1 → odbms-0.3.2}/odbms/orms/sqlitedb.py +0 -0
- {odbms-0.3.1 → odbms-0.3.2}/odbms.egg-info/SOURCES.txt +0 -0
- {odbms-0.3.1 → odbms-0.3.2}/odbms.egg-info/dependency_links.txt +0 -0
- {odbms-0.3.1 → odbms-0.3.2}/odbms.egg-info/requires.txt +0 -0
- {odbms-0.3.1 → odbms-0.3.2}/odbms.egg-info/top_level.txt +0 -0
- {odbms-0.3.1 → odbms-0.3.2}/setup.cfg +0 -0
|
@@ -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
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
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
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|