Expand description
Rust bindings for the Velr runtime.
This crate exposes a high-level API over the Velr runtime ABI (loaded via the runtime module),
wrapping raw FFI pointers in RAII types with predictable lifetimes.
§Threading model
Velr uses a connection-affine model:
-
Velr(the connection) isSend+!Sync.- ✅ You may move a connection to another thread. Example: spawn a worker thread and move the connection into it.
- ❌ Wrapping a connection in
Arcdoes not make it safe to share across threads;Velris!Sync, so concurrent shared use is not supported.
-
In-flight / handle-based objects are
!Send+!Sync(thread-affine):ExecTables,TableResult,RowIter,VelrTx,ExecTablesTx,VelrSavepoint,ExplainTrace.- ❌ You may not move these to another thread.
- ❌ You may not share these across threads.
Practical implications:
- ✅ Many connections across many threads is fine (open one connection per thread).
- ✅ You can move a connection between threads (e.g., create in main, move into worker).
- ❌ You cannot run concurrent operations on the same connection across threads.
If you need parallelism, open multiple connections and/or use a pool.
§Results and lifetimes
Queries can produce zero or more result tables:
Velr::exec/VelrTx::execstream tables viaExecTables/ExecTablesTx.Velr::exec_one/VelrTx::exec_onereturn a singleTableResult.
Rows are processed via callbacks. Individual cell values are represented by CellRef, which
may borrow bytes from buffers owned by the underlying row cursor. For Text/Json values, the
borrowed bytes remain valid until the next call to RowIter::next on the same iterator (or
until the iterator is dropped). In typical usage this means the borrows are scoped to the row
callback invocation.
§Bounded result previews
Hosts that need projected column names plus a small sample can use QueryOptions with
Velr::exec_with_options, Velr::exec_one_with_options, or Velr::run_with_options.
The row cap is enforced by Velr while emitting result rows; the driver does not rewrite the
Cypher text.
let db = Velr::open(None)?;
let mut table = db.exec_one_with_options(
"UNWIND [1,2,3,4,5,6] AS x RETURN x ORDER BY x LIMIT 10",
QueryOptions::max_result_rows(5),
)?;
assert_eq!(table.column_names(), &["x".to_string()]);
let rows = table.collect(|row| Ok(format!("{:?}", row[0])))?;
assert_eq!(rows.len(), 5);Existing Cypher LIMIT clauses still apply. For example, LIMIT 3 with
QueryOptions::max_result_rows(5) emits at most three rows, while LIMIT 10 with the same
option emits at most five rows. Use QueryOptions::max_result_rows(0) when you want result
table metadata, including column names, without materializing any rows.
§Query parameter binding
Use params! or QueryParams for params-only calls, or combine params with bounded
previews through QueryOptions. Query text uses $name; API parameter names omit the
leading $.
let db = Velr::open(None)?;
db.run_with_params(
"CREATE (:Person {name: $name, age: $age})",
velr::params! {
name: "Alice",
age: 42_i64,
}?,
)?;
let mut table = db.exec_one_with_options(
"MATCH (p:Person) WHERE p.age >= $min_age RETURN p.name AS name ORDER BY name",
QueryOptions::max_result_rows(20).with_param("min_age", 18_i64)?,
)?;
assert_eq!(table.column_names(), &["name".to_string()]);§Errors
Most operations return Result<T>. On failure, you get an Error containing a numeric
code (originating from the runtime ABI) and an optional message.
§Schema migration and introspection
This runtime’s current on-disk schema is version 7. Supported older databases can be opened
without automatic migration. Reads remain available on those databases, but writes and
features that require the current schema return a query error until the user explicitly
migrates. SHOW CURRENT GRAPH SHAPE is available once a database has reached schema version 5.
Use Velr::schema_version, Velr::current_schema_version, and
Velr::needs_migration to inspect the connection state. Use Velr::migrate or execute
MIGRATE DATABASE from maintenance code when upgrading is intended.
SHOW CURRENT GRAPH SHAPE exposes Velr’s observed graph schema: labels, relationship types,
properties, observed value types, and counts. Use YIELD to compose it with WHERE and
RETURN, or YIELD * to inspect the full row shape.
Fulltext search is also available through normal Cypher execution. Use CREATE FULLTEXT INDEX
to define an index and CALL db.index.fulltext.queryNodes(...) to search it. Fulltext indexes
use a sidecar next to file-backed databases, and no dedicated driver methods are required. The
query grammar supports terms, phrases, field scoping, boolean grouping, required/excluded
terms, phrase slop, phrase-prefix, boosts, and * match-all. score is a non-normalized
relevance score. Higher scores are better within a single query result set; scores are not
guaranteed to be in 0..1 or comparable across different queries.
Macros§
- params
- Build a
QueryParamsmap with compact syntax.
Structs§
- Date
Value - Duration
Value - Error
- Error returned by the Velr API.
- Exec
Tables - Streaming result of an execution that may yield multiple tables.
- Exec
Tables Tx - Streaming result of an execution within a transaction.
- Explain
Plan - One explain plan plus all steps in it.
- Explain
Plan Meta - Owned plan metadata returned from an
ExplainTrace. - Explain
Statement - One explain statement plus its SQLite query-plan detail lines.
- Explain
Statement Meta - Owned statement metadata returned from an
ExplainTrace. - Explain
Step - One explain step plus all statements in it.
- Explain
Step Meta - Owned step metadata returned from an
ExplainTrace. - Explain
Trace - EXPLAIN / EXPLAIN ANALYZE trace handle.
- Geography
Value - Geometry
Value - Line
String Value - Linear
Ring Value - Local
Date Time Value - Local
Time Value - Migration
Report - Report returned by
Velr::migrate. - Point
Value - Polygon
Value - Query
Options - Out-of-band execution options for query result emission.
- Query
Param Error - Error returned while constructing or binding query parameters.
- Query
Params - Named parameters supplied to a Cypher query.
- RowIter
- Iterator over rows of a table.
- Table
Result - A single result table produced by query execution.
- Vector
Embedding Field - One named Velr value passed to a registered vector embedding callback.
- Vector
Embedding Input - One source row passed to a registered vector embedding callback.
- Vector
Value - Velr
- Velr
Savepoint - A scoped savepoint handle within a transaction (thread-affine).
- VelrTx
- A transaction handle (thread-affine).
- Zoned
Date Time Value - Zoned
Time Value
Enums§
- CellRef
- Borrowed view of a single cell value in a result row.
- Geometry
Shape - List
Iter - List
Value - Migration
Status - Status returned by
Velr::migrate. - Position
- Property
Value - Property
Value Ref - Query
Value - A Cypher value supplied out-of-band through
QueryParams. - Vector
Elem - Vector
Embedding Purpose - Why Velr is asking an embedder to produce vectors.
- Vector
Entity Kind - Graph entity kind for indexed vector embedding inputs.
- Vector
Iter - Vector
Storage - Vector
Type
Traits§
- TryInto
Query Value - Fallible conversion from a Rust value into a Cypher parameter value.
Type Aliases§
- Result
- Convenience result type used throughout the public API.
- Vector
Embedding Batch Result