#[non_exhaustive]pub struct Plan {
pub declares: Vec<Vec<String>>,
pub queries: Vec<PlanEntry>,
pub notes: Vec<String>,
pub dropped: Vec<(String, String)>,
}Expand description
A migration plan: what to declare, and what becomes of each query.
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';",
)?;
assert_eq!(p.declares.len(), 1);
assert_eq!(p.queries.len(), 3);
assert_eq!(p.unserved(), 1);Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.declares: Vec<Vec<String>>TABLE.DECLARE argv per table, declaration order.
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';",
)?;
assert_eq!(p.declares[0][..2], ["TABLE.DECLARE", "orders"]);queries: Vec<PlanEntry>Every CREATE VIEW, served or not, declaration order.
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';",
)?;
assert_eq!(p.queries.len(), 3);notes: Vec<String>Honest-mapping notes, as crate::Compilation::notes.
let p = kevy_sql::plan("CREATE TABLE ev (id bigint PRIMARY KEY, at timestamp);")?;
assert!(p.notes.iter().any(|n| n.contains("ev.at: timestamp → str")));dropped: Vec<(String, String)>Tables (and stray indexes) that could NOT be declared:
(name, named reason). The charter’s migration bar reads
“every type either moved or named” — this is the named half.
let p = kevy_sql::plan(
"CREATE TABLE users (id bigint PRIMARY KEY, email text);
CREATE TABLE billing (id bigint PRIMARY KEY, amount money);",
)?;
assert_eq!(p.declares.len(), 1); // users still declares
assert_eq!(p.dropped[0].0, "billing");
assert!(p.dropped[0].1.contains("money"));Implementations§
Source§impl Plan
impl Plan
Sourcepub fn unserved(&self) -> usize
pub fn unserved(&self) -> usize
How many queries cannot be served as declared.
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';",
)?;
assert_eq!(p.unserved(), 1);Trait Implementations§
impl Eq for Plan
impl StructuralPartialEq for Plan
Auto Trait Implementations§
impl Freeze for Plan
impl RefUnwindSafe for Plan
impl Send for Plan
impl Sync for Plan
impl Unpin for Plan
impl UnsafeUnpin for Plan
impl UnwindSafe for Plan
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more