forked from 0LNetworkCommunity/libra-framework
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ccef148
commit 5482239
Showing
3 changed files
with
52 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ pub mod table_structs; | |
pub mod warehouse_cli; | ||
pub mod unzip_temp; | ||
pub mod restaurant; | ||
pub mod neo4j_init; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use anyhow::Result; | ||
use neo4rs::Graph; | ||
|
||
pub static ACCOUNT_CONSTRAINT: &str = | ||
"CREATE CONSTRAINT unique_address FOR (n:Account) REQUIRE n.address IS UNIQUE"; | ||
|
||
pub static TX_CONSTRAINT: &str = | ||
"CREATE CONSTRAINT unique_tx_hash FOR ()-[r:Tx]-() REQUIRE r.txs_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)"; | ||
|
||
pub static INDEX_TX_FUNCTION: &str = | ||
"CREATE INDEX tx_function IF NOT EXISTS FOR ()-[r:Tx]-() ON (r.function)"; | ||
|
||
pub async fn init_neo4j(graph: Graph) -> Result<()>{ | ||
let mut txn = graph.start_txn().await.unwrap(); | ||
|
||
txn.run_queries([ | ||
ACCOUNT_CONSTRAINT, | ||
TX_CONSTRAINT, | ||
INDEX_HEX_ADDR, | ||
INDEX_TX_TIMESTAMP, | ||
INDEX_TX_FUNCTION, | ||
]).await?; | ||
txn.commit().await?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters