pub fn plan(sql: &str) -> Result<Plan, SqlError>Expand description
Plan a whole SQL file: DDL becomes declarations, each CREATE VIEW
becomes an entry saying whether it can be served and by what.
Errors only on the schema itself — a file whose DDL does not parse has no plan. A view that cannot be served comes back as an entry.
let p = kevy_sql::plan(
"CREATE TABLE orders (id bigint PRIMARY KEY, user_id bigint, status text);
CREATE INDEX ON orders (user_id);
CREATE VIEW mine AS SELECT * FROM orders WHERE user_id = 7;
CREATE VIEW by_user AS SELECT * FROM orders WHERE user_id = $1;
CREATE VIEW paid AS SELECT * FROM orders WHERE status = 'paid';",
)?;
// one refused view does not stop the other two from being planned
assert_eq!(p.queries.len(), 3);
assert_eq!(p.unserved(), 1);
// a schema that does not parse has no plan at all
assert!(kevy_sql::plan("CREATE TABLE (").is_err());