def delete(self, **kwargs): if kwargs: delete_filter = self.get_update_filter(kwargs) table = sqlines.DELETE_WHERE.format(self.table_name, delete_filter) else: table = sqlines.DELETE.format(self.table_name) connection.execute(table)
def update(self, **kwargs): table_args = self.get_update_args() if kwargs: update_filter = self.get_update_filter(kwargs) table = sqlines.UPDATE_WHERE.format(self.table_name, ', '.join(table_args), update_filter) else: table = sqlines.UPDATE.format(self.table_name, ', '.join(table_args)) connection.execute(table) connection.commit()
def save(self): table_args = self.get_arg_table() if table_args: if type(table_args).__name__.lower() == 'list': table = sqlines.SAVE.format(self.table_name, ', '.join(table_args)) else: table = sqlines.SAVE_DICT.format(self.table_name, ', '.join(table_args[0]), ', '.join(table_args[1])) connection.execute(table) connection.commit() else: logging.info('Нет значений для записи в таблицу!') raise EmptyArgsException('No values to write to the table!')
def filter(self, **kwargs): filter_args = self.get_filter_args(kwargs) if not filter_args: logging.info('Нет аргументов для фильтра!') raise EmptyArgsException('Missing required arguments!') field_list = self.field_parse() select = sqlines.FILTER.format(field_list, self.table_name, ' AND '.join(filter_args)) try: select = connection.execute(select) return select.fetchone() except OperationalError as o: logging.info(o)
def between(self, *args): try: b_args = self.get_between_ars(args) field_list = self.field_parse() select = sqlines.BETWEEN.format(field_list, self.table_name, b_args[0], ' AND '.join(b_args[1:])) try: select = connection.execute(select) return select.fetchall() except KeyError as k: logging.info(k) except TypeError: logging.info('Недопустимый тип аргументов!')
def order_by_asc(self, order_arg): field_list = self.field_parse() select = sqlines.ORDER_BY_ASC.format(field_list, self.table_name, str(order_arg)) select = connection.execute(select) return select.fetchall()
def all(self): select_all = sqlines.ALL.format(self.table_name) q_all = connection.execute(select_all) return q_all.fetchall()
def create(self): field_list = self.get_field_name() table = sqlines.CREATE.format(self.table_name, ', '.join(field_list)) connection.execute(table) connection.commit()
def foreign_keys_on(self): f = sqlines.PRAGMA connection.execute(f) connection.commit()