You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.2 KiB
58 lines
1.2 KiB
//! Helper struct for inserting relational data in the database
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use super::data::TypedValue;
|
|
use super::ID;
|
|
|
|
/// Value to insert
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct InsertValue {
|
|
pub model: ID,
|
|
pub value: TypedValue,
|
|
}
|
|
|
|
impl InsertValue {
|
|
pub fn new(model_id: ID, value: TypedValue) -> Self {
|
|
Self {
|
|
model: model_id,
|
|
value,
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Info for inserting a relation
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct InsertRel {
|
|
pub model: ID,
|
|
pub related: ID,
|
|
pub values: Vec<InsertValue>,
|
|
}
|
|
|
|
impl InsertRel {
|
|
pub fn new(model_id: ID, related_id: ID, values: Vec<InsertValue>) -> Self {
|
|
Self {
|
|
model: model_id,
|
|
related: related_id,
|
|
values,
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Info for inserting a relation
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct InsertObj {
|
|
pub model: ID,
|
|
pub values: Vec<InsertValue>,
|
|
pub relations: Vec<InsertRel>,
|
|
}
|
|
|
|
impl InsertObj {
|
|
pub fn new(model_id: ID, values: Vec<InsertValue>, relations: Vec<InsertRel>) -> Self {
|
|
Self {
|
|
model: model_id,
|
|
values,
|
|
relations,
|
|
}
|
|
}
|
|
}
|
|
|