Expand description
Persistent embedded memory mapped graph database with native object queries.
Readme | Quickstart | Queries | Efficient agdb
§Example
use agdb::{Db, QueryBuilder};
let mut db = Db::new("db4.agdb").unwrap();
db.exec_mut(QueryBuilder::insert().nodes().values([[("key", 123).into()]]).query()).unwrap();
let result = db.exec(QueryBuilder::select().ids(1).query()).unwrap();
println!("{:?}", result);
// QueryResult { result: 1, elements: [ DbElement { id: DbId(1), values: [ DbKeyValue { key: String("key"), value: Int(123) } ] } ] }Modules§
Structs§
- DbElement
- Database element used in [
QueryResult] that represents a node or an edge. - DbError
- Universal
agdbdatabase error. It represents any error caused by the database processing such as loading a database, running queries, writing data etc. - DbF64
- Database float is a wrapper around
f64to provide functionality like comparison. The comparison is usingtotal_cmpstandard library function. See its docs to understand how it handles NaNs and other edge cases of floating point numbers. - DbId
- Database id is a wrapper around
i64. The id is an identifier of a database element both nodes and edges. The positive ids represent nodes, negative ids represent edges. The value of0is logically invalid (there cannot be element with id 0) and a default. - DbImpl
- An instance of the
agdbdatabase. To create a database: - DbKey
Orders - DbKey
Value - Database key-value pair (aka property) attached to
database elements. It can be constructed from a
tuple of types that are convertible to
DbValue. - File
Storage - Single file based storage with write ahead log (WAL) for resiliency
implementing
StorageData. It uses the storage name as the file name (.{name}for WAL). It allows multiple readers from the file by opening additional temporary file handles if the single member file handle is being used (read). TheStorageData::read()always returns owning buffer. - File
Storage Memory Mapped - The default implementation of the database storage implementing
StorageData. It combines theFileStorageandMemoryStorageleveraging the former for the persistence and the latter for performance. The read operations are implemented in terms of theMemoryStorageonly and the write operations are implemented in terms of bothFileStorageandMemoryStorage. - Insert
Aliases Query - Query to insert or update aliases of existing nodes.
All
idsmust exist. None of thealiasescan be empty. If there is an existing alias for any of the elements it will be overwritten with a new one. - Insert
Edges Query - Query to inserts edges to the database. The
fromandtoids must exist in the database. There must be enoughvaluesfor all new edges unless set toSinglein which case they will be uniformly applied to all new edges. Theeachflag is only useful iffrom andtoare symmetric (same length) but you still want to connect every origin to every destination. By default it would connect only the pairs. For asymmetric insertseach` is assumed. - Insert
Index Query - Query to create a new index on a given key.
- Insert
Nodes Query - Query to insert nodes to the database. Only one of
count,valuesoraliasesneed to be given as the implementation will derive the count from the other parameters. Ifvaluesis set toSingleeithercountoraliasesmust be provided however. Ifvaluesare not set toSinglethere must be enough value forcount/aliasesunless they are not se and the count is derived from `values. - Insert
Values Query - Query to insert or update key-value pairs (properties)
to existing elements in the database. All
idsmust exist in the database. Ifvaluesis set toSinglethe properties will be inserted uniformly to allidsotherwise there must be enoughvaluesfor allids. - KeyValue
Comparison - Comparison of a value stored under specific
keyto a value using the comparison operator. - Memory
Storage - Query
Builder - The starting point of all queries.
- Query
Condition - Query condition. The condition consists of
data, logic operator and a modifier. - Query
Result - Universal database result. Successful
execution of a query will always yield
this type. The
resultfield is a numerical representation of the result while theelementsare the list ofDbElements with database ids and properties (key-value pairs). - Remove
Aliases Query - Query to remove aliases from the database. It is not an error if an alias to be removed already does not exist.
- Remove
Index Query - Query to create a new index on a given key.
- Remove
Query - Query to remove database elements (nodes & edges). It
is not an error if any of the
idsdo not already exist. - Remove
Values Query - Query to remove properties from existing elements
in the database. All of the specified
idsmust exist in the database however they do not need to have all the listed keys (it is NOT an error if any or all keys do not exist on any of the elements). - Search
Query - Query to search for ids in the database following the graph.
- Select
Aliases Query - Query to select aliases of given ids. All of the ids must exist in the database and have an alias.
- Select
AllAliases Query - Query to select all aliases in the database.
- Select
Edge Count Query - Query to select number of edges of given node ids. All of the ids must exist in the database. If any of the ids is not a node the result will be 0 (not an error).
- Select
Indexes Query - Query to select all indexes in the database.
- Select
KeyCount Query - Query to select number of properties (key count) of given ids. All of the ids must exist in the database.
- Select
Keys Query - Query to select only property keys of given ids. All of the ids must exist in the database.
- Select
Node Count Query - Query to select number of nodes in the database.
- Select
Values Query - Query to select elements with only certain properties of given ids. All ids must exist in the database and all of them must have the requested properties.
- Transaction
- The
Transactionis a proxy struct that encapsulates an immutably borrowedDbImpl. It allows running queries viaexec(). - Transaction
Mut - The
TransactionMutis a proxy struct that encapsulates a mutably borrowedDbImpl. It allows running queries viaexec()andexec_mut().
Enums§
- AnyStorage
- The enum that can hold any of the other storage types
and that implements the
StorageDatatrait by delegating to the inner storage type. When constructed withAnyStorage::new()it will be the memory mapped variant. - Comparison
- Comparison of database values ([
DbValue]) used bykey()condition. Supports the usual set of named comparisons:==, !=, <, <=, >, =>pluscontains(). The comparisons are type strict except for thecontainscomparison which allows vectorized version of the base type. Notably however it does not support thebytesand integral types where the “contains” makes little sense (i.e. does 3 contain 1?). - Count
Comparison - Comparison of unsigned integers (
u64) used bydistance()andedge_count*()conditions. Supports the usual set of named comparisons:==, !=, <, <=, >, =>. - DbKey
Order - Ordering for search queries
- DbValue
- Database value is a strongly types value.
- Query
Condition Data - Query condition data
- Query
Condition Logic - Logical operator for query conditions
- Query
Condition Modifier - Query condition modifier
- QueryId
- Database id used in queries that lets you refer to a database element as numerical id or a string alias.
- Query
Ids - List of database ids used in queries. It
can either represent a list of
QueryIds or a search query. Search query allows query nesting and sourcing the ids dynamically for another query most commonly with the select queries. - Query
Values - Helper type distinguishing uniform (
Single) values and multiple (Multi) values in database queries. - Search
Query Algorithm - Search algorithm to be used
Traits§
- Agdb
Serialize - DbType
- Trait that allows use of user defined values
directly by facilitating translation from/to
database primitive types. The names of fields
becomes keys of type
String. Values must be of types that are convertible to/from database primitive types. - DbType
Marker - Marker trait for user values to get around
conflicting trait implementations between database
and blanket
stdimplementations. Implement it or use the derive macroagdb::DbTypeMarkerfor custom types that are to be used with the database. - Query
- Trait for immutable
agdbdatabase queries. This trait is unlikely to be implementable for user types. - Query
Mut - Trait for mutable
agdbdatabase queries. This trait is unlikely to be implementable for user types. - Stable
Hash - Storage
Data - Minimum set of data operations required by the database to store & retrieve data.
Type Aliases§
- Db
- The default implementation of the database using memory mapped file (full ACID) with
write ahead log. If your data set exceeds available (or reasonable amount) of memory
consider using
DbFileinstead. You can load the file created withDbFileand vice versa. - DbAny
- A convenience alias for a Db type that can use any implemented storage (mapper, memory or file).
- DbAny
Transaction - A convenience alias for the
Transactiontype for the defaultDbAny. - DbAny
Transaction Mut - A convenience alias for the
TransactionMuttype for the defaultDbAny. - DbFile
- The file based implementation of the database (full ACID) with write ahead logging and
but minimum memory footprint but slower than the default
Db. You can load the file created withDband vice versa. - DbFile
Transaction - A convenience alias for the
Transactiontype for the defaultDbFile. - DbFile
Transaction Mut - A convenience alias for the
TransactionMuttype for the defaultDbFile. - DbMemory
- The purely in-memory implementation of the database. It has no persistence but offers unmatched performance.
- DbMemory
Transaction - A convenience alias for the
Transactiontype for the defaultDbMemory. - DbMemory
Transaction Mut - A convenience alias for the
TransactionMuttype for the defaultDbMemory. - DbTransaction
- A convenience alias for the
Transactiontype for the defaultDb. - DbTransaction
Mut - A convenience alias for the
TransactionMuttype for the defaultDb. - Storage
Slice - Convenience alias for
Cow<'a, [u8]>.
Derive Macros§
- DbElement
- The same as DbType but additionally implements
DbType::db_element_id()allowing more streamlined selection and search of strongly typed elements. This derive adds additional element property to the element representation in the database of type(String, String), i.e.("db_element_id", <usertypename>.to_string()). - DbSerialize
- The derive macro to add
agdbplatform agnostic serialization support. This is only needed if you want to serialize custom complex data structures and do not want or cannot use serde. It is primarily used internally to serialize theagdbdata structures. - DbType
- The derive macro to add
agdbcompatibility to user defined types. It implements [agdb::UserDbType] for the type automatically to allow your type to be read and stored from/to the database. - DbType
Marker - The helper derive macro to add
agdbcompatibility to user defined types. This type provides blank implementation of theagdb::DbTypeMarkertrait. This is needed for the vectorized custom values to be compatible with the database as theFromtrait implementation without it conflicts with the blanket implementations. - DbValue
- The derive macro to allow automatically serializing user types
into
DbValue::Bytes. Useful when derivingDbTypefor a custom type with nested custom types or enums as it avoids the need to manually implement From/TryFrom for such nested types. It does additionally support enums and vectorized types (Vec<T>).