mirror of
https://github.com/NexVeridian/wikidata-to-surrealdb.git
synced 2025-09-02 01:49:13 +00:00
swap to Option<Thing>
This commit is contained in:
parent
e0d2cef391
commit
08d8d2d63b
3 changed files with 27 additions and 9 deletions
11
Useful queries.md
Normal file
11
Useful queries.md
Normal file
|
@ -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;
|
10
src/main.rs
10
src/main.rs
|
@ -33,13 +33,17 @@ async fn main() -> Result<(), Error> {
|
||||||
let json: Value = from_str(&line)?;
|
let json: Value = from_str(&line)?;
|
||||||
let data = Entity::from_json(json).expect("Failed to parse JSON");
|
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<EntityMini> = db.delete(&id).await?;
|
let _: Option<EntityMini> = db.delete(&id).await?;
|
||||||
let _: Option<EntityMini> = db.create(&id).content(data.clone()).await?;
|
let _: Option<EntityMini> = db.create(&id).content(data.clone()).await?;
|
||||||
|
|
||||||
let _: Option<Claims> = db.delete(&claims.0).await?;
|
let id = claims.id.clone().expect("No ID");
|
||||||
let _: Option<Claims> = db.create(&claims.0).content(claims.1).await?;
|
claims.id = None;
|
||||||
|
let _: Option<Claims> = db.delete(&id).await?;
|
||||||
|
let _: Option<Claims> = db.create(&id).content(claims).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
15
src/utils.rs
15
src/utils.rs
|
@ -31,6 +31,7 @@ impl ClaimData {
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||||
pub struct Claims {
|
pub struct Claims {
|
||||||
|
pub id: Option<Thing>,
|
||||||
pub claims: Vec<Claim>,
|
pub claims: Vec<Claim>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,25 +43,26 @@ pub struct Claim {
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||||
pub struct EntityMini {
|
pub struct EntityMini {
|
||||||
|
pub id: Option<Thing>,
|
||||||
pub label: String,
|
pub label: String,
|
||||||
pub claims: Thing,
|
pub claims: Thing,
|
||||||
pub description: String,
|
pub description: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EntityMini {
|
impl EntityMini {
|
||||||
pub fn from_entity(entity: Entity) -> (Thing, (Thing, Claims), Self) {
|
pub fn from_entity(entity: Entity) -> (Claims, Self) {
|
||||||
let thing_claim = Thing {
|
let thing_claim = Thing {
|
||||||
id: get_id_entity(&entity).id,
|
id: get_id_entity(&entity).id,
|
||||||
tb: "Claims".to_string(),
|
tb: "Claims".to_string(),
|
||||||
};
|
};
|
||||||
|
|
||||||
(
|
(
|
||||||
get_id_entity(&entity),
|
Claims {
|
||||||
(
|
id: Some(thing_claim.clone()),
|
||||||
thing_claim.clone(),
|
..Self::flatten_claims(entity.claims.clone())
|
||||||
Self::flatten_claims(entity.claims.clone()),
|
},
|
||||||
),
|
|
||||||
Self {
|
Self {
|
||||||
|
id: Some(get_id_entity(&entity)),
|
||||||
label: get_name(&entity),
|
label: get_name(&entity),
|
||||||
claims: thing_claim,
|
claims: thing_claim,
|
||||||
description: get_description(&entity).unwrap_or("".to_string()),
|
description: get_description(&entity).unwrap_or("".to_string()),
|
||||||
|
@ -70,6 +72,7 @@ impl EntityMini {
|
||||||
|
|
||||||
fn flatten_claims(claims: Vec<(Pid, ClaimValue)>) -> Claims {
|
fn flatten_claims(claims: Vec<(Pid, ClaimValue)>) -> Claims {
|
||||||
Claims {
|
Claims {
|
||||||
|
id: None,
|
||||||
claims: claims
|
claims: claims
|
||||||
.iter()
|
.iter()
|
||||||
.flat_map(|(pid, claim_value)| {
|
.flat_map(|(pid, claim_value)| {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue