Native Driver Protocol

SoliDB provides a high-performance native binary protocol as an alternative to the HTTP REST API. The native driver offers lower latency and higher throughput.

Port: The native driver uses the same port as the HTTP API (default: 6745) via protocol multiplexing. The server automatically detects the protocol based on the connection's magic header.

Overview

The native driver protocol provides:

  • Binary Protocol: Uses MessagePack for efficient serialization
  • Length-Prefixed Framing: Reliable message boundary detection
  • Full Feature Parity: Supports all database operations including SDBQL queries
  • Connection Multiplexing: Shares port with HTTP API
  • Transaction Support: Full ACID transaction support

Wire Protocol

Connection Handshake

When connecting, the client must send the magic header:

solidb-drv-v1\0  (14 bytes)

Message Format

Each message consists of:

  1. Length: 4 bytes, big-endian unsigned integer
  2. Payload: MessagePack-encoded command or response
+------------------+-------------------------+
| Length (4 bytes) | MessagePack Payload     |
+------------------+-------------------------+

Maximum Message Size

The maximum message size is 16 MB (16,777,216 bytes).

Commands

Utility Commands

CommandDescriptionFields
pingPing the serverNone
authAuthenticatedatabase, username, password

Database Operations

CommandDescriptionFields
list_databasesList all databasesNone
create_databaseCreate a databasename
delete_databaseDelete a databasename

Collection Operations

CommandDescriptionFields
list_collectionsList collectionsdatabase
create_collectionCreate collectiondatabase, name, collection_type
delete_collectionDelete collectiondatabase, name
collection_statsGet collection statsdatabase, name

Document Operations

CommandDescriptionFields
getGet document by keydatabase, collection, key
insertInsert documentdatabase, collection, key, document
updateUpdate documentdatabase, collection, key, document, merge
deleteDelete documentdatabase, collection, key
listList documentsdatabase, collection, limit, offset

Query Operations

CommandDescriptionFields
queryExecute SDBQL querydatabase, sdbql, bind_vars
explainExplain query plandatabase, sdbql, bind_vars

Transaction Operations

CommandDescriptionFields
begin_transactionStart transactiondatabase, isolation_level
commit_transactionCommit transactiontx_id
rollback_transactionRollback transactiontx_id

Bulk Operations

CommandDescriptionFields
batchExecute multiple commandscommands
bulk_insertInsert multiple documentsdatabase, collection, documents

Rust Client Library

SoliDB includes a native Rust client library for easy integration:

Installation

Add the library to your Cargo.toml:

[dependencies]
solidb = { version = "0.1.0" }

Basic Usage

Import the client and connect to your SoliDB instance:

use solidb::driver::SoliDBClient;
use serde_json::json;

#[tokio::main]
async fn main() -> Result<(), Box> {
    // Connect to SoliDB
    let mut client = SoliDBClient::connect("localhost:6745").await?;
    
    // Authenticate (optional)
    client.auth("mydb", "admin", "password").await?;
    
    // Insert a document
    let doc = client.insert("mydb", "users", None, json!({
        "name": "Alice",
        "email": "[email protected]"
    })).await?;
    
    println!("Inserted: {:?}", doc);
    
    // Query using SDBQL
    let results = client.query("mydb", "FOR u IN users RETURN u", None).await?;
    println!("Results: {:?}", results);
    
    Ok(())
}

Transactions

use solidb_client::protocol::IsolationLevel;

// Begin transaction
let tx_id = client.begin_transaction("mydb", Some(IsolationLevel::ReadCommitted)).await?;

// Operations are automatically associated with the transaction
client.insert("mydb", "users", None, json!({"name": "Bob"})).await?;

// Commit
client.commit().await?;

// Or rollback
// client.rollback().await?;

Performance

The native driver offers significant performance improvements over HTTP:

  • ~50% lower latency due to binary protocol and no HTTP overhead
  • ~30% smaller payload sizes with MessagePack vs JSON
  • Persistent connections eliminate connection setup overhead

Error Handling

Errors are returned with type-specific error codes:

connection_error Network or connection issues
auth_error Authentication failed
database_error Database operation failed
transaction_error Transaction operation failed
protocol_error Protocol violation
message_too_large Message exceeds 16MB limit