Expand description
Crate for typing SQL statements.
use sql_type::{schema::parse_schemas, type_statement, TypeOptions,
    SQLDialect, SQLArguments, StatementType, Issues};
let schemas = "
    CREATE TABLE `events` (
      `id` bigint(20) NOT NULL,
      `user` int(11) NOT NULL,
      `message` text NOT NULL
    );";
let mut issues = Issues::new(schemas);
// Compute terse representation of the schemas
let schemas = parse_schemas(schemas,
    &mut issues,
    &TypeOptions::new().dialect(SQLDialect::MariaDB));
assert!(issues.is_ok());
let sql = "SELECT `id`, `user`, `message` FROM `events` WHERE `id` = ?";
let mut issues = Issues::new(sql);
let stmt = type_statement(&schemas, sql, &mut issues,
    &TypeOptions::new().dialect(SQLDialect::MariaDB).arguments(SQLArguments::QuestionMark));
assert!(issues.is_ok());
let stmt = match stmt {
    StatementType::Select{columns, arguments} => {
        assert_eq!(columns.len(), 3);
        assert_eq!(arguments.len(), 1);
    }
    _ => panic!("Expected select statement")
};Modules§
- schema
- Facility for parsing SQL schemas into a terse format that can be used for typing statements.
Structs§
- Fragment
- FullType 
- Represent a type with not_null information
- Issue
- An issue encountered during parsing, or later stages
- Issues
- SelectType Column 
- A column in select
- TypeOptions 
- Options used when typing sql or parsing a schema
Enums§
- ArgumentKey 
- Key of argument
- AutoIncrement Id 
- Does the insert yield an auto increment id
- BaseType 
- Canonical base type of a type
- Level
- Level of an issues
- SQLArguments
- What kinds or arguments
- SQLDialect
- What sql diarect to parse as
- StatementType 
- Type information of typed statement
- Type
- Represent the type of a value
Functions§
- type_statement 
- Type an sql statement with respect to a given schema