コード例 #1
0
import edgedb
import edgeql_queries

queries = edgeql_queries.from_path("./edgeql", async_driver=False)

conn = edgedb.connect()

movies = queries.movies.select_movies_by_year(conn, year=2020)

print(movies)
コード例 #2
0
import edgedb
from edgeql_queries import from_path

conn = edgedb.connect()
queries = from_path("./queries.edgeql", async_driver=False)

user = queries.select_person_by_ip(conn, user_ip="127.0.0.1")
if user is None:
    print("oops, no user was found")
else:
    print("user:", user.username)
コード例 #3
0
def async_queries(queries_path: pathlib.Path) -> Queries:
    return edgeql_queries.from_path(queries_path)
コード例 #4
0
def sync_queries(queries_path: pathlib.Path) -> Queries:
    return edgeql_queries.from_path(queries_path, async_driver=False)
コード例 #5
0

class Queries(Protocol):
    async def create_movies(self, executor: AsyncIOExecutor) -> None:
        ...

    async def create_new_person(
        self,
        executor: AsyncIOExecutor,
        first_name: str,
        last_name: str,
    ) -> EdgeDBObject:
        ...

    async def create_new_movie(
        self,
        executor: AsyncIOExecutor,
        title: str,
        year: int,
        director_id: UUID,
        person_ids: List[UUID],
    ) -> EdgeDBObject:
        ...

    async def select_movie_by_id(self, executor: AsyncIOExecutor,
                                 id: UUID) -> Movie:
        ...


queries: Queries = cast(Queries, from_path("./app/edgeql"))
コード例 #6
0
import edgeql_queries


class Person(Protocol):
    id: UUID
    first_name: str
    last_name: str


class Queries:
    async def select_users_by_last_name(
        self,
        executor: edgedb.AsyncIOExecutor,
        last_name: str,
    ) -> Set[Person]:
        ...

    async def select_user_by_id(
        self,
        executor: edgedb.AsyncIOExecutor,
        user_id: UUID,
    ) -> Person:
        ...

    async def create_keanu_reeves(self,
                                  executor: edgedb.AsyncIOExecutor) -> None:
        ...


queries = cast(Queries, edgeql_queries.from_path("./queries.edgeql"))
コード例 #7
0
def test_loader_raises_error_when_path_does_not_exist() -> None:
    with pytest.raises(EdgeQLLoadError):
        from_path("wrong_path")
コード例 #8
0
def test_loading_queries_from_single_file(queries_path: pathlib.Path) -> None:
    queries = from_path(queries_path / "movies" / "movies.edgeql")
    assert queries.create_new_movie
コード例 #9
0
def test_loader_raises_error_when_path_is_not_file_or_dir() -> None:
    with pytest.raises(EdgeQLLoadError):
        from_path("/dev/null")