*.edgeql
code generation
#4244
Replies: 6 comments 4 replies
-
This doesn't account for changes in the edgedb client API. If a user does a major version upgrade then the files won't be updated and may not compile/run. |
Beta Was this translation helpful? Give feedback.
-
Potentially the hash should also include the latest applied migration hash. |
Beta Was this translation helpful? Give feedback.
-
I have a question about the obligation to use an executable script to generate code. Does it really need to be a command that has to be run manually? For example in the case of Elixir I created edgedb_ecto which does similar things to the above (except automatic options recognizing) and generates modules and functions when the Elixir application is being compiled. Because of this, I don't need, for example, the I also have 2 suggestions about generators usage:
|
Beta Was this translation helpful? Give feedback.
-
I think we might want to add
Either that hash should include or another field should contain version of the tool. So you don't have to run clean/force schenanigans after an update. |
Beta Was this translation helpful? Give feedback.
-
Is there a reason of why you export What happens with folders in |
Beta Was this translation helpful? Give feedback.
-
The problem with this is not just that one have to implement support for all of the arguments, but also that we can add more later and everyone should follow. Do we have a strong use case for that? I think environment configuration is good enough and simplifies implementation and maintenance. |
Beta Was this translation helpful? Give feedback.
-
This is a proposal for a semi-standardized workflow for writing queries inside
*.edgeql
files and generating associated source files that provide a typesafe and idiomatic way to execute those queries.*.edgeql
filesQueries are written as plain EdgeQL inside
*.edgeql
filesA generation command
An executable package/command should be provided to generate an executable function for each
*.edgeql
file.This command should
.edgeql
files.Different language ecosystems provide different mechanisms for executing scripts of this nature, e.g.
npx
in the Node.js ecosystem,pipx
in Python, etc.myQuery.edgeql
should produce a file in the same directory calledmyQuery.edgeql.<ext>
myQuery
. In statically typed languages, this function should have an appropriate return type.Client
instance.File names
The generated files should be easy to exclude with a single line in a
.gitignore
. This may involve a suffix or another naming convention.my_query.edgeql
->my_query_edgeql.py
my_query.edgeql
->my_query.edgeql.ts
Detecting project root
The existence of an
edgedb.toml
is used to detecting the project root. Starting from the directory where the command is executed, the script should search up the file system for a directory containingedgedb.toml
. In none is found, an error should be thrown.Ignore migration files
Do not generate files associated with migration files. We'll need to respect the location of
dbschema
specified inedgedb.toml
if/when it becomes possible to customize that (it isn't currently).Connection args
The generation script should rely on the client library to resolve connection parameters, though it should also support the full set of command-line connection parameteters as an override:
-h/--help
--dsn
--credentials-file
-I/--instance
-H/--host
-P/--port
-d/--database
-u/--user
--password
--password-from-stdin
--tls-ca-file
--tls-security
--file
There should be a
--file
mode that will generate all "query functions" into a single file instead of generating per-query files. In the case of naming conflicts, an error should be thrown.--watch
There should be a
--watch
mode that listens for changes to*.edgeql
files. On the first run, each query will detect the project root, recursive find all*.edgeql
files in that directory, and generate files appropriately. It should then start a file watcher that listens for changes to these files and the creation of any new*.edgeql
files.To avoid unnecessary regenerations, the generated files should contain a hash of the query as a comment on the first line.
This hash can be read and used to determine if a given query has changed and needs to be re-generated.
--target
Where necessary, a
--target
flag should be provided to provide support for different language variants. For instance, JavaScript vs TypeScript.Worked example
Query file
getUser.edgeql
The user executes an
npx
command to generate appropriate filesA
getUser.edgeql.ts
file is generated with the following contentsThe generated query is consumed like so
Comparison to a full query builder
Pros
Cons
*.edgeql
files until LSP lands*.edgeql
files (this is also kinda nice in some sense)Beta Was this translation helpful? Give feedback.
All reactions