#sql-query #sql-parser #query-parser #condition #pest-parser #table #columns

bin+lib sql_parser_project

This is a simple project to parse SQL queries using pest crate. Currently parser supports simple select queries whith where conditions.

1 unstable release

0.1.0 Nov 14, 2024

#2 in #columns

Download history 103/week @ 2024-11-11 13/week @ 2024-11-18

116 downloads per month

MIT license

155KB
162 lines

SQL Parser Project

This is a simple project to parse SQL queries using pest crate.
Currently parser supports simple select queries whith where conditions.

Project Description

The SQL Query Parser extracts from a basic SQL query:

  • Table Name: The table from which data is selected.
  • Columns: List of columns specified in the query.

Technical overview

Created parser processes PSQL-like select statements with multiple columns selections and where statements. Column and table names have to be encased in double quotes, while string values have to be encased in single quotes. Reserved keywords have to

There are main grammar rules used:

  • query: Matches the full SQL SELECT statement.
  • columns: Parses a comma-separated list of columns.
  • from_clause: Parses the FROM TABLE part of statement.
  • where_clause: Parses the WHERE CONDITION part of statement.
  • identifier: Parses the name of a column or table.

Example Usage

cargo run test-query.txt

Example query

SELECT "column1" FROM "table" WHERE "column1" = 5 AND "column2" = 'value';

Example output

Selected table: "table"
Selected columns: "column1"
Conditions:
  Column: "column1", Operator: =, Value: 5
   AND 
  Column: "column2", Operator: =, Value: 'value'

Dependencies

~2.2–3MB
~59K SLoC