.NET Embedded

Run Traverse as an in-process graph database inside your .NET application — no server required.

dotnet add package Traverse.Embedded

Targets net10.0. Traverse is written in Rust and compiled to a native C library. The Traverse.Embedded package includes native FFI binaries for x64 Windows and x64 Linux, and provides a managed C# wrapper, so you get direct in-process access to the graph engine without any network overhead.

Open a Database

using Traverse.NET;

// Open or create a database file
using var db = Database.Open("mydata.tvdb");

// With license key
using var db = Database.OpenLicensed("mydata.tvdb", "tskey_your_key_here");

The database file is memory-mapped. Call Flush() to write dirty pages to disk, or let Dispose() handle it.

File Size Limit

// Default: 80% of system RAM
Database.MaxFileSizeBytes = 4L * 1024 * 1024 * 1024; // 4 GB

Transactions

Write operations require a transaction. Traverse uses MVCC for concurrent readers.

using var tx = db.BeginTransaction();

var result = tx.Query("CREATE (n:Person {name: 'Alice', age: 30}) RETURN n");
foreach (var row in result)
{
    Console.WriteLine(row.GetString("n.name"));
}

tx.Commit();
// or let Dispose() auto-abort if not committed

Query Results

QueryResult is a forward-only cursor. Access columns and rows:

using var result = tx.Query("MATCH (n:Person) RETURN n.name, n.age");

// Column metadata
foreach (var col in result.Columns)
    Console.WriteLine($"{col.Index}: {col.Name}");

// Iterate rows
foreach (var row in result)
{
    if (!row.IsNull(0))
    {
        string name = row.GetString("n.name");
        long age = row.GetInt64("n.age");
    }
}

// Or materialize all rows
var rows = result.ToList();

Row Access Methods

MethodReturn TypeDescription
GetString(int col)string?String value by column index
GetString(string name)string?String value by column name
GetInt64(int col)longInteger value by column index
GetInt64(string name)longInteger value by column name
GetDouble(int col)doubleFloat value by column index
GetDouble(string name)doubleFloat value by column name
GetBool(int col)boolBoolean value by column index
GetBool(string name)boolBoolean value by column name
GetValue(int col)object?Boxed typed value
IsNull(int col)boolCheck if value is null
GetTypeName(int col)stringType name (INTEGER, FLOAT, STRING, NODE, EDGE, PATH, etc.)
Snapshot()RowCreate a managed copy valid beyond cursor lifetime

Bulk Loading

For high-throughput imports, use BulkWriter. It bypasses MVCC for maximum write speed.

using var bulk = db.BeginBulkWrite();

// Create nodes (returns node ID)
long alice = bulk.CreateNode(
    new[] { "Person" },
    new[] { "name", "age" },
    new[] { "Alice", "30" });  // values are auto-type-inferred

long bob = bulk.CreateNode(
    new[] { "Person" },
    new[] { "name", "age" },
    new[] { "Bob", "25" });

// Create edges
bulk.CreateEdge(alice, bob, "KNOWS",
    new[] { "since" },
    new[] { "2024" });

// Create indexes
bulk.CreateIndex("idx_person_name", "Person", "name");
bulk.CreateEdgeIndex("idx_knows", "KNOWS");

bulk.Commit();

BulkWriter Methods

MethodDescription
CreateNode(labels, propKeys, propValues)Create a node, returns node ID
CreateEdge(source, target, type, propKeys, propValues)Create a relationship, returns edge ID
CreateIndex(name, label, property)Create a node property index
CreateEdgeIndex(name, edgeType, property)Create an edge property index
CreateEdgeIndex(name, edgeType)Create a type-only edge index
DropEdgeIndex(name)Drop an edge index
Commit()Finalize and flush to disk
Abort()Discard without flushing

Error Handling

try
{
    tx.Query("INVALID CYPHER");
}
catch (TraverseException ex)
{
    Console.WriteLine(ex.ErrorCode); // TvErrorCode.Syntax
    Console.WriteLine(ex.Message);
}

Error Codes

CodeDescription
IoFile I/O error
CorruptDatabase file corruption detected
LockedDatabase file is locked by another process
SyntaxCypher syntax error
TypeType mismatch
SemanticSemantic query error
GraphGraph constraint violation
TransactionTransaction conflict or abort
InvalidArgInvalid argument
InternalInternal engine error
ResourceExhaustedMemory or file size limit exceeded