Skip to content

Commit

Permalink
fix args insert
Browse files Browse the repository at this point in the history
  • Loading branch information
0o-de-lally committed Nov 26, 2024
1 parent 0e6daf3 commit 074facf
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
6 changes: 5 additions & 1 deletion src/cypher_templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ MERGE (from)-[rel:Tx {{tx_hash: tx.tx_hash}}]->(to)
ON CREATE SET rel.created_at = timestamp(), rel.modified_at = null
ON MATCH SET rel.modified_at = timestamp()
SET
rel += tx.args,
rel.block_datetime = tx.block_datetime,
rel.block_timestamp = tx.block_timestamp,
rel.relation = tx.relation,
rel.function = tx.function
// Conditionally add `tx.args` if it exists
FOREACH (_ IN CASE WHEN tx.args IS NOT NULL THEN [1] ELSE [] END |
SET rel += tx.args
)
WITH rel
RETURN
Expand Down
8 changes: 7 additions & 1 deletion src/json_rescue_v5_load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ pub async fn decompress_and_extract(tgz_file: &Path, pool: &Graph) -> Result<u64

if queue.len() >= LOAD_QUEUE_SIZE {
let drain: Vec<WarehouseTxMaster> = std::mem::take(&mut queue);
let res = tx_batch(&drain, pool, QUERY_BATCH_SIZE, j.to_str().unwrap()).await?;
let res = tx_batch(
&drain,
pool,
QUERY_BATCH_SIZE,
j.file_name().unwrap().to_str().unwrap(),
)
.await?;
created_count += res.created_tx as u64;
}
}
Expand Down
15 changes: 9 additions & 6 deletions src/schema_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,28 +111,31 @@ impl WarehouseTxMaster {
/// since no sane Cypher serialization libraries exist.
/// and I'm not going to write a deserializer.
/// and JSON is not the same format as cypher property maps
/// JSON5 but the last time someone updated
/// I'd use JSON5 but the last time someone updated
/// that crate was 3 years ago.
pub fn to_cypher_object_template(&self) -> String {
let tx_args = match &self.entry_function {
Some(ef) => to_cypher_object(ef).unwrap_or("null".to_string()),
None => "null".to_owned(),
// make blank string or nest the arguments
let mut tx_args = "NULL".to_string();
if let Some(args) = &self.entry_function {
if let Ok(st) = to_cypher_object(args) {
tx_args = st;
}
};

format!(
r#"{{tx_hash: "{}", block_datetime: datetime("{}"), block_timestamp: {}, relation: "{}", function: "{}", sender: "{}", args: {}, recipient: "{}"}}"#,
r#"{{ args: {maybe_args_here}, tx_hash: "{}", block_datetime: datetime("{}"), block_timestamp: {}, relation: "{}", function: "{}", sender: "{}", recipient: "{}"}}"#,
self.tx_hash.to_hex_literal(),
self.block_datetime.to_rfc3339(),
self.block_timestamp,
self.relation_label.to_cypher_label(),
self.function,
self.sender.to_hex_literal(),
tx_args,
// TODO: should be from relation_label.get_recipient
self.relation_label
.get_recipient()
.unwrap_or(self.sender)
.to_hex_literal(),
maybe_args_here = tx_args,
)
}

Expand Down
3 changes: 0 additions & 3 deletions tests/test_json_rescue_v5_load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ async fn test_load_entrypoint() -> anyhow::Result<()> {
let path = fixtures::v5_json_tx_path();

let tx_count = json_rescue_v5_load::rip(&path, &pool).await?;
// dbg!(&tx_count);
assert!(tx_count == 5244);

Ok(())
Expand All @@ -60,8 +59,6 @@ async fn test_rescue_v5_parse_set_wallet_tx() -> anyhow::Result<()> {

let (vec_tx, _) = extract_v5_json_rescue(&path)?;

dbg!(&vec_tx);

let c = start_neo4j_container();
let port = c.get_host_port_ipv4(7687);
let pool = get_neo4j_localhost_pool(port)
Expand Down

0 comments on commit 074facf

Please sign in to comment.