Пример #1
0
    def test_order_by_expr(self) -> None:
        select = self._factory \
            .select() \
            .from_('users') \
            .order_by(express("FIELD({}, 'off')", identify('status')), 'DESC')

        self.assertSql("SELECT * FROM users ORDER BY FIELD(status, 'off') DESC", select)
        self.assertParams((), select)
Пример #2
0
 def join(self,
          table: str,
          criteria: 'CriteriaInterface',
          join_type: str = '') -> 'SelectQuery':
     """Add a join."""
     sql = '{} JOIN {{}} ON {{}}'.format(join_type.upper()).strip()
     self._joins.append(express(sql, identify(table), criteria))
     return self
Пример #3
0
 def set(self, value_dict: Dict[str, Any]):
     """Sets the column and values with a dictionary."""
     self._set = listing(list(map(
         lambda k, v: express('{} = {}', identify(k), param(v)),
         value_dict.keys(),
         value_dict.values()
     )))
     return self
Пример #4
0
 def into(self, table: str) -> 'InsertQuery':
     """Sets the table."""
     self._into = identify(table)
     return self
Пример #5
0
 def test_identifier(self) -> None:
     f = identify('id')
     self.assertSql('"id"', f)
Пример #6
0
 def test_identity(self) -> None:
     field = identify('id')
     self.assertSql('id', field)
     self.assertParams((), field)
Пример #7
0
 def test_qualified(self) -> None:
     field = identify('public.users.username')
     self.assertSql('public.users.username', field)
     self.assertParams((), field)
Пример #8
0
 def table(self, table: Union[str, 'StatementInterface']) -> 'UpdateQuery':
     """Sets the table."""
     self._table = identify(table)
     return self