async def test_crud_array_extend(): c, db, TableOneModel = crud_db_init() await c.update(QueryInfo.from_table_raw(TableOne), values=ValuesToWrite({'arr.array_extend': ['aa', 'bb']}, table=TableOne, try_parse=True)) assert c.last_sql == 'UPDATE "table_one" SET "arr"="arr"||? WHERE "id" IN (?)'
def test_condition_is(): q = QueryInfo.from_table_raw(User, where=[ f(User.nickname).is_(None) ]) cond = q.conditions.items[0] assert cond.op == QUERY_OP_RELATION.IS
async def test_crud_array_prune_distinct(): c, db, TableOneModel = crud_db_init() await c.update(QueryInfo.from_table_raw(TableOne), values=ValuesToWrite( {'arr.array_prune_distinct': ['aa', 'bb']}, table=TableOne, try_parse=True)) assert c.last_sql == 'UPDATE "table_one" SET "arr"=array(SELECT unnest("arr") EXCEPT SELECT unnest(?)) WHERE "id" IN (?)'
def test_dsl_condition_simple(): q = QueryInfo.from_table_raw(User, where=[ User.nickname == 'test' ]) cond = q.conditions.items[0] assert cond.column == User.nickname assert cond.op == QUERY_OP_COMPARE.EQ assert cond.value == 'test'
def test_condition_logic_2(): q = QueryInfo.from_table_raw(User, where=[ (User.nickname == 'test') & ( (User.test >= 5) | (User.test <= 10) ) ]) cond = q.conditions.items[0] assert isinstance(cond, ConditionLogicExpr) assert cond.type == 'and' assert cond.items[0].op == QUERY_OP_COMPARE.EQ assert isinstance(cond.items[1], ConditionLogicExpr) assert cond.items[1].type == 'or' assert cond.items[1].items[1].value == 10
def test_query_select_exclude(): q = QueryInfo.from_table_raw( User, select=[User.id, User.nickname, User.password], select_exclude=[User.nickname]) assert q.select_for_crud == [User.id, User.password]
def test_select_simple2(): q = QueryInfo.from_table_raw(User) assert q.select_for_crud == [User.id, User.nickname, User.username, User.password, User.test]
def test_select_dsl_simple(): q = QueryInfo.from_table_raw(User, select=[User.id, User.nickname, User.password]) assert q.select_for_crud == [User.id, User.nickname, User.password]