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

Proposal: Implement HQL Query Parsing via Parsing Expression Grammar (PEG) #92

Open
vnayar opened this issue May 17, 2024 · 1 comment

Comments

@vnayar
Copy link
Contributor

vnayar commented May 17, 2024

Motivation: I was looking over the code for processing HQL queries in https://github.com/buggins/hibernated/blob/master/source/hibernated/query.d because I was looking to see how difficult it would be to add support for the DELETE statement, which is useful because it can have a major performance boost over deleting a single object at a time when there is a large number of objects. I realized that the code in query.d is very much built around SELECT statements, and changing it to support other kinds of statements would be difficult, error-prone, and hard to maintain.

Idea: Replace the existing HQL query parsing with one backed by a Parsing Expression Grammar.

Advantages include:

  1. Easy to expand and adopt to new types of statements with little effort.
  2. Cleanly split parsing and interpretation for easier code testing and maintenance.
  3. Automatically gain error detection pointing out the character position of any mistake.

Most of the initial work would be to make a clean separation between the parsing logic and the SQL query generation logic for the current "SELECT" statements. Once that work is done, then it will be much easier to expand the parsing to support new statement types like "UPDATE" or "DELETE", and then add a modular SQL query generator based on the parsing results.

I've used a D library in other projects to generate a PEG parser: https://code.dlang.org/packages/pegged

If I were to make a larger overhaul like this and submit a PR, would it be considered?

@SingingBush
Copy link
Collaborator

I think it would be good and to do. potentially separated either as a sub package or a feature so that end users can easily choose to include it or not. I like the separation of using a parent dub file with multiple sub projects but this is just my personal preference.
I've not been using D recently so it would be good to get some input from other users or perhaps @buggins.

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