def _update_request(self, cls): fields = cls.get_attrs() request = \ self.get_update_part() \ + self.get_set_part(fields) \ + self.get_search_id_part() return PgsqlCRUD.pgsql_update(request)
def __mass_delete(cls, **kwargs): fields = cls.get_attrs() request = \ 'DELETE ' \ + cls.get_from_part() \ + cls.get_search_part(fields, kwargs) return PgsqlCRUD.pgsql_delete(request)
def _search_request(cls, search_fields): fields = cls.get_attrs() request = \ cls.get_select_part(fields) \ + cls.get_from_part() \ + cls.get_search_part(fields, search_fields) # with open('./xxx.txt', 'a') as file: # file.write(str(request) + '\n') return cls.parse_sql_response(PgsqlCRUD.pgsql_select(request))
def _insert_request(cls, given_values): fields = cls.get_attrs() given_values = cls.check_creating_list(fields, given_values) request = \ cls.get_insert_part(given_values) + \ 'VALUES ' + \ cls.get_values_part(fields, given_values) if PgsqlCRUD.pgsql_insert(request): return cls.get(**given_values) else: return None
def bulk_insert_request(cls, given_rows): fields = cls.get_attrs() for row in given_rows: cls.check_creating_list(fields, row) fields_list = given_rows[0] request = \ cls.get_insert_part(fields_list) + \ 'VALUES ' for row in given_rows: request += (cls.get_values_part(fields, row) + ',') else: request = request[:-1] if PgsqlCRUD.pgsql_insert(request): return MassModel([cls.get(**row) for row in given_rows]) else: None
def _delete_request(self): request = \ 'DELETE ' \ + self.get_from_part() \ + self.get_search_id_part() return PgsqlCRUD.pgsql_delete(request)
def _search_all_request(cls): request = \ cls.get_select_all_part() \ + cls.get_from_part() return cls.parse_sql_response(PgsqlCRUD.pgsql_select(request))