Skip to content

Commit

Permalink
Use Executor on generated code for Client/Tx
Browse files Browse the repository at this point in the history
  • Loading branch information
fantix committed Nov 2, 2022
1 parent a912511 commit 20020f2
Show file tree
Hide file tree
Showing 25 changed files with 70 additions and 70 deletions.
8 changes: 4 additions & 4 deletions edgedb/codegen/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,9 @@ def _generate(
print(f"def {name}(", file=buf)
self._imports.add("edgedb")
if self._async:
print(f"{INDENT}client: edgedb.AsyncIOClient,", file=buf)
print(f"{INDENT}executor: edgedb.AsyncIOExecutor,", file=buf)
else:
print(f"{INDENT}client: edgedb.Client,", file=buf)
print(f"{INDENT}executor: edgedb.Executor,", file=buf)
if kw_only:
print(f"{INDENT}*,", file=buf)
for name, arg in args.items():
Expand All @@ -337,9 +337,9 @@ def _generate(
rt = "return "

if self._async:
print(f"{INDENT}{rt}await client.{method}(", file=buf)
print(f"{INDENT}{rt}await executor.{method}(", file=buf)
else:
print(f"{INDENT}{rt}client.{method}(", file=buf)
print(f"{INDENT}{rt}executor.{method}(", file=buf)
print(f'{INDENT}{INDENT}"""\\', file=buf)
print(
textwrap.indent(
Expand Down
4 changes: 2 additions & 2 deletions tests/codegen/linked/test_linked_async_edgeql.py.assert
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import edgedb


async def test_linked(
client: edgedb.AsyncIOClient,
executor: edgedb.AsyncIOExecutor,
) -> int:
return await client.query_single(
return await executor.query_single(
"""\
select 42\
""",
Expand Down
4 changes: 2 additions & 2 deletions tests/codegen/linked/test_linked_edgeql.py.assert
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import edgedb


def test_linked(
client: edgedb.Client,
executor: edgedb.Executor,
) -> int:
return client.query_single(
return executor.query_single(
"""\
select 42\
""",
Expand Down
12 changes: 6 additions & 6 deletions tests/codegen/test-project1/generated_async_edgeql.py.assert
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ class SelectOptionalJsonResultItemSnakeCase:


async def select_optional_json(
client: edgedb.AsyncIOClient,
executor: edgedb.AsyncIOExecutor,
arg0: str | None,
) -> list[tuple[str, SelectOptionalJsonResultItem]]:
return await client.query(
return await executor.query(
"""\
create type TestCase {
create link snake_case -> TestCase;
Expand All @@ -40,19 +40,19 @@ async def select_optional_json(


async def select_scalar(
client: edgedb.AsyncIOClient,
executor: edgedb.AsyncIOExecutor,
) -> int:
return await client.query_single(
return await executor.query_single(
"""\
select 1;\
""",
)


async def test_linked(
client: edgedb.AsyncIOClient,
executor: edgedb.AsyncIOExecutor,
) -> int:
return await client.query_single(
return await executor.query_single(
"""\
select 42\
""",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ class SelectOptionalJsonResultItemSnakeCase(NoPydanticValidation):


async def select_optional_json(
client: edgedb.AsyncIOClient,
executor: edgedb.AsyncIOExecutor,
arg0: typing.Optional[str],
) -> typing.List[typing.Tuple[str, SelectOptionalJsonResultItem]]:
return await client.query(
return await executor.query(
"""\
create type TestCase {
create link snake_case -> TestCase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ class SelectOptionalJsonResultItemSnakeCase:


def select_optional_json(
client: edgedb.Client,
executor: edgedb.Executor,
arg0: typing.Optional[str],
) -> list[tuple[str, SelectOptionalJsonResultItem]]:
return client.query(
return executor.query(
"""\
create type TestCase {
create link snake_case -> TestCase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import edgedb


async def select_scalar(
client: edgedb.AsyncIOClient,
executor: edgedb.AsyncIOExecutor,
) -> int:
return await client.query_single(
return await executor.query_single(
"""\
select 1;\
""",
Expand Down
4 changes: 2 additions & 2 deletions tests/codegen/test-project1/select_scalar_edgeql.py.assert
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import edgedb


def select_scalar(
client: edgedb.Client,
executor: edgedb.Executor,
) -> int:
return client.query_single(
return executor.query_single(
"""\
select 1;\
""",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import edgedb


async def query_one(
client: edgedb.AsyncIOClient,
executor: edgedb.AsyncIOExecutor,
*,
arg_name_with_underscores: int,
) -> int:
return await client.query_single(
return await executor.query_single(
"""\
select <int64>$arg_name_with_underscores\
""",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import edgedb


def query_one(
client: edgedb.Client,
executor: edgedb.Executor,
*,
arg_name_with_underscores: int,
) -> int:
return client.query_single(
return executor.query_single(
"""\
select <int64>$arg_name_with_underscores\
""",
Expand Down
32 changes: 16 additions & 16 deletions tests/codegen/test-project2/generated_async_edgeql.py.assert
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ class SelectObjectResultParamsItem:


async def link_prop(
client: edgedb.AsyncIOClient,
executor: edgedb.AsyncIOExecutor,
) -> list[LinkPropResult]:
return await client.query(
return await executor.query(
"""\
create type Person {
create required property name -> str;
Expand All @@ -162,7 +162,7 @@ async def link_prop(


async def my_query(
client: edgedb.AsyncIOClient,
executor: edgedb.AsyncIOExecutor,
*,
a: uuid.UUID,
b: uuid.UUID | None,
Expand Down Expand Up @@ -215,7 +215,7 @@ async def my_query(
aw: edgedb.Range[datetime.date],
ax: edgedb.Range[datetime.date] | None,
) -> MyQueryResult:
return await client.query_single(
return await executor.query_single(
"""\
create scalar type MyScalar extending int64;
create scalar type MyEnum extending enum<This, That>;
Expand Down Expand Up @@ -331,11 +331,11 @@ async def my_query(


async def query_one(
client: edgedb.AsyncIOClient,
executor: edgedb.AsyncIOExecutor,
*,
arg_name_with_underscores: int,
) -> int:
return await client.query_single(
return await executor.query_single(
"""\
select <int64>$arg_name_with_underscores\
""",
Expand All @@ -344,12 +344,12 @@ async def query_one(


async def select_args(
client: edgedb.AsyncIOClient,
executor: edgedb.AsyncIOExecutor,
*,
arg_str: str,
arg_datetime: datetime.datetime,
) -> SelectArgsResult:
return await client.query_single(
return await executor.query_single(
"""\
select {
Str := <str>$arg_str,
Expand All @@ -362,9 +362,9 @@ async def select_args(


async def select_object(
client: edgedb.AsyncIOClient,
executor: edgedb.AsyncIOExecutor,
) -> SelectObjectResult | None:
return await client.query_single(
return await executor.query_single(
"""\
select schema::Function {
Name := .name,
Expand All @@ -380,9 +380,9 @@ async def select_object(


async def select_objects(
client: edgedb.AsyncIOClient,
executor: edgedb.AsyncIOExecutor,
) -> list[SelectObjectResult]:
return await client.query(
return await executor.query(
"""\
select schema::Function {
Name := .name,
Expand All @@ -397,19 +397,19 @@ async def select_objects(


async def select_scalar(
client: edgedb.AsyncIOClient,
executor: edgedb.AsyncIOExecutor,
) -> int:
return await client.query_single(
return await executor.query_single(
"""\
select 1;\
""",
)


async def select_scalars(
client: edgedb.AsyncIOClient,
executor: edgedb.AsyncIOExecutor,
) -> list[edgedb.ConfigMemory]:
return await client.query(
return await executor.query(
"""\
select <cfg::memory>{1, 2, 3};\
""",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ class LinkPropResultFriendsItem(NoPydanticValidation):


async def link_prop(
client: edgedb.AsyncIOClient,
executor: edgedb.AsyncIOExecutor,
) -> typing.List[LinkPropResult]:
return await client.query(
return await executor.query(
"""\
create type Person {
create required property name -> str;
Expand Down
4 changes: 2 additions & 2 deletions tests/codegen/test-project2/object/link_prop_edgeql.py.assert
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ class LinkPropResultFriendsItem:


def link_prop(
client: edgedb.Client,
executor: edgedb.Executor,
) -> list[LinkPropResult]:
return client.query(
return executor.query(
"""\
create type Person {
create required property name -> str;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ class SelectObjectResultParamsItem(NoPydanticValidation):


async def select_object(
client: edgedb.AsyncIOClient,
executor: edgedb.AsyncIOExecutor,
) -> typing.Optional[SelectObjectResult]:
return await client.query_single(
return await executor.query_single(
"""\
select schema::Function {
Name := .name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ class SelectObjectResultParamsItem:


def select_object(
client: edgedb.Client,
executor: edgedb.Executor,
) -> typing.Optional[SelectObjectResult]:
return client.query_single(
return executor.query_single(
"""\
select schema::Function {
Name := .name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ class SelectObjectsResultParamsItem(NoPydanticValidation):


async def select_objects(
client: edgedb.AsyncIOClient,
executor: edgedb.AsyncIOExecutor,
) -> typing.List[SelectObjectsResult]:
return await client.query(
return await executor.query(
"""\
select schema::Function {
Name := .name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ class SelectObjectsResultParamsItem:


def select_objects(
client: edgedb.Client,
executor: edgedb.Executor,
) -> list[SelectObjectsResult]:
return client.query(
return executor.query(
"""\
select schema::Function {
Name := .name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ class SelectArgsResult(NoPydanticValidation):


async def select_args(
client: edgedb.AsyncIOClient,
executor: edgedb.AsyncIOExecutor,
*,
arg_str: str,
arg_datetime: datetime.datetime,
) -> SelectArgsResult:
return await client.query_single(
return await executor.query_single(
"""\
select {
Str := <str>$arg_str,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ class SelectArgsResult:


def select_args(
client: edgedb.Client,
executor: edgedb.Executor,
*,
arg_str: str,
arg_datetime: datetime.datetime,
) -> SelectArgsResult:
return client.query_single(
return executor.query_single(
"""\
select {
Str := <str>$arg_str,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class MyQueryResult(NoPydanticValidation):


async def my_query(
client: edgedb.AsyncIOClient,
executor: edgedb.AsyncIOExecutor,
*,
a: uuid.UUID,
b: typing.Optional[uuid.UUID],
Expand Down Expand Up @@ -141,7 +141,7 @@ async def my_query(
aw: edgedb.Range[datetime.date],
ax: typing.Optional[edgedb.Range[datetime.date]],
) -> MyQueryResult:
return await client.query_single(
return await executor.query_single(
"""\
create scalar type MyScalar extending int64;
create scalar type MyEnum extending enum<This, That>;
Expand Down
Loading

0 comments on commit 20020f2

Please sign in to comment.