Crate vibesql

Crate vibesql 

Source
Expand description

§VibeSQL

A SQL parser and semantic analyzer library with standard SQL type system.

This library provides a complete SQL parsing and analysis pipeline that can be used as a middleware layer between transport and storage layers in database systems.

§Features

  • Full SQL lexer/tokenizer
  • Comprehensive AST representation
  • Expression, query, and statement parsing
  • Standard SQL type system (BIGINT, VARCHAR, DOUBLE PRECISION, etc.)
  • Semantic analysis with type checking
  • Extensible catalog with custom types, functions, and tables
  • Zero dependencies (standard library only)

§Quick Start

use vibesql::{Parser, Analyzer};

let sql = "SELECT id, name FROM users WHERE age > 21";
let mut parser = Parser::new(sql);
let ast = parser.parse().expect("Failed to parse SQL");

§Extensibility

Use CatalogBuilder to create catalogs with custom functions and types:

use vibesql::catalog::{CatalogBuilder, TypeRegistry};
use vibesql::types::SqlType;

let catalog = CatalogBuilder::new()
    .with_builtins()
    .add_scalar_function("MY_HASH", SqlType::Int64)
    .add_table("users", |t| {
        t.primary_key("id", SqlType::Int64)
         .column("name", SqlType::Varchar)
         .column("email", SqlType::Varchar)
    })
    .build();

§Type System

VibeSQL uses standard SQL type names:

TypeDisplay Name
SqlType::BoolBOOLEAN
SqlType::Int32INTEGER
SqlType::Int64BIGINT
SqlType::Float32REAL
SqlType::Float64DOUBLE PRECISION
SqlType::VarcharVARCHAR
SqlType::VarbinaryVARBINARY

Re-exports§

pub use analyzer::AnalyzedQuery;
pub use analyzer::Analyzer;
pub use analyzer::AnalyzerError;
pub use analyzer::OutputColumn;
pub use catalog::Catalog;
pub use catalog::CatalogBuilder;
pub use catalog::ColumnSchema;
pub use catalog::FunctionSignature;
pub use catalog::MemoryCatalog;
pub use catalog::TableBuilder;
pub use catalog::TableSchema;
pub use catalog::TableSchemaBuilder;
pub use catalog::TypeRegistry;
pub use error::Error;
pub use error::Result;
pub use lexer::Lexer;
pub use lexer::Token;
pub use lexer::TokenKind;
pub use parser::Parser;
pub use types::SqlType;
pub use types::Value;
pub use ast::*;

Modules§

analyzer
Semantic analyzer for SQL statements.
ast
Abstract Syntax Tree (AST) definitions for SQL statements.
catalog
Catalog abstraction for schema metadata.
error
Error handling for the VibeSQL parser and analyzer.
lexer
SQL Lexer/Tokenizer.
parser
SQL Parser.
types
Type system for SQL values and expressions.