hibernated icon indicating copy to clipboard operation
hibernated copied to clipboard

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

Open vnayar opened this issue 9 months ago • 1 comments

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?

vnayar avatar May 17 '24 10:05 vnayar