lbug/lib.rs
1//! Bindings to Lbug: an in-process property graph database management system built for query speed and scalability.
2//!
3//! ## Example Usage
4//! ```
5//! use lbug::{Database, SystemConfig, Connection};
6//! # use anyhow::Error;
7//!
8//! # fn main() -> Result<(), Error> {
9//! # let temp_dir = tempfile::tempdir()?;
10//! # let path = temp_dir.path().join("testdb");
11//! let db = Database::new(path, SystemConfig::default())?;
12//! let conn = Connection::new(&db)?;
13//! conn.query("CREATE NODE TABLE Person(name STRING, age INT64, PRIMARY KEY(name));")?;
14//! conn.query("CREATE (:Person {name: 'Alice', age: 25});")?;
15//! conn.query("CREATE (:Person {name: 'Bob', age: 30});")?;
16//!
17//! let mut result = conn.query("MATCH (a:Person) RETURN a.name AS NAME, a.age AS AGE;")?;
18//! println!("{}", result);
19//! # temp_dir.close()?;
20//! # Ok(())
21//! # }
22//! ```
23//! ## Building
24//!
25//! By default, the Lbug C++ library will be compiled from source and statically linked.
26//!
27//! If you want to instead link against a pre-built version of the library, the following environment
28//! variables can be used to configure the build process:
29//!
30//! - `LBUG_SHARED`: If set, link dynamically instead of statically
31//! - `LBUG_INCLUDE_DIR`: Directory of Lbug's headers
32//! - `LBUG_LIBRARY_DIR`: Directory containing Lbug's pre-built libraries.
33//!
34//! Example:
35//! ```bash
36//! lbug_prebuilt_dir=/tmp/lbug # pre-built Lbug from https://docs.ladybugdb.com/installation/#cc
37//! lbug_prebuilt_dir=/path_to_lbug_source/build/release/src # Lbug built from source
38//! export LBUG_LIBRARY_DIR="lbug_prebuilt_dir"
39//! export LBUG_INCLUDE_DIR="lbug_prebuilt_dir"
40//! export LBUG_SHARED=1
41//! ```
42//! On macOS:
43//! ```bash
44//! brew install lbug
45//! export LBUG_LIBRARY_DIR=/opt/homebrew/lib
46//! export LBUG_INCLUDE_DIR=/opt/homebrew/include
47//! export LBUG_SHARED=1
48//! ```
49//!
50//! ## Using Extensions
51//! By default, binaries created using this library will not work with Lbug's
52//! [extensions](https://docs.ladybugdb.com/extensions/) (except on Windows/MSVC, where the linker works differently).
53//!
54//! If you want to use extensions in binaries (binary crates or tests) using this
55//! library, you will need to add the following (or a similar command; see
56//! [build-scripts](https://doc.rust-lang.org/cargo/reference/build-scripts.html#rustc-link-arg))
57//! to your build.rs (or create one) so that the binary
58//! produced acts like a library that the extension can link with. Not doing this will produce
59//! undefined symbol errors when the extension is loaded:
60//!
61//! ```ignore
62//! println!("cargo:rustc-link-arg=-rdynamic");
63//! ```
64
65pub use connection::{Connection, PreparedStatement};
66pub use database::{Database, SystemConfig};
67pub use error::Error;
68pub use logical_type::LogicalType;
69#[cfg(feature = "arrow")]
70pub use query_result::ArrowIterator;
71pub use query_result::{CSVOptions, QueryResult};
72pub use value::{InternalID, NodeVal, RelVal, Value};
73
74mod connection;
75mod database;
76mod error;
77mod ffi;
78mod logical_type;
79mod query_result;
80mod value;
81
82/// The version of the Lbug crate as reported by Cargo's `CARGO_PKG_VERSION` environment variable
83pub const VERSION: &str = env!("CARGO_PKG_VERSION");
84/// Returns the storage version of the Lbug library
85pub fn get_storage_version() -> u64 {
86 crate::ffi::ffi::get_storage_version()
87}