def filter_query(self, filters): for filter in filters: self.query_builder = self.query_builder.where( OPERATOR_URI_MAPPER[filter.op](pypika.Parameter(filter.memory), pypika.Parameter(' ? '))) self.params['where_params'].append(filter.value)
def instantiate(cls, **kwargs): self = super(Postgres, cls).instantiate(**kwargs) keys = self._Crud__field_values.keys() table = pypika.Table(cls._table) query = pypika.PostgreSQLQuery.into(table).columns( *keys ).insert( *[pypika.Parameter("%({})s".format(k)) for k in keys ] ).returning('*') with conn_pool.getconn() as conn: print(conn.autocommit) with conn.cursor() as curr: curr.execute(query.get_sql(), self._Crud__field_values) data = curr.fetchone() for field in self._schema.keys(): self._Crud__field_values[field] = data.get(field, None) setattr(self, field, data.get(field, None)) return self
def pagination_query(self, page: Page): self.query_builder = self.query_builder.where( self.game.id > pypika.Parameter(' ? ')).limit( pypika.Parameter(' ? ')) self.params['where_params'].append(page.last_id) self.params['limit_params'].append(page.limit)
def developer_query(self, developer: str): self.query_builder = self.query_builder.where( self.game.developer == pypika.Parameter(' ? ')) developer = developer.replace('"', '', 2) self.params['where_params'].append(developer)
def name_query(self, name: str): self.query_builder = self.query_builder.where( self.game.name == pypika.Parameter(' ? ')) name = name.replace('"', '', 2) self.params['where_params'].append(name)