def _get_select_where_sql(cls, args=[]): ''' search[('name', '=', 10)] ''' fld_types = {} new_filter = [] for name, field in inspect.getmembers(cls): if isinstance(field, Char) or isinstance(field, Integer) or \ isinstance(field, Float) or isinstance(field, Datetime) or \ isinstance(field, Date): fld_types[name] = field.data_type for item in args: if type(item) == tuple: if fld_types.get(item[0]) == "INTEGER": new_filter.append((item[0], item[1], int(item[2]))) if fld_types.get(item[0]) == "VARCHAR": new_filter.append((item[0], item[1], "'{x}'".format(x=str(item[2])))) if fld_types.get(item[0] == "BOOLEAN"): new_filter.append((item[0], item[1], 'true' if item[2] else 'false')) if fld_types.get(item[0] in ["TIMESTAMP", "DATE"]): new_filter.append((item[0], item[1], item[2])) if fld_types.get(item[0] == "DECIMAL"): new_filter.append((item[0], item[1], float(item[2]))) if item[0] == 'id': new_filter.append((item[0], item[1], item[2])) else: new_filter.append(item) fld_types['id'] = "INTEGER" return sql._search_flds_where_(tbname=cls._get_name(), colist=fld_types.keys(), filters=new_filter)
async def create(self, vals={}): cls = self.__class__ newObj = cls.clspartum() newObj._fld_value_setter(vals=vals) fields, values = newObj._fld_value_casting(classmebers=inspect.getmembers(cls)) sqlQ = sql._insert_sql_(tbname=cls._get_name(), colist=fields, valist=values) res = await ormConfig.environ._execute(sqlQ) return await newObj.browse(ids=[int(CelertixTools.id_parseser(res))])
async def write(self, vals={}): cls = self.__class__ self._fld_value_setter(vals=vals) fields, values = self._fld_value_casting(classmebers=inspect.getmembers(cls)) combin_l = [] for index, fld in enumerate(fields): combin_l.append((fld, '=', values[index])) query = sql._update_sql(tbname=cls._get_name(), vals=combin_l, ids=self._id) res = await ormConfig.environ._execute(query) return True
def _migrate_new_cols(cls, existcolist=[]): colist = [] dtype = [] for name, field in inspect.getmembers(cls): if isinstance(field, Char) or isinstance(field, Integer) or \ isinstance(field, Float) or isinstance(field, Datetime) or \ isinstance(field, Date): if name not in tuple(list(existcolist)[0]): colist.append(name) dtype.append(field.data_type) elif isinstance(field, ForeignKey): if name not in tuple(list(existcolist)[0]): colist.append(name + "_id") dtype.append("INTEGER") if colist and dtype: return sql.add_new_cols(tbname=cls._get_name(), colist=colist, dtypels=dtype) return None
async def get_all_cols(self, tbname): return await self._execute(sqlcommand=sql.select_all_columns(tbname=tbname))
async def tables(self): return await self._execute(sqlcommand=sql.get_all_tables())
async def unlink(self): cls = self.__class__ query = sql._delete_sql(tbname=cls._get_name(), ids=self._id) await ormConfig.environ._execute(query)