pub trait Model:
Sized
+ Send
+ Sync {
type Schema;
type FieldChanges: Send + Sync;
// Required methods
fn table_name() -> &'static str;
fn schema_version() -> &'static str;
fn get<'life0, 'life1, 'async_trait>(
id: &'life0 str,
valence: &'life1 Valence,
) -> Pin<Box<dyn Future<Output = Result<Option<Self>, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait;
fn create<'life0, 'async_trait>(
data: Self,
valence: &'life0 Valence,
) -> Pin<Box<dyn Future<Output = Result<Self, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
Self: 'async_trait;
fn update<'life0, 'life1, 'async_trait>(
id: &'life0 str,
data: Self,
valence: &'life1 Valence,
) -> Pin<Box<dyn Future<Output = Result<Self, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait;
fn delete<'life0, 'life1, 'async_trait>(
id: &'life0 str,
valence: &'life1 Valence,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait;
fn upsert<'life0, 'life1, 'async_trait>(
id: &'life0 str,
data: Self,
valence: &'life1 Valence,
) -> Pin<Box<dyn Future<Output = Result<Self, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait;
fn merge<'life0, 'life1, 'async_trait>(
id: &'life0 str,
patch: Value,
valence: &'life1 Valence,
) -> Pin<Box<dyn Future<Output = Result<Self, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait;
}Expand description
Core trait that all generated models implement.
CRUD methods route through the active Valence backend, applying privacy and ownership
hooks defined in the source schema.
§Examples
Generated models (from valence-codegen) implement this trait. After including
$OUT_DIR/generated_models.rs:
use valence::Model;
let created = Widget::create(widget, &valence).await?;
let loaded = Widget::get(created.id(), &valence).await?;
Widget::update(created.id(), updated, &valence).await?;
Widget::delete(created.id(), &valence).await?;See workspace examples/codegen-host and examples/product-model-host.
Required Associated Types§
Sourcetype FieldChanges: Send + Sync
type FieldChanges: Send + Sync
Field-level change set type used by update/merge paths.
Required Methods§
Sourcefn table_name() -> &'static str
fn table_name() -> &'static str
Physical table name from the schema DSL table: key.
Sourcefn schema_version() -> &'static str
fn schema_version() -> &'static str
Schema version string from the DSL version: key.
Sourcefn get<'life0, 'life1, 'async_trait>(
id: &'life0 str,
valence: &'life1 Valence,
) -> Pin<Box<dyn Future<Output = Result<Option<Self>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn get<'life0, 'life1, 'async_trait>(
id: &'life0 str,
valence: &'life1 Valence,
) -> Pin<Box<dyn Future<Output = Result<Option<Self>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Fetch one row by primary key; returns Ok(None) when absent.
Sourcefn create<'life0, 'async_trait>(
data: Self,
valence: &'life0 Valence,
) -> Pin<Box<dyn Future<Output = Result<Self, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn create<'life0, 'async_trait>(
data: Self,
valence: &'life0 Valence,
) -> Pin<Box<dyn Future<Output = Result<Self, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
Insert a new row.
Sourcefn update<'life0, 'life1, 'async_trait>(
id: &'life0 str,
data: Self,
valence: &'life1 Valence,
) -> Pin<Box<dyn Future<Output = Result<Self, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn update<'life0, 'life1, 'async_trait>(
id: &'life0 str,
data: Self,
valence: &'life1 Valence,
) -> Pin<Box<dyn Future<Output = Result<Self, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Replace an existing row by id.
Sourcefn delete<'life0, 'life1, 'async_trait>(
id: &'life0 str,
valence: &'life1 Valence,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
fn delete<'life0, 'life1, 'async_trait>(
id: &'life0 str,
valence: &'life1 Valence,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Delete one row by id.
Sourcefn upsert<'life0, 'life1, 'async_trait>(
id: &'life0 str,
data: Self,
valence: &'life1 Valence,
) -> Pin<Box<dyn Future<Output = Result<Self, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn upsert<'life0, 'life1, 'async_trait>(
id: &'life0 str,
data: Self,
valence: &'life1 Valence,
) -> Pin<Box<dyn Future<Output = Result<Self, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Create or replace a row by explicit id.
Sourcefn merge<'life0, 'life1, 'async_trait>(
id: &'life0 str,
patch: Value,
valence: &'life1 Valence,
) -> Pin<Box<dyn Future<Output = Result<Self, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn merge<'life0, 'life1, 'async_trait>(
id: &'life0 str,
patch: Value,
valence: &'life1 Valence,
) -> Pin<Box<dyn Future<Output = Result<Self, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Patch an existing row with a partial JSON object when the backend supports merge.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".