Skip to content

Commit

Permalink
indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
Raffa Hind committed Jan 26, 2025
1 parent 3097570 commit 99f5c78
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/neo4j_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@ pub static ACCOUNT_UNIQUE: &str =
// "CREATE CONSTRAINT account_not_null FOR (n:Account) REQUIRE n.address IS NOT NULL";

pub static TX_CONSTRAINT: &str =
"CREATE CONSTRAINT unique_tx_hash IF NOT EXISTS FOR ()-[r:Tx]-() REQUIRE r.tx_hash IS UNIQUE";
"CREATE CONSTRAINT unique_tx_hash IF NOT EXISTS FOR ()-[r:Transfer]-() REQUIRE r.tx_hash IS UNIQUE";

// assumes the Account.address is stored as a hex string
// NOTE: hex numericals may query faster but will be hard to use in user interface
pub static INDEX_HEX_ADDR: &str =
"CREATE TEXT INDEX hex_addr IF NOT EXISTS FOR (n:Account) ON (n.address)";

pub static INDEX_TX_TIMESTAMP: &str =
"CREATE INDEX tx_timestamp IF NOT EXISTS FOR ()-[r:Tx]-() ON (r.block_timestamp)";
"CREATE INDEX tx_timestamp IF NOT EXISTS FOR ()-[r:Transfer]-() ON (r.block_timestamp)";

pub static INDEX_TX_HASH: &str =
"CREATE INDEX tx_function IF NOT EXISTS FOR ()-[r:Tx]-() ON (r.tx_hash)";
"CREATE INDEX tx_function IF NOT EXISTS FOR ()-[r:Transfer]-() ON (r.tx_hash)";

pub static INDEX_TX_FUNCTION: &str =
"CREATE INDEX tx_function IF NOT EXISTS FOR ()-[r:Tx]-() ON (r.function)";
"CREATE INDEX tx_function IF NOT EXISTS FOR ()-[r:Transfer]-() ON (r.function)";

pub static INDEX_TX_RELATION: &str =
"CREATE INDEX tx_relation IF NOT EXISTS FOR ()-[r:Tx]-() ON (r.relation)";
// pub static INDEX_TX_RELATION: &str =
// "CREATE INDEX tx_relation IF NOT EXISTS FOR ()-[r:Transfer:Vouch:Onboarding]-() ON (r.relation)";

pub static INDEX_SWAP_ID: &str =
"CREATE INDEX swap_account_id IF NOT EXISTS FOR (n:SwapAccount) ON (n.swap_id)";
Expand All @@ -46,6 +46,9 @@ pub static INDEX_EXCHANGE_LINK_LEDGER: &str = "
CREATE INDEX link_ledger IF NOT EXISTS FOR ()-[r:DailyLedger]->() ON (r.date)
";

pub static INDEX_LIFETIME: &str = "
CREATE INDEX link_ledger IF NOT EXISTS FOR ()-[r:Lifetime]->() ON (r.amount)
";
/// get the testing neo4j connection
pub async fn get_neo4j_localhost_pool(port: u16) -> Result<Graph> {
let uri = format!("127.0.0.1:{port}");
Expand Down Expand Up @@ -77,10 +80,11 @@ pub async fn maybe_create_indexes(graph: &Graph) -> Result<()> {
INDEX_TX_TIMESTAMP,
INDEX_TX_HASH,
INDEX_TX_FUNCTION,
INDEX_TX_RELATION,
// INDEX_TX_RELATION,
INDEX_SWAP_ID,
INDEX_EXCHANGE_LEDGER,
INDEX_EXCHANGE_LINK_LEDGER,
INDEX_LIFETIME,
])
.await?;
txn.commit().await?;
Expand Down

0 comments on commit 99f5c78

Please sign in to comment.