a small relational database with user-editable schema for manual data entry
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.
yopa/yopa/src/insert.rs

60 lines
1.2 KiB

//! Helper struct for inserting relational data in the database
3 years ago
use serde::{Deserialize, Serialize};
use super::data::TypedValue;
3 years ago
use super::ID;
/// Value to insert
3 years ago
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct InsertValue {
pub model_id: ID,
3 years ago
pub value: TypedValue,
}
impl InsertValue {
3 years ago
pub fn new(model_id: ID, value: TypedValue) -> Self {
Self {
model_id,
3 years ago
value,
}
}
}
/// Info for inserting a relation
3 years ago
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct InsertRel {
pub model_id: ID,
pub related_id: ID,
3 years ago
pub values: Vec<InsertValue>,
}
impl InsertRel {
3 years ago
pub fn new(model_id: ID, related_id: ID, values: Vec<InsertValue>) -> Self {
Self {
model_id,
related_id,
3 years ago
values,
}
}
}
/// Info for inserting a relation
3 years ago
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct InsertObj {
pub model_id: ID,
pub values: Vec<InsertValue>,
pub relations: Vec<InsertRel>,
}
impl InsertObj {
3 years ago
pub fn new(model_id: ID, values: Vec<InsertValue>, relations: Vec<InsertRel>) -> Self {
Self {
model_id,
values,
3 years ago
relations,
}
}
}