zeta4g_driver/
lib.rs

1//! # Zeta4G Driver
2//!
3//! A Rust driver for [Zeta4G](https://github.com/zeta9044/zeta4g) graph database
4//! with full Bolt protocol support.
5//!
6//! ## Features
7//!
8//! - **Bolt Protocol 5.x** - Full implementation of the Bolt protocol for efficient communication
9//! - **Async/Await** - Built on Tokio for high-performance async operations
10//! - **Connection Pooling** - Automatic connection management with configurable pool sizes
11//! - **Transactions** - Full ACID transaction support with explicit control
12//! - **Type Safety** - Strongly typed values with automatic conversion
13//!
14//! ## Quick Start
15//!
16//! Add to your `Cargo.toml`:
17//!
18//! ```toml
19//! [dependencies]
20//! zeta4g-driver = "0.1"
21//! tokio = { version = "1", features = ["full"] }
22//! ```
23//!
24//! ## Basic Usage
25//!
26//! ```rust,no_run
27//! use zeta4g_driver::{Driver, AuthToken, SessionConfig, Value};
28//! use std::collections::HashMap;
29//!
30//! #[tokio::main]
31//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
32//!     // Create driver
33//!     let driver = Driver::new(
34//!         "bolt://localhost:7687",
35//!         AuthToken::basic("zeta4g", "password"),
36//!     )?;
37//!
38//!     // Create session
39//!     let session_config = SessionConfig::builder()
40//!         .with_database("zeta4g")
41//!         .with_write_access()
42//!         .build();
43//!     let session = driver.session(session_config)?;
44//!
45//!     // Run query with parameters
46//!     let mut params = HashMap::new();
47//!     params.insert("name".to_string(), Value::String("Alice".to_string()));
48//!
49//!     let result = session.run(
50//!         "CREATE (n:Person {name: $name}) RETURN n",
51//!         Some(params),
52//!     ).await?;
53//!
54//!     // Iterate results
55//!     for record in result {
56//!         println!("{:?}", record);
57//!     }
58//!
59//!     // Clean up
60//!     session.close().await?;
61//!     driver.close().await?;
62//!
63//!     Ok(())
64//! }
65//! ```
66//!
67//! ## Transactions
68//!
69//! For operations requiring atomicity, use explicit transactions:
70//!
71//! ```rust,no_run
72//! # use zeta4g_driver::{Driver, AuthToken, SessionConfig};
73//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
74//! # let driver = Driver::new("bolt://localhost:7687", AuthToken::basic("u", "p"))?;
75//! # let session = driver.session(SessionConfig::default())?;
76//! // Begin transaction
77//! let mut tx = session.begin_transaction(None).await?;
78//!
79//! // Execute queries
80//! tx.run("CREATE (n:Node {id: 1})", None).await?;
81//! tx.run("CREATE (n:Node {id: 2})", None).await?;
82//!
83//! // Commit (or rollback on error)
84//! tx.commit().await?;
85//! # Ok(())
86//! # }
87//! ```
88//!
89//! ## Transaction Functions
90//!
91//! For automatic retry on transient errors:
92//!
93//! ```rust,no_run
94//! # use zeta4g_driver::{Driver, AuthToken, SessionConfig, Value};
95//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
96//! # let driver = Driver::new("bolt://localhost:7687", AuthToken::basic("u", "p"))?;
97//! # let session = driver.session(SessionConfig::default())?;
98//! let result = session.write_transaction(|mut tx| async move {
99//!     tx.run("CREATE (n:Node) RETURN n", None).await?;
100//!     tx.commit().await?;
101//!     Ok(42)
102//! }).await?;
103//! # Ok(())
104//! # }
105//! ```
106//!
107//! ## Authentication
108//!
109//! Several authentication methods are supported:
110//!
111//! ```rust
112//! use zeta4g_driver::AuthToken;
113//!
114//! // Basic authentication
115//! let auth = AuthToken::basic("username", "password");
116//!
117//! // Bearer token
118//! let auth = AuthToken::bearer("my-token");
119//!
120//! // No authentication
121//! let auth = AuthToken::none();
122//! ```
123//!
124//! ## Value Types
125//!
126//! The driver provides type-safe value handling:
127//!
128//! ```rust
129//! use zeta4g_driver::Value;
130//!
131//! // Supported types
132//! let null = Value::Null;
133//! let boolean = Value::Boolean(true);
134//! let integer = Value::Integer(42);
135//! let float = Value::Float(3.14);
136//! let string = Value::String("hello".to_string());
137//! let list = Value::List(vec![Value::Integer(1), Value::Integer(2)]);
138//! ```
139//!
140//! ## Configuration
141//!
142//! Customize driver behavior with [`DriverConfig`]:
143//!
144//! ```rust
145//! use zeta4g_driver::{DriverConfig, AuthToken};
146//! use std::time::Duration;
147//!
148//! let config = DriverConfig::builder("bolt://localhost:7687", AuthToken::basic("u", "p"))
149//!     .unwrap()
150//!     .with_max_connection_pool_size(50)
151//!     .with_connection_timeout(Duration::from_secs(10))
152//!     .with_fetch_size(500)
153//!     .build();
154//! ```
155//!
156//! ## Error Handling
157//!
158//! All operations return [`DriverResult`] for consistent error handling:
159//!
160//! ```rust,no_run
161//! # use zeta4g_driver::{Driver, AuthToken, DriverError};
162//! # fn example() -> Result<(), Box<dyn std::error::Error>> {
163//! let driver = Driver::new("bolt://localhost:7687", AuthToken::basic("u", "p"));
164//!
165//! match driver {
166//!     Ok(d) => println!("Connected!"),
167//!     Err(DriverError::Connection(msg)) => eprintln!("Connection failed: {}", msg),
168//!     Err(e) => eprintln!("Error: {}", e),
169//! }
170//! # Ok(())
171//! # }
172//! ```
173//!
174//! ## Modules
175//!
176//! - [`driver`] - Core driver, session, and transaction types
177//! - [`bolt`] - Low-level Bolt protocol implementation
178//!
179
180#![cfg_attr(docsrs, feature(doc_cfg))]
181#![warn(missing_docs)]
182#![warn(rustdoc::missing_crate_level_docs)]
183
184pub mod bolt;
185pub mod driver;
186
187// Re-exports for convenience
188pub use driver::{
189    Driver, DriverConfig, DriverConfigBuilder, AuthToken, TrustStrategy,
190    Session, SessionConfig, SessionConfigBuilder,
191    Transaction, TransactionConfig,
192    Record, Value,
193    DriverError, DriverResult,
194    AccessMode, Bookmark,
195    Query, QueryResult, ResultSummary,
196    ServerAddress, ServerInfo, DriverMetrics,
197};
198
199pub use bolt::{
200    BoltError, BoltVersion,
201    PackStreamValue,
202};
203
204/// Config alias for convenience
205pub type Config = DriverConfig;