Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    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
Exemplo n.º 3
0
 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)
Exemplo n.º 4
0
 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)
Exemplo n.º 5
0
 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)