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

57 lines
1.2 KiB

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