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)
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
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
def into(self, table: str) -> 'InsertQuery': """Sets the table.""" self._into = identify(table) return self
def test_identifier(self) -> None: f = identify('id') self.assertSql('"id"', f)
def test_identity(self) -> None: field = identify('id') self.assertSql('id', field) self.assertParams((), field)
def test_qualified(self) -> None: field = identify('public.users.username') self.assertSql('public.users.username', field) self.assertParams((), field)
def table(self, table: Union[str, 'StatementInterface']) -> 'UpdateQuery': """Sets the table.""" self._table = identify(table) return self