Expand description
§Zeta4G Driver
A Rust driver for Zeta4G graph database with full Bolt protocol support.
§Features
- Bolt Protocol 5.x - Full implementation of the Bolt protocol for efficient communication
- Async/Await - Built on Tokio for high-performance async operations
- Connection Pooling - Automatic connection management with configurable pool sizes
- Transactions - Full ACID transaction support with explicit control
- Type Safety - Strongly typed values with automatic conversion
§Quick Start
Add to your Cargo.toml:
[dependencies]
zeta4g-driver = "0.1"
tokio = { version = "1", features = ["full"] }§Basic Usage
use zeta4g_driver::{Driver, AuthToken, SessionConfig, Value};
use std::collections::HashMap;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create driver
let driver = Driver::new(
"bolt://localhost:7687",
AuthToken::basic("zeta4g", "password"),
)?;
// Create session
let session_config = SessionConfig::builder()
.with_database("zeta4g")
.with_write_access()
.build();
let session = driver.session(session_config)?;
// Run query with parameters
let mut params = HashMap::new();
params.insert("name".to_string(), Value::String("Alice".to_string()));
let result = session.run(
"CREATE (n:Person {name: $name}) RETURN n",
Some(params),
).await?;
// Iterate results
for record in result {
println!("{:?}", record);
}
// Clean up
session.close().await?;
driver.close().await?;
Ok(())
}§Transactions
For operations requiring atomicity, use explicit transactions:
// Begin transaction
let mut tx = session.begin_transaction(None).await?;
// Execute queries
tx.run("CREATE (n:Node {id: 1})", None).await?;
tx.run("CREATE (n:Node {id: 2})", None).await?;
// Commit (or rollback on error)
tx.commit().await?;§Transaction Functions
For automatic retry on transient errors:
let result = session.write_transaction(|mut tx| async move {
tx.run("CREATE (n:Node) RETURN n", None).await?;
tx.commit().await?;
Ok(42)
}).await?;§Authentication
Several authentication methods are supported:
use zeta4g_driver::AuthToken;
// Basic authentication
let auth = AuthToken::basic("username", "password");
// Bearer token
let auth = AuthToken::bearer("my-token");
// No authentication
let auth = AuthToken::none();§Value Types
The driver provides type-safe value handling:
use zeta4g_driver::Value;
// Supported types
let null = Value::Null;
let boolean = Value::Boolean(true);
let integer = Value::Integer(42);
let float = Value::Float(3.14);
let string = Value::String("hello".to_string());
let list = Value::List(vec![Value::Integer(1), Value::Integer(2)]);§Configuration
Customize driver behavior with DriverConfig:
use zeta4g_driver::{DriverConfig, AuthToken};
use std::time::Duration;
let config = DriverConfig::builder("bolt://localhost:7687", AuthToken::basic("u", "p"))
.unwrap()
.with_max_connection_pool_size(50)
.with_connection_timeout(Duration::from_secs(10))
.with_fetch_size(500)
.build();§Error Handling
All operations return DriverResult for consistent error handling:
let driver = Driver::new("bolt://localhost:7687", AuthToken::basic("u", "p"));
match driver {
Ok(d) => println!("Connected!"),
Err(DriverError::Connection(msg)) => eprintln!("Connection failed: {}", msg),
Err(e) => eprintln!("Error: {}", e),
}§Modules
Re-exports§
pub use driver::Driver;pub use driver::DriverConfig;pub use driver::DriverConfigBuilder;pub use driver::AuthToken;pub use driver::TrustStrategy;pub use driver::Session;pub use driver::SessionConfig;pub use driver::SessionConfigBuilder;pub use driver::Transaction;pub use driver::TransactionConfig;pub use driver::Record;pub use driver::Value;pub use driver::DriverError;pub use driver::DriverResult;pub use driver::AccessMode;pub use driver::Bookmark;pub use driver::Query;pub use driver::QueryResult;pub use driver::ResultSummary;pub use driver::ServerAddress;pub use driver::ServerInfo;pub use driver::DriverMetrics;pub use bolt::BoltError;pub use bolt::BoltVersion;pub use bolt::PackStreamValue;
Modules§
Macros§
- params
- 파라미터 맵 생성 매크로
Type Aliases§
- Config
- Config alias for convenience