Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def primary_key(self):
return self.kwargs.get('primary_key', jardin.model.Model.primary_key)
def write_values(self):
kw_values = self.kwargs['values']
if isinstance(kw_values, jardin.model.Model):
kw_values = kw_values.attributes
if isinstance(kw_values, dict):
kw_values = [kw_values]
kw_values = pd.DataFrame(kw_values).copy()
kw_values.reset_index(drop=True, inplace=True)
for col in ['stack']:
if col in kw_values:
del kw_values[col]
return kw_values
def joins(self, joins, how):
if joins is None: return []
if isinstance(joins, str):
joins = [joins]
js = []
for j in joins:
if isinstance(j, str):
js += [how, 'JOIN', j]
elif issubclass(j, jardin.model.Model):
js += [self.build_join(j, how=how)]
return js
def __init__(self, **kwargs):
self.attributes = dict()
table_schema = self.__class__.table_schema()
self.attributes[self.primary_key] = kwargs.get(self.primary_key, None)
for column in set(list(table_schema.keys()) + list(kwargs.keys())):
self.attributes[column] = kwargs.get(
column,
table_schema.get(column, {}).get('default'))
# MySQL filth
if self.attributes[column] == '0000-00-00 00:00:00':
self.attributes[column] = None
if column in kwargs:
del kwargs[column]
self.init_relationships()
super(Model, self).__init__(**kwargs)