Skip to main content

core_api/
lib.rs

1pub mod algo;
2mod db;
3pub mod history;
4mod ingest;
5pub mod mask;
6pub mod schema;
7mod shared;
8pub mod subscription;
9
10pub use algo::{
11    AlgoDir, DegreeConfig, DegreeReport, PageRankConfig, PageRankReport, WccConfig, WccReport,
12};
13pub use core_query::{CmpOp, Dir, Filter, ResultSet};
14pub use core_rules::suggest::DEFAULT_SEED as SUGGEST_DEFAULT_SEED;
15pub use core_rules::{
16    default_max_edges, is_keymatch_rooted, AggFn, Predicate, RuleDef, RuleSuggestion,
17    SuggestConfig, SuggestReport, ViewDef, ViewSource, ViewStore, DEFAULT_KEYMATCH_TOP_K,
18    DEFAULT_SCORED_TOP_K,
19};
20pub use core_storage::{Direction, GraphError, Result, Value};
21pub use db::{
22    BatchBuilder, DeleteReport, EdgeInfo, Explanation, FsyncPolicy, GraphDb, MutationEvent,
23    NodeInfo, NodeRef, PredicateSummary, RuleStats, SnapshotOptions, Stats,
24};
25pub use history::{HistoryChange, HistoryEntry};
26pub use ingest::{
27    json_to_rows, json_to_value, AutoFk, FkSkip, IngestOptions, IngestReport, JsonRows,
28};
29pub use mask::NodeMask;
30pub use schema::{Schema, SchemaDiff};
31pub use shared::SharedDb;
32pub use subscription::{DbEvent, Subscription, DEFAULT_SUB_CAPACITY};
33
34/// Return `true` if `cypher` is a write statement (CREATE / MERGE / MATCH…SET /
35/// MATCH…DELETE).  Returns `Err` only when the string fails to lex.
36///
37/// Used by the HTTP server to dispatch to the write lock without a full parse.
38pub fn is_write_query(cypher: &str) -> std::result::Result<bool, String> {
39    let toks = core_query::cypher::lex(cypher).map_err(|e| format!("lex: {e}"))?;
40    Ok(core_query::cypher::is_write_tokens(&toks))
41}
42
43/// Return the number of valid WAL commits in the database at `dir`.
44///
45/// Useful for displaying "as-of commit N of M" in CLIs without opening the
46/// full database.  Returns 0 if the WAL file does not exist (e.g., after
47/// `snapshot()` which truncates it to empty).
48pub fn wal_commit_count_at(dir: &std::path::Path) -> crate::Result<u64> {
49    let wal_path = dir.join("wal.bin");
50    let bytes = match std::fs::read(&wal_path) {
51        Ok(b) => b,
52        Err(e) if e.kind() == std::io::ErrorKind::NotFound => Vec::new(),
53        Err(e) => return Err(core_storage::GraphError::Io(e)),
54    };
55    Ok(core_storage::wal::wal_commits(&bytes))
56}