Crate yehorbolt_sql_parser

Source
Expand description

§SQL parser

This is a simple SQL parser written in Rust using the pest library. The parser supports parsing CREATE TABLE statements with column definitions.

§Example

extern crate yehorbolt_sql_parser;
use yehorbolt_sql_parser::parse_sql;

fn main() {
   let table = "CREATE TABLE financial_report
   {
       id INT,
       currency_name TEXT,
       is_usable BOOL
   }";
   let res = parse_sql(table);
   println!("Parsed: {:#?}", res);
}

In this example, the parse_sql function is used to parse the provided SQL CREATE TABLE statement, and the parsed result is printed using println! (with {:?}).

Structs§

ColumnInfo
Represents information about a database column.
ColumnInfoOption
A variant of ColumnInfo with options for column name and column type.
CreateTable
Represents the structure of a SQL CREATE TABLE statement.
CreateTableOption
A variant of CreateTable with options for table name and column definitions.
SQLParser
SQL parser struct

Enums§

Parsed
Represents parsed SQL statements.
Rule
SqlParseError
Using thiserror::Error for error handling
SqlType
SQL data types.

Functions§

parse_create_table
This function parses a create table statement, extracting the table name, column names, and types to construct a CreateTable struct.
parse_sql
This function takes a SQL query as input and returns a parsed result.
unwrap_column_info
This function, unwrap_column_info, recursively unwraps and extracts column information from a vector of optional ColumnInfoOption instances, returning a vector of ColumnInfo.