// @generated by `zero-rust codegen` from packages/zero-swift-cli/test/sweep-schema.ts. Do not edit. // // Declare it as `#[rustfmt::skip] mod schema;`: rustfmt would reformat it, // and `zero-rust codegen --check` compares it as generated. #![allow(dead_code)] use ::zero_client::typed as z; /// A row of `t`. #[derive(Clone, Debug, PartialEq)] pub struct T { pub id: String, pub o: Fields, } impl T { pub const ID: z::Column = z::Column::new("id"); pub const O: z::Column = z::Column::new("o"); } impl z::QueryElement for T { fn from_entry(entry: &z::ViewEntry) -> Result { Ok(T { id: z::column(entry, "id", 0)?, o: z::column(entry, "o", 1)?, }) } } impl z::ZeroRow for T { const TABLE: &'static str = "t"; type Update = TUpdate; type Key = TKey; fn column_values(&self) -> z::Object { let mut row = z::Object::with_capacity(2); row.insert("id", z::ZeroValue::to_zero_value(&self.id)); row.insert("o", z::ZeroValue::to_zero_value(&self.o)); row } } impl z::OptionalQueryElement for T { fn optional_from_view(view: &z::ViewValue) -> Result, z::ZeroValueError> { z::optional_row(view) } } /// What `mutate::t(tx).update` takes: the primary key, and the other columns to set. A column that is `None`, or `ColumnUpdate::Unchanged`, keeps its value. #[derive(Clone, Debug, PartialEq)] pub struct TUpdate { pub id: String, pub o: Option, } impl TUpdate { /// The primary key, with every other column left as it is. pub fn new(id: String) -> Self { TUpdate { id, o: None, } } } impl z::ColumnValues for TUpdate { fn column_values(&self) -> z::Object { let mut row = z::Object::with_capacity(2); row.insert("id", z::ZeroValue::to_zero_value(&self.id)); if let Some(v) = &self.o { row.insert("o", z::ZeroValue::to_zero_value(v)); } row } } /// What `mutate::t(tx).delete` takes: the primary key. #[derive(Clone, Debug, PartialEq)] pub struct TKey { pub id: String, } impl z::ColumnValues for TKey { fn column_values(&self) -> z::Object { let mut row = z::Object::with_capacity(1); row.insert("id", z::ZeroValue::to_zero_value(&self.id)); row } } /// The `Fields` objects of a `json` column. #[derive(Clone, Debug, PartialEq)] pub struct Fields { pub zero_value: f64, pub a_b_: f64, pub a_b: f64, } impl z::ZeroValue for Fields { fn from_zero_value(value: &z::Value) -> Result { let object = z::object(value, "Fields")?; Ok(Fields { zero_value: z::field(object, "zeroValue")?, a_b_: z::field(object, "a-b")?, a_b: z::field(object, "a_b")?, }) } fn to_zero_value(&self) -> z::Value { let mut object = z::Object::with_capacity(3); object.insert("zeroValue", z::ZeroValue::to_zero_value(&self.zero_value)); object.insert("a-b", z::ZeroValue::to_zero_value(&self.a_b_)); object.insert("a_b", z::ZeroValue::to_zero_value(&self.a_b)); z::Value::Object(object) } } /// The schema the queries of `zql` are over. pub fn schema() -> ::std::sync::Arc { static SCHEMA: ::std::sync::OnceLock<::std::sync::Arc> = ::std::sync::OnceLock::new(); SCHEMA.get_or_init(|| z::schema_from_json(r#"{ "tables": { "t": { "name": "t", "columns": { "id": { "type": "string" }, "o": { "type": "json" } }, "primaryKey": [ "id" ] } }, "relationships": {} }"#)).clone() } /// The queries of the schema, one per table: `zql::t()`. pub mod zql { /// The rows of `t`. pub fn t() -> super::z::Query { super::z::Query::table(super::schema()) } } /// The CRUD operations of a mutator, one per table: `mutate::t(tx).insert(&row)`. pub mod mutate { /// Inserts, upserts, updates, and deletes rows of `t`. pub fn t(tx: &super::z::Transaction) -> super::z::TypedTableMutator<'_, super::T> { super::z::TypedTableMutator::new(tx) } }