Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create query builder like the Typescript client library has #292

Open
jerber opened this issue Feb 10, 2022 · 12 comments
Open

Create query builder like the Typescript client library has #292

jerber opened this issue Feb 10, 2022 · 12 comments

Comments

@jerber
Copy link

jerber commented Feb 10, 2022

The TS client library has a very cool auto-generated query builder. With python typing we could build the same type of functionality. Here is the TS docs: https://www.edgedb.com/docs/clients/01_js/generation

@nandorojo
Copy link

Would love to have this for Python.

@fantix
Copy link
Member

fantix commented Feb 11, 2022

Yes, this is absolutely part of the plan. Let's keep this issue open until it's implemented.

@Pentusha
Copy link

Pentusha commented May 26, 2022

You may be interested in a project that I made over a couple of weekends.
The current features set can be best seen in documentation.
I tried to make it look like SQLAlchemy Core and not like TypeScript builder. I think this might be a good starting point.
It allows you to build complex expressions:

from edgeql_qb import EdgeDBModel
from edgeql_qb.operators import Alias
from edgeql_qb.types import int16

# please note that you may specify module for model,
# which would be used in every generated `with` statements.
Person = EdgeDBModel('Person', module='imdb')
Movie = EdgeDBModel('Movie', module='imdb')

actors = Person.insert.values(first_name='Harrison', last_name='Ford').label('actors')
director = Person.select().where(Person.c.id == director_id).limit1.label('director')
title = Alias('title').assign('Blade Runner 2049')
year = Alias('year').assign(int16(2017))
query = Movie.insert.with_(actors, director, title, year).values(
    title=title,
    year=year,
    director=director,
    actors=actors,
).build()

print(query.query)
# with
#     module imdb,
#     actors := (with imdb insert Person { first_name := <str>$insert_0, last_name := <str>$insert_1 }),
#     director := (with imdb select Person filter .id = $filter_2 limit 1),
#     title := <str>$with_3,
#     year := <int16>$with_4
# insert Movie {
#     title := title,
#     year := year,
#     director := director,
#     actors := actors
# }

print(query.context)
# {'insert_0': 'Harrison', 'insert_1': 'Ford', 'filter_2': director_id, 'with_3': 'Blade Runner 2049', 'with_4': 2017}

Any feedback is appreciated

@rmzr7
Copy link

rmzr7 commented Jul 28, 2022

@fantix do you have an estimated timeline for this?

@fantix
Copy link
Member

fantix commented Aug 3, 2022

@fantix do you have an estimated timeline for this?

This has been discussed with the team again this week. It's likely that we'll soon come up with something that works in a similar way across Go and Python, so let's sit tight 😼

@hwmrocker
Copy link

This feature was just released, or are you talking about something different?

@chrisemke
Copy link

is there any news about this? should I use pentusha's project until it officially launches?

@fantix
Copy link
Member

fantix commented Jun 23, 2023

The codegen will likely be the main way to use for at least the Python binding, this is also demonstrated in the 3.0 launch event.

@raddevon
Copy link
Contributor

Do you mind to create a separate feature request for this, @triumph1? I don't want it to get lost in this query builder request. It's slightly different and might be more feasible. (Don't know that it is but maybe.)

@triumph1
Copy link

Sure! I'll make an issue and delete above comment. Thank you! 🙇‍♂️

@triumph1
Copy link

Do you mind to create a separate feature request for this, @triumph1? I don't want it to get lost in this query builder request. It's slightly different and might be more feasible. (Don't know that it is but maybe.)

#463 done! 👍

@darinkishore
Copy link

hi! is this still planned?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants