Expand description
Parse MySQL and MariaDB DDL into a compact table model and JSON Schema.
Feed SQL Data Definition statements into a Parser, then read one of
three outputs:
- the parse tree, via
Parser::parse - the compact table model, via
Parser::parse_compact - JSON Schema draft-07 documents, via
Parser::parse_json_schema
Each of these drains the buffered statements. To reformat a tree you already
hold, use the free functions compact_from_tree and
json_schema_from_tables.
Only DDL is supported. SET parses but is ignored. Database statements
(USE, CREATE DATABASE, ALTER DATABASE, DROP DATABASE) parse but do
not produce tables.
The parser is stream friendly. Input can arrive in chunks. Statements split at unquoted, unescaped semicolons.
§Example
use sql_ddl_to_json_schema::Parser;
let ddl = "CREATE TABLE users (id INT NOT NULL AUTO_INCREMENT, \
nickname VARCHAR(255) NOT NULL, PRIMARY KEY (id));";
let mut parser = Parser::new("mysql").unwrap();
parser.feed(ddl);
let schemas = parser.parse_json_schema(Default::default()).unwrap();
assert_eq!(schemas[0]["$id"], "users");Structs§
- Json
Schema Options - Options for JSON Schema output.
- Parser
- Parser for MySQL and MariaDB DDL.
Enums§
- Error
- Error returned by parser operations.
Functions§
- compact_
from_ tree - Build the compact table model from a
MAINparse tree. - json_
schema_ from_ tables - Build JSON Schema draft-07 documents from compact tables, one per table.