1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//! 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");
//! ```
pub use ;