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

can we get querybuilder object from stringified obj? #787

Open
RasoulZamani opened this issue Jan 21, 2024 · 3 comments
Open

can we get querybuilder object from stringified obj? #787

RasoulZamani opened this issue Jan 21, 2024 · 3 comments

Comments

@RasoulZamani
Copy link

Hi, thank you fort your open source package PyPika!

I want to use pypika objects as a custom filed type in pydantic, when I want to serialize and deserialize my pydantic model, for pypika field I get error.
It seems I need method like QueryBuilder.from_str(query_str) that get string and make querybuider from it.
for example

customers = Table('customers')
q_str =str(Query.from_(customers).select(customers.id))

get us :query_str = "SELECT id FROM customers"
I want to get q object when I have query_str

Is it possible?

@wd60622
Copy link
Contributor

wd60622 commented Jan 21, 2024

It is not part of the library. But I think it would be cool functionality

I've built out some simple parsing using sqlparse but it is not very robust so I haven't released it. Mainly making use of the sqlparse.parse function. It might be good to look into if it isn't on your radar.

How complex are the queries that you are working with?

@RasoulZamani
Copy link
Author

Thank you very much for your response, my queries will be complex. As I explained, my main issue is using pypika objects as a field type in the pydantic. For now I simply stringify them, but in deserialization I have no idea. Do you have suggestion for serialization and deserialization of pypika instanses (except stringify)?

@wd60622
Copy link
Contributor

wd60622 commented Mar 4, 2024

Not totally sure. Maybe something like this. Were you able to come up with any solutions?

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

2 participants