Ejemplo n.º 1
0
def test_query_union():
    s = ("select * from users union select users.* from organisations "
         "left join users on users.organisation_id = organisations.id")
    q = (Query(User).select().union(Organisation).select(
        fn.wild(User)).left_join(User,
                                 on=[User.organisation_id, Organisation.id]))
    assertSQL(q, s)
Ejemplo n.º 2
0
 def get_by_id(cls, id):
     return (
         Query(cls)
         .select()
         .where(cls.id == id, fn.is_null(cls.tombstoned))
         .execute()
     )
Ejemplo n.º 3
0
    def get_by_email(cls, email):
        user = (
            Query(cls)
            .get_or_none()
            .where(cls.email == email, op.is_null(cls.tombstoned))
            .execute()
        )

        return user
Ejemplo n.º 4
0
def test_has_one_get():
    org = (
        Query(Organisation)
        .get()
        .preload({Organisation.admin: [{Admin.user: [User.name]}]})
        .execute()
    )

    assert org.get("admin") is not None
    assert org["admin"].get("user") is not None
Ejemplo n.º 5
0
def test_has_many_select():
    Query(Organisation).select().preload(Organisation.users).execute()
    assert True
Ejemplo n.º 6
0
def test_has_one_select():
    Query(Organisation).select().preload(Organisation.admin).execute()
    assert True
Ejemplo n.º 7
0
def test_has_many_get():
    org = Query(Organisation).get().preload(Organisation.users).execute()
    assert len(org.get("users")) > 0
Ejemplo n.º 8
0
def test_left_join():
    s = ("select * from users left join organisations "
         "on users.organisation_id = organisations.id")
    q = (Query(User).select().left_join(
        Organisation, on=[User.organisation_id, Organisation.id]))
    assertSQL(q, s)
Ejemplo n.º 9
0
from estoult import Query, op
from .base import assertSQL, User

_query = Query(User).select(User.id)


def test_or():
    s = ("select users.id from users "
         "where ((users.name) = ('Astolfo')) or ((users.id) = (1))")
    q = _query.copy().where(op.or_(User.name == "Astolfo", User.id == 1))
    assertSQL(q, s)


def test_and():
    s = ("select users.id from users "
         "where ((users.name) = ('Astolfo')) and ((users.id) = (1))")
    q = _query.copy().where(op.and_(User.name == "Astolfo", User.id == 1))
    assertSQL(q, s)


def test_in():
    s = "select users.id from users where " "(users.id) in (select users.id from users)"
    q = _query.copy().where(op.in_(User.id, _query))
    assertSQL(q, s)


def test_like():
    s = "select users.id from users where (users.name) like ('%stolf%')"
    q = _query.copy().where(op.like(User.name, "%stolf%"))
    assertSQL(q, s)
Ejemplo n.º 10
0
def test_wildcard_preload_pass():
    Query(User).select().preload({User.data: [Data.value]}).execute()
Ejemplo n.º 11
0
def test_wildcard_preload_fail():
    with pytest.raises(QueryError):
        Query(User).select().preload(User.data).execute()
Ejemplo n.º 12
0
def test_query():
    s = "select * from users"
    q = Query(User).select()
    assertSQL(q, s)
Ejemplo n.º 13
0
def test_wildcard_pass():
    Query(Data).select(Data.value).execute()
Ejemplo n.º 14
0
def test_wildcard_fail():
    with pytest.raises(QueryError):
        Query(Data).select().execute()
Ejemplo n.º 15
0
def test_order_by():
    s = "select * from users order by users.name desc, users.id limit 10 offset 2"
    q = Query(User).select().order_by({
        User.name: "desc"
    }, User.id).limit(10, 2)
    assertSQL(q, s)
Ejemplo n.º 16
0
def test_query_update():
    Query(User).update({
        "name": "Astolfo"
    }).where(User.name == "Charlemagne").execute()
Ejemplo n.º 17
0
 def get_by_name(cls, name):
     return Query(cls).get_or_none().where(cls.name == name).execute()
Ejemplo n.º 18
0
def test_query_delete():
    Query(User).delete().where(User.name == "Charlemagne").execute()
Ejemplo n.º 19
0
 def applied_at(self, id):
     return (Query(RiderMigration).get_or_none().where(
         RiderMigration.migration == id).execute() or {}).get("applied_at")
Ejemplo n.º 20
0
def test_query_specify():
    s = "select users.name from users"
    q = Query(User).select(User.name)
    assertSQL(q, s)