-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also drop pydantic target: It is not really a code generation target. Instead, new options are added: --skip-pydantic-validation and --no-skip-pydantic-validation. Also added help text in codegen CLI. Co-authored-by: Fantix King <fantix.king@gmail.com>
- Loading branch information
1 parent
361221d
commit 23dd42e
Showing
16 changed files
with
145 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
.. _edgedb-python-codegen: | ||
|
||
=============== | ||
Code Generation | ||
=============== | ||
|
||
.. py:currentmodule:: edgedb | ||
The ``edgedb-python`` package exposes a command-line tool to generate | ||
typesafe functions from ``*.edgeql`` files, using :py:mod:`dataclasses` for | ||
objects primarily. | ||
|
||
.. code-block:: bash | ||
$ edgedb-py | ||
Or alternatively: | ||
|
||
.. code-block:: bash | ||
$ python -m edgedb.codegen | ||
Consider a simple query that lives in a file called ``get_number.edgeql``: | ||
|
||
.. code-block:: edgeql | ||
select <int64>$arg; | ||
Running the code generator will generate a new file called | ||
``get_number_async_edgeql.py`` containing the following code (roughly): | ||
|
||
.. code-block:: python | ||
from __future__ import annotations | ||
import edgedb | ||
async def get_number( | ||
client: edgedb.AsyncIOClient, | ||
*, | ||
arg: int, | ||
) -> int: | ||
return await client.query_single( | ||
"""\ | ||
select <int64>$arg\ | ||
""", | ||
arg=arg, | ||
) | ||
Target | ||
~~~~~~ | ||
|
||
By default, the generated code uses an ``async`` API. The generator supports | ||
additional targets via the ``--target`` flag. | ||
|
||
.. code-block:: bash | ||
$ edgedb-py --target async # generate async function (default) | ||
$ edgedb-py --target blocking # generate blocking code | ||
The names of the generated files will differ accordingly: | ||
``{query_filename}_{target}_edgeql.py``. | ||
|
||
Single-file mode | ||
~~~~~~~~~~~~~~~~ | ||
|
||
It may be preferable to generate a single file containing all the generated | ||
functions. This can be done by passing the ``--file`` flag. | ||
|
||
.. code-block:: bash | ||
$ edgedb-py --file | ||
This generates a single file called ``generated_{target}_edgeql.py`` in the | ||
root of your project. | ||
|
||
Connection | ||
~~~~~~~~~~ | ||
|
||
The ``edgedb-py`` command supports the same set of :ref:`connection options | ||
<ref_cli_edgedb_connopts>` as the ``edgedb`` CLI. | ||
|
||
.. code-block:: | ||
-I, --instance <instance> | ||
--dsn <dsn> | ||
--credentials-file <path/to/credentials.json> | ||
-H, --host <host> | ||
-P, --port <port> | ||
-d, --database <database> | ||
-u, --user <user> | ||
--password | ||
--password-from-stdin | ||
--tls-ca-file <path/to/certificate> | ||
--tls-security <insecure | no_host_verification | strict | default> | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/codegen/test-project2/argnames/query_one_edgeql.py.assert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/codegen/test-project2/object/select_object_edgeql.py.assert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/codegen/test-project2/object/select_objects_edgeql.py.assert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/codegen/test-project2/parpkg/select_args_edgeql.py.assert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/codegen/test-project2/parpkg/subpkg/my_query_edgeql.py.assert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/codegen/test-project2/scalar/select_scalar_edgeql.py.assert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/codegen/test-project2/scalar/select_scalars_edgeql.py.assert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters