pub fn table_ddl(declaration: &[String]) -> Result<String, DeclarationError>Expand description
A TABLE.DECLARE argv as the SQL sql compile turns back into the
same declaration: CREATE TABLE, then one CREATE [UNIQUE] INDEX per
index and order path, in declaration order. What SQL has no words for
— a key prefix other than <table>:, WINDOW, AUTODECLARE, a
one-column order path — is written as a -- comment naming the
clause, so a reader sees what the SQL form does not carry.
let decl: Vec<String> = "TABLE.DECLARE users PREFIX users: PK id COLUMN id i64 \
COLUMN email str INDEX email unique"
.split_whitespace()
.map(String::from)
.collect();
let ddl = kevy_sql::table_ddl(&decl).unwrap();
assert_eq!(
ddl,
"CREATE TABLE users (\n id bigint PRIMARY KEY,\n email text\n);\n\
CREATE UNIQUE INDEX ON users (email);\n"
);
assert_eq!(kevy_sql::compile(&ddl).unwrap().commands, vec![decl]);