diff --git a/Useful queries.md b/Useful queries.md new file mode 100644 index 0000000..85cfdca --- /dev/null +++ b/Useful queries.md @@ -0,0 +1,11 @@ +# Get number of episodes +let $number_of_episodes = (select claims.claims[where id = Property:1113][0].value.ClaimValueData.Quantity.amount as number_of_episodes from Entity where label = "Black Clover, season 1")[0].number_of_episodes; + +return $number_of_episodes[0].number_of_episodes; + +update Entity SET number_of_episodes=$number_of_episodes where label = "Black Clover, season 1"; + +# Get Parts +let $parts = (select claims.claims[where id = Property:527].value.Thing as parts from Entity where label = "Black Clover")[0].parts; + +return $parts; diff --git a/src/main.rs b/src/main.rs index 9942d51..483ac15 100644 --- a/src/main.rs +++ b/src/main.rs @@ -33,13 +33,17 @@ async fn main() -> Result<(), Error> { let json: Value = from_str(&line)?; let data = Entity::from_json(json).expect("Failed to parse JSON"); - let (id, claims, data) = EntityMini::from_entity(data); + let (mut claims, mut data) = EntityMini::from_entity(data); + let id = data.id.clone().expect("No ID"); + data.id = None; let _: Option = db.delete(&id).await?; let _: Option = db.create(&id).content(data.clone()).await?; - let _: Option = db.delete(&claims.0).await?; - let _: Option = db.create(&claims.0).content(claims.1).await?; + let id = claims.id.clone().expect("No ID"); + claims.id = None; + let _: Option = db.delete(&id).await?; + let _: Option = db.create(&id).content(claims).await?; } Ok(()) diff --git a/src/utils.rs b/src/utils.rs index 9dc26c2..b947dee 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -31,6 +31,7 @@ impl ClaimData { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct Claims { + pub id: Option, pub claims: Vec, } @@ -42,25 +43,26 @@ pub struct Claim { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct EntityMini { + pub id: Option, pub label: String, pub claims: Thing, pub description: String, } impl EntityMini { - pub fn from_entity(entity: Entity) -> (Thing, (Thing, Claims), Self) { + pub fn from_entity(entity: Entity) -> (Claims, Self) { let thing_claim = Thing { id: get_id_entity(&entity).id, tb: "Claims".to_string(), }; ( - get_id_entity(&entity), - ( - thing_claim.clone(), - Self::flatten_claims(entity.claims.clone()), - ), + Claims { + id: Some(thing_claim.clone()), + ..Self::flatten_claims(entity.claims.clone()) + }, Self { + id: Some(get_id_entity(&entity)), label: get_name(&entity), claims: thing_claim, description: get_description(&entity).unwrap_or("".to_string()), @@ -70,6 +72,7 @@ impl EntityMini { fn flatten_claims(claims: Vec<(Pid, ClaimValue)>) -> Claims { Claims { + id: None, claims: claims .iter() .flat_map(|(pid, claim_value)| {