geldata / geldata/gel-python

Generating single file for each directory in the queries directory

Open
#411 2 comments 1 reaction 0 assignees View on GitHub
Dominant language
Python
Stars
415
Forks
50
PR merge metrics
No merged PRs in 30d

Description

As the project may grow complex generating a single file for each query is cumbersome to use them. And having all in one file for a large project is also cumbersome.

I want to propose the idea:
If the following is the `queries` folder structure:
```
queries
├── hero
│ ├── delete.edgeql
│ └── insert.edgeql
└── movies
├── delete.edgeql
├── insert.edgeql
├── select.edgeql
└── update.edgeql
```
With an option to generate a python file for each directory under the `queries` directory, the generated file shall look like this:
```
from __future__ import annotations
import dataclasses
import edgedb
import uuid

@dataclasses.dataclass
class HeroDeleteResult:
id: uuid.UUID

@dataclasses.dataclass
class HeroInsertResult:
id: uuid.UUID
name: str
secret_identity: str | None

# Observe hero_ is prefixed to the query delete.edgeql
def hero_delete(
executor: edgedb.Executor,
*,
id: uuid.UUID,
) -> HeroDeleteResult | None:
return executor.query_single(
"""\
with module default
delete (select Hero filter .id=$id)\
""",
id=id,
)

# Observe hero_ is prefixed to the query insert.edgeql
def hero_insert(
executor: edgedb.Executor,
*,
name: str,
si: str,
) -> HeroInsertResult:
return executor.query_single(
"""\
with module default
select (
insert Hero {
name:=$name,
secret_identity:=$si,
}
){
id,
name,
secret_identity
};\
""",
name=name,
si=si,
)
```
Automatically prefix the folder name before each method in the file generated.

I've modified the local installation of `edgedb-python` for my convenience of using it in a project and achieved the desired result, albeit I need to run the command for each folder under the `queries` folder manually.

I've modified the `edgedb\codegen\generator.py` and `edgedb\codegen\cli.py`. Added an option called `--cwd-file` in `cli.py` and then for the option modified the `generator.py` to get the desired result.
I see this issue can be clubbed with https://github.com/edgedb/edgedb-python/issues/410

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.