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

61 lines
1.3 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 name : String,
pub values: Vec<InsertValue>,
pub relations: Vec<InsertRel>,
}
impl InsertObj {
pub fn new(model_id: ID, name : String, values: Vec<InsertValue>, relations: Vec<InsertRel>) -> Self {
Self {
model: model_id,
name,
values,
relations,
}
}
}