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

Parse queries into objects #94

Open
vitusortner opened this issue Mar 11, 2019 · 8 comments
Open

Parse queries into objects #94

vitusortner opened this issue Mar 11, 2019 · 8 comments
Labels
feature Request and implementation of a feature (release drafter)
Milestone

Comments

@vitusortner
Copy link
Collaborator

Create SqlParser that returns a query object, which holds information about the query (SELECT, DELETE, etc.).
This is only required for queries annotated with @Query.

This is the first step in making returning the result of inserting, updating or deleting records possible.

@vitusortner vitusortner added the refactoring Improvement without changing functionality label Mar 11, 2019
@vitusortner vitusortner changed the title Parse a query into an object Parse queries into objects Mar 11, 2019
@vitusortner vitusortner self-assigned this Mar 11, 2019
@ghost
Copy link

ghost commented Mar 23, 2019

The Query needs to return simple data. (int, String, double, bool)

@vitusortner
Copy link
Collaborator Author

Parsing SQL queries seems more tricky than expected. Unluckily I didn't find a package that could help with that.

@cw-dev
Copy link

cw-dev commented Mar 28, 2019

You might be interested in https://github.com/AlecStrong/sqlite-psi

It’s the backend for https://github.com/square/sqldelight

@vitusortner
Copy link
Collaborator Author

@cw-dev thanks, I'll take a look at it!

@simolus3
Copy link

I've written https://pub.dev/packages/sqlparser, which is a pure-Dart sql parser and static analyzer. Originally, it was written for another project, but it might be helpful to this library as well. It can turn any sql query into an AST (so you know whether it is an insert/update/select/etc.), so you could just do

final engine = SqlEngine();
print(engine.parse('SELECT * FROM tbl').rootNode is SelectStatement) // true

If you know the table structure at build-time, you can also register available tables to the sql engine by adding them to SqlEngine.knownTables. Then, SqlEngine.analyze can be used to figure out what's returned by queries and it can resolve the type of variables in the query.

@vitusortner
Copy link
Collaborator Author

This looks awesome and seems to be the right fit for the library's needs. Thanks @simolus3!

@vladimirfx
Copy link

As now is any way to do partial updates? With UPDATE queries or like Room's 2.2 partial updates.

@dkaera
Copy link
Collaborator

dkaera commented Feb 11, 2023

Many thanks to @simolus3 for the SQL parser, it saved a lot of time to solve this issue.
PR #733

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Request and implementation of a feature (release drafter)
Development

No branches or pull requests

5 participants