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/update.rs

96 lines
2.1 KiB

use serde::{Deserialize, Serialize};
use crate::{ID, TypedValue};
/// Update or insert a value
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UpsertValue {
/// PK, null if creating
pub id: Option<ID>,
/// Property template ID
pub model: ID,
/// Property value
pub value: TypedValue,
}
/// Update or insert a relation
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UpsertRelation {
/// PK, null if creating
pub id: Option<ID>,
/// Relation template ID
pub model: ID,
/// Related model ID
pub related: ID,
/// Relation values
pub values: Vec<UpsertValue>,
}
/// Update an existing object
#[derive(Deserialize,Debug)]
pub struct UpdateObj {
pub id: ID,
pub name: String,
pub values: Vec<UpsertValue>,
pub relations: Vec<UpsertRelation>
}
#[cfg(test)]
mod tests {
use crate::update::UpdateObj;
#[test]
#[cfg(not(feature = "uuid-ids"))]
fn deserialize() {
let json = json!({
"model_id": 0,
"id": 10,
"name": "Recipe1",
"values": [
{
"id": 11,
"model": 3,
"object": 10,
"value": {
"String": "Bla bla bla"
}
},
{
"value": {
"String": "sdfsdfsdf"
},
"model": 3
}
],
"relations": [
{
"id": 12,
"model": 5,
"object": 10,
"related": 8,
"values": [
{
"id": 13,
"model": 6,
"object": 12,
"value": {
"Integer": 15
},
"model": 6
}
]
}
]
});
let obj : UpdateObj = serde_json::from_value(json).unwrap();
}
#[test]
#[cfg(not(feature = "uuid-ids"))]
fn deserialize2() {
let json = json!();
let obj : UpdateObj = serde_json::from_value(json).unwrap();
}
}