Attributes
Every attribute #[derive(View)] accepts. A test fails when the derive accepts one that is not listed here.
| Attribute | On | Syntax | Meaning | Rules |
|---|---|---|---|---|
table | struct, variant | #[view(table = "t")] | The table of a view, or of a variant | MPA-VIEW-1, MPA-SUM-3 |
key | struct, variant | #[view(key = "c")] | The key column, id by default | MPA-VIEW-2, MPA-SUM-3 |
embedded | struct | #[view(embedded)] | A struct stored in columns of the containing view, generic over types or not | MPA-VIEW-3, MPA-VIEW-4 |
databases | struct, enum | #[view(databases = "postgres, mysql")] | Limit the databases a view is decoded and encoded on | MPA-DB-2 |
tag | enum | #[view(tag = "c")] | The column naming the variant | MPA-SUM-1 |
strategy | enum | #[view(strategy = "tag" | "table_per_variant")] | Where the variants’ data is stored | MPA-SUM-2, MPA-SUM-3 |
lenient | enum | #[view(lenient)] | Allow non-NULL columns of other variants | MPA-SUM-4 |
tag_value | variant | #[view(tag_value = "v")] | The tag of a variant, its name by default | MPA-SUM-1 |
column | field | #[view(column = "c")] | The column of a field, its name by default | MPA-VIEW-5 |
json | field | #[view(json)] | A column decoded and written as JSON | MPA-VIEW-6 |
version | field | #[view(version)] | An integer version column for optimistic locking | MPA-WRITE-9, MPA-WRITE-10 |
generated | field | #[view(generated)] | A key the database generates when the row is inserted | MPA-WRITE-13 |
computed | field | #[view(computed)] | A value SQL computes, not a column of the table | MPA-VIEW-13 |
embed | field | #[view(embed)] | An embedded struct or enum | MPA-VIEW-7 |
prefix | field | #[view(embed(prefix = "p_"))] | The column prefix of an embedded value | MPA-VIEW-7 |
to_one | field | #[view(to_one(fk = "c"))] | A reference to another view | MPA-VIEW-8 |
child | field | #[view(child(fk = "c"))] | A to-many collection | MPA-VIEW-9, MPA-VIEW-10 |
fk | to_one, child | fk = "c" | The foreign key column | MPA-VIEW-8, MPA-VIEW-9 |
order_by | child | order_by = "a, b desc" | The order of the elements | MPA-VIEW-9 |
through | child | through = "link" | The link table of a many-to-many collection | MPA-VIEW-9 |
target | child | target = "c" | The link table column referencing the element | MPA-VIEW-9 |
index | child | index = "c" | The column placing the elements of a Vec | MPA-VIEW-9 |
key | child | key = "c" | The column keying the elements of a map | MPA-VIEW-9 |
depth | child, to_one | depth = n | The most levels of a recursive collection or reference | MPA-VIEW-8, MPA-VIEW-9, MPA-PLAN-4 |
recursive | child, to_one | recursive = "cte" | Load all levels with one WITH RECURSIVE query | MPA-VIEW-8, MPA-VIEW-9, MPA-PLAN-4 |
Functions
Section titled “Functions”| API | What it does | Rules |
|---|---|---|
mabat::load::<T>() | Start a load of the generated queries | MPA-LOAD-1 |
Load::by_key / by_keys | Load by keys | MPA-LOAD-3 |
Load::filter | Filter the root rows | MPA-LOAD-4 |
Load::order_by / order_by_desc / limit / offset | Order and page the root rows | MPA-LOAD-6 |
Load::nested | Arguments of a nested collection | MPA-LOAD-9 |
Load::select | Load a selection of fields, as JSON | MPA-JSON-3 |
Load::sql | Run SQL as the root query, for reports | MPA-LOAD-19 |
Load::bind | Bind a named parameter of the root query’s SQL | MPA-LOAD-19 |
Load::all / one / optional / count | Run a load | MPA-LOAD-2 |
Load::graph | Load a graph view | MPA-LOAD-14 |
Load::json | Load as JSON | MPA-JSON-1 |
Load::graph_json | Load a graph as JSON, each entity once with $id and $ref | MPA-JSON-7 |
Load::stream | Load a batch at a time, as a stream | MPA-LOAD-15, MPA-LOAD-16, MPA-LOAD-17, MPA-LOAD-18 |
Load::json_stream | Load as JSON a batch at a time, as a stream | MPA-LOAD-17 |
Load::batch_size | The number of values a stream loads at a time | MPA-LOAD-15 |
mabat::save | Save an aggregate | MPA-WRITE-3 |
mabat::save_changes | Save what changed | MPA-WRITE-8 |
mabat::save_graph | Save every entity of a graph | MPA-WRITE-14, MPA-WRITE-15 |
mabat::save_all | Save many values, batched by table and level | MPA-WRITE-19 |
mabat::save_graph_changes | Save the changed entities of a graph | MPA-WRITE-20 |
Graph::is_changed | Whether save_graph_changes writes an entity | MPA-WRITE-20 |
mabat::schema::snapshot | A snapshot of the database’s schema | MPA-SCH-1 |
Manifest::check_snapshot | Check the views against a snapshot of the schema, without a database | MPA-SCH-4, MPA-SCH-5, MPA-SCH-6 |
mabat_check::build | Check the views against a snapshot from a build script | MPA-SCH-7 |
Graph::insert | Add an entity to a graph, for saving | MPA-LOAD-14, MPA-WRITE-14 |
mabat::delete | Delete an aggregate | MPA-WRITE-7 |
mabat::plan | The plan of a view | MPA-PLAN-5 |
mabat::scaffold | An override file with the generated SQL | MPA-OVR-8 |
Mabat::builder / Builder::register / overrides_dir / overrides / overrides_sql / on_invalid | Configure a registry | MPA-OVR-1, MPA-OVR-5 |
Builder::check / build | Check and build a registry | MPA-OVR-5 |
Builder::manifest | The manifest of the views | MPA-OVR-8 |
Mabat::load / explain / report / reload / shadow_stats | Use a registry | MPA-OVR-1, MPA-PLAN-5, MPA-OVR-6, MPA-OVR-7 |
Pooled::snapshot / read_committed | Concurrent loads on a pool | MPA-LOAD-11 |
Selection::new / field / nested / parse | Build a selection | MPA-JSON-3 |
Graph::root / roots / get / get_mut / all / count | Read a graph | MPA-LOAD-14 |
mabat_graphql::schema / SchemaBuilder::list / by_key / registry / connections / finish / into_dynamic | A GraphQL schema of views | MPA-GQL-1 |