Expand description
This crate provides the core functionalities of CozoDB. It may be used to embed CozoDB in your application.
This doc describes the Rust API. To learn how to use CozoDB to query (CozoScript), see:
Rust API usage:
use cozo::*;
let db = DbInstance::new("mem", "", Default::default()).unwrap();
let script = "?[a] := a in [1, 2, 3]";
let result = db.run_script(script, Default::default()).unwrap();
println!("{:?}", result);
We created an in-memory database above. There are other persistent options: see DbInstance::new. It is perfectly fine to run multiple storage engines in the same process.
Features
-
compact
(enabled by default) — Enables theminimal
,requests
andgraph-algo
features. -
compact-single-threaded
— Enables theminimal
,requests
andgraph-algo
features in single threaded mode. -
minimal
— Enables thestorage-sqlite
feature. -
storage-sqlite
— Enables the Sqlite backend, also allows backup and restore with Sqlite data files. Sqlite is easy to compile, has very low resource requirements and reasonable performance, but does not support much concurrency. -
storage-rocksdb
— Enables the RocksDB backend. RocksDB is hard to compile on some platforms, uses more resources than SQLite, but is very performant and supports an extremely high level of concurrency. You can also fine-tune RocksDB options. -
graph-algo
— Enables the graph algorithms. -
requests
— Allows the utilities to make web requests to fetch data. -
jemalloc
— Uses jemalloc as the global allocator, can make a difference in performance. -
io-uring
— Enables io-uring option for the RocksDB storage -
wasm
— Polyfills for the WASM target
The following features are highly experimental:
-
storage-sled
— Enables the Sled backend. Sled is slower than Sqlite for the usual workload of Cozo, can use quite a lot of disk space, and may not be stable enough. In general you should use RocksDB instead. The Sled engine does not support time travel. -
storage-tikv
— Enables the TiKV client backend. The only reason that you may want to use this is that your data does not fit in a single machine. This engine is orders of magnitude slower than every other engine for graph traversals, due to the significant network overhead. Simple point-lookup queries are fine, though. The TiKV engine does not support time travel.
Recommendation for features to enable
Generally you will want the storage-sqlite
and graph-algo
features enabled,
unless your environment makes compiling them difficult. The backup/restore functionalities
are only available if storage-sqlite
is on. Without graph-algo
you cannot use any graph algorithms
(utilities are still available),
which could be OK if you only want to deal with pure Datalog.
The requests
feature allows the database to make outgoing HTTP requests to fetch data
into queries – only enable it if you need it.
The wasm
feature simply patches some functions so that they can compile on WASM platform,
which lacks some std implementations at the moment. (On WASM you must also enable nothread
).
This feature will not work on any other platform.
The jemalloc
feature only makes sense for desktop and servers. It could improve performance,
sometimes substantially, but you need to benchmark for your use case. It also tends to break
builds on untested platforms. None of our prebuilt binaries have it enabled.
Enable storage-rocksdb
if you expect high concurrency or want better performance than SQLite,
but note that RocksDB is much more resource-hungry and takes long to compile.
The other storage options are just for experimentation. We do not recommend using them.
Structs
Enums
Traits
Functions
StoreTx
.