| Crates.io | sql_create_parser |
| lib.rs | sql_create_parser |
| version | 0.1.3 |
| created_at | 2025-11-10 13:55:46.039469+00 |
| updated_at | 2025-11-11 17:45:31.843585+00 |
| description | A simple SQL CREATE parser for SQL CREATE TABLE queries. |
| homepage | |
| repository | https://github.com/prymochenkovictoria/sql_create_parser |
| max_upload_size | |
| id | 1925556 |
| size | 29,040 |
A command-line tool designed to parse and analyze SQL CREATE TABLE queries. Developed in Rust, it uses the pest parser generator to produce a well-structured Abstract Syntax Tree (AST) that represents the input query.
This tool parses CREATE TABLE statements. The parser identifies the table name and a list of column definitions. Each column definition consists of a column name and its corresponding data type.
Supported data types:
INTTEXTBOOLEANDATEVARCHAR(n) (where 'n' is a number)NOT NULL constraintThe parsing process uses a pest grammar to generate a parse tree, which is then traversed to build a strongly-typed AST (CreateTableQuery). This AST can be used for schema validation, code generation, or database migration analysis.
NOT NULL).thiserror.Makefile for easy building, testing, and linting.table_name: The name of the table.columns: A Vec<ColumnDef> of column definitions.name: The name of the column.data_type: A DataType enum.not_null: A bool indicating if the NOT NULL constraint is present.Simple(String): e.g., INT, TEXT.Varchar(u64): e.g., VARCHAR(255).Crate on crates.io
Documentation on docs.rs
Clone the repository:
git clone https://github.com/prymochenkovictoria/sql_create_parser
cd sql_create_parser
We have an example file:
CREATE TABLE users (
user_id INT,
username VARCHAR(100) NOT NULL,
email TEXT,
is_active BOOLEAN,
created_at DATE
);
It will be parsed like this:
Parsed Query:
CreateTableQuery {
table_name: "users",
columns: [
ColumnDef {
name: "user_id",
data_type: Simple(
"INT",
),
not_null: false,
},
ColumnDef {
name: "username",
data_type: Varchar(
100,
),
not_null: true,
},
ColumnDef {
name: "email",
data_type: Simple(
"TEXT",
),
not_null: false,
},
ColumnDef {
name: "is_active",
data_type: Simple(
"BOOLEAN",
),
not_null: false,
},
ColumnDef {
name: "created_at",
data_type: Simple(
"DATE",
),
not_null: false,
},
],
}
WHITESPACE = _{" " | "\t" | "\r" | "\n"}
CREATE = {"CREATE" | "create"}
TABLE = {"TABLE" | "table"}
NOT = {"NOT" | "not"}
NULL = {"NULL" | "null"}
identifier = @{(ASCII_ALPHA | "_") ~ (ASCII_ALPHANUMERIC | "_")*}
number = @{ASCII_DIGIT+}
simple_type = @{"INT" | "int" | "TEXT" | "text" | "BOOLEAN" | "boolean" | "DATE" | "date"}
varchar_type = {("VARCHAR" | "varchar") ~ "(" ~ number ~ ")"}
data_type = {simple_type | varchar_type}
not_null_constraint = {(NOT ~ NULL)}
column_definition = {identifier ~ data_type ~ not_null_constraint?}
column_list = {column_definition ~ ("," ~ column_definition)*}
create_query = {SOI ~ CREATE ~ TABLE ~ identifier ~ "(" ~ column_list ~ ")" ~ (";")? ~ EOI}