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§
- Column
Info - Represents information about a database column.
- Column
Info Option - A variant of
ColumnInfo
with options for column name and column type. - Create
Table - Represents the structure of a SQL
CREATE TABLE
statement. - Create
Table Option - A variant of
CreateTable
with options for table name and column definitions. - SQLParser
- SQL parser struct
Enums§
- Parsed
- Represents parsed SQL statements.
- Rule
- SqlParse
Error - 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.