pub struct NexusClient { /* private fields */ }Expand description
Nexus client — transport-agnostic handle to a running server.
Implementations§
Source§impl NexusClient
impl NexusClient
Sourcepub async fn batch_create_nodes(
&self,
nodes: Vec<BatchNode>,
) -> Result<BatchCreateNodesResponse>
pub async fn batch_create_nodes( &self, nodes: Vec<BatchNode>, ) -> Result<BatchCreateNodesResponse>
Batch create multiple nodes
§Arguments
nodes- Vector of batch node definitions
§Example
let mut nodes = Vec::new();
for i in 0..10 {
let mut properties = HashMap::new();
properties.insert("name".to_string(), Value::String(format!("Node{}", i)));
nodes.push(nexus_sdk::BatchNode {
labels: vec!["Person".to_string()],
properties,
});
}
let response = client.batch_create_nodes(nodes).await?;
tracing::info!("Created {} nodes", response.node_ids.len());Sourcepub async fn batch_create_relationships(
&self,
relationships: Vec<BatchRelationship>,
) -> Result<BatchCreateRelationshipsResponse>
pub async fn batch_create_relationships( &self, relationships: Vec<BatchRelationship>, ) -> Result<BatchCreateRelationshipsResponse>
Batch create multiple relationships
§Arguments
relationships- Vector of batch relationship definitions
§Example
let mut relationships = Vec::new();
for i in 0..5 {
relationships.push(nexus_sdk::BatchRelationship {
source_id: i,
target_id: i + 1,
rel_type: "KNOWS".to_string(),
properties: HashMap::new(),
});
}
let response = client.batch_create_relationships(relationships).await?;
tracing::info!("Created {} relationships", response.rel_ids.len());Source§impl NexusClient
impl NexusClient
Sourcepub fn endpoint_description(&self) -> String
pub fn endpoint_description(&self) -> String
Describe the active transport ("nexus://host:15475 (RPC)").
Useful for tracing and --verbose-style diagnostics in
applications wrapping the SDK.
Sourcepub fn is_rpc(&self) -> bool
pub fn is_rpc(&self) -> bool
True when the active transport uses the native binary RPC wire format.
Sourcepub fn new(base_url: &str) -> Result<Self>
pub fn new(base_url: &str) -> Result<Self>
Create a client with default configuration against base_url.
base_url may use nexus://, http://, https://, or a bare
host:port (defaults to RPC). Loading a nexus:// URL picks
the native binary RPC transport; any other scheme uses HTTP.
§Example
use nexus_sdk::NexusClient;
// Binary RPC (fastest path)
let rpc = NexusClient::new("nexus://localhost:15475")?;
// Legacy HTTP
let http = NexusClient::new("http://localhost:15474")?;Sourcepub fn with_api_key(base_url: &str, api_key: &str) -> Result<Self>
pub fn with_api_key(base_url: &str, api_key: &str) -> Result<Self>
Create a client with API key authentication.
Sourcepub fn with_credentials(
base_url: &str,
username: &str,
password: &str,
) -> Result<Self>
pub fn with_credentials( base_url: &str, username: &str, password: &str, ) -> Result<Self>
Create a client with username/password authentication.
Sourcepub fn with_config(config: ClientConfig) -> Result<Self>
pub fn with_config(config: ClientConfig) -> Result<Self>
Create a client from a custom ClientConfig.
Transport precedence (strongest → weakest):
- URL scheme in
config.base_url(nexus://forces RPC,http[s]://forces HTTP). NEXUS_SDK_TRANSPORTenv var.config.transportfield.- Default:
TransportMode::NexusRpc.
Sourcepub async fn execute_cypher(
&self,
query: &str,
parameters: Option<HashMap<String, Value>>,
) -> Result<QueryResult>
pub async fn execute_cypher( &self, query: &str, parameters: Option<HashMap<String, Value>>, ) -> Result<QueryResult>
Execute a Cypher query.
Sourcepub async fn get_stats(&self) -> Result<DatabaseStats>
pub async fn get_stats(&self) -> Result<DatabaseStats>
Get database statistics.
Sourcepub async fn health_check(&self) -> Result<bool>
pub async fn health_check(&self) -> Result<bool>
Health check — returns true if the server responds
successfully on the active transport.
Sourcepub async fn list_databases(&self) -> Result<ListDatabasesResponse>
pub async fn list_databases(&self) -> Result<ListDatabasesResponse>
List all databases (REST).
Sourcepub async fn create_database(
&self,
name: &str,
) -> Result<CreateDatabaseResponse>
pub async fn create_database( &self, name: &str, ) -> Result<CreateDatabaseResponse>
Create a new database (REST).
Sourcepub async fn get_database(&self, name: &str) -> Result<DatabaseInfo>
pub async fn get_database(&self, name: &str) -> Result<DatabaseInfo>
Get database information (REST).
Sourcepub async fn drop_database(&self, name: &str) -> Result<DropDatabaseResponse>
pub async fn drop_database(&self, name: &str) -> Result<DropDatabaseResponse>
Drop a database (REST).
Sourcepub async fn get_current_database(&self) -> Result<String>
pub async fn get_current_database(&self) -> Result<String>
Get the current session database (REST).
Sourcepub async fn switch_database(
&self,
name: &str,
) -> Result<SwitchDatabaseResponse>
pub async fn switch_database( &self, name: &str, ) -> Result<SwitchDatabaseResponse>
Switch to a different database (REST).
Source§impl NexusClient
impl NexusClient
Sourcepub async fn create_node(
&self,
labels: Vec<String>,
properties: HashMap<String, Value>,
) -> Result<CreateNodeResponse>
pub async fn create_node( &self, labels: Vec<String>, properties: HashMap<String, Value>, ) -> Result<CreateNodeResponse>
Create a new node
§Arguments
labels- Node labelsproperties- Node properties
§Example
let mut properties = HashMap::new();
properties.insert("name".to_string(), Value::String("Alice".to_string()));
let response = client.create_node(vec!["Person".to_string()], properties).await?;
tracing::info!("Created node with ID: {}", response.node_id);Sourcepub async fn create_node_with_external_id(
&self,
labels: Vec<String>,
properties: HashMap<String, Value>,
external_id: impl Into<String>,
conflict_policy: Option<&str>,
) -> Result<CreateNodeResponse>
pub async fn create_node_with_external_id( &self, labels: Vec<String>, properties: HashMap<String, Value>, external_id: impl Into<String>, conflict_policy: Option<&str>, ) -> Result<CreateNodeResponse>
Create a node with a caller-supplied external id.
external_id accepts the prefixed string form
(sha256:<hex>, blake3:<hex>, sha512:<hex>, uuid:<canonical>,
str:<utf8>, bytes:<hex>). conflict_policy is one of
"error" (default), "match", or "replace".
Phase9 §5.5.
Sourcepub async fn get_node_by_external_id(
&self,
external_id: impl AsRef<str>,
) -> Result<GetNodeResponse>
pub async fn get_node_by_external_id( &self, external_id: impl AsRef<str>, ) -> Result<GetNodeResponse>
Resolve a node by external id (returns node: None when absent).
Phase9 §5.5.
Sourcepub async fn get_node(&self, node_id: u64) -> Result<GetNodeResponse>
pub async fn get_node(&self, node_id: u64) -> Result<GetNodeResponse>
Sourcepub async fn update_node(
&self,
node_id: u64,
properties: HashMap<String, Value>,
) -> Result<UpdateNodeResponse>
pub async fn update_node( &self, node_id: u64, properties: HashMap<String, Value>, ) -> Result<UpdateNodeResponse>
Update an existing node
§Arguments
node_id- ID of the node to updateproperties- New properties for the node
§Example
let mut properties = HashMap::new();
properties.insert("name".to_string(), Value::String("Bob".to_string()));
let response = client.update_node(0, properties).await?; // Replace 0 with an actual node ID
tracing::info!("Update node result: {}", response.message);Sourcepub async fn delete_node(&self, node_id: u64) -> Result<DeleteNodeResponse>
pub async fn delete_node(&self, node_id: u64) -> Result<DeleteNodeResponse>
Sourcepub async fn create_relationship(
&self,
source_id: u64,
target_id: u64,
rel_type: String,
properties: HashMap<String, Value>,
) -> Result<CreateRelResponse>
pub async fn create_relationship( &self, source_id: u64, target_id: u64, rel_type: String, properties: HashMap<String, Value>, ) -> Result<CreateRelResponse>
Create a new relationship
§Arguments
source_id- ID of the source nodetarget_id- ID of the target noderel_type- Type of the relationshipproperties- Optional relationship properties
§Example
let mut properties = HashMap::new();
properties.insert("weight".to_string(), Value::Float(1.5));
let response = client.create_relationship(1, 2, "KNOWS".to_string(), properties).await?;
tracing::info!("Created relationship with ID: {}", response.rel_id);Sourcepub async fn update_relationship(
&self,
rel_id: u64,
properties: HashMap<String, Value>,
) -> Result<UpdateRelResponse>
pub async fn update_relationship( &self, rel_id: u64, properties: HashMap<String, Value>, ) -> Result<UpdateRelResponse>
Update an existing relationship using Cypher
§Arguments
rel_id- ID of the relationship to updateproperties- New properties for the relationship
§Example
let mut properties = HashMap::new();
properties.insert("weight".to_string(), Value::Float(2.0));
let response = client.update_relationship(1, properties).await?;
tracing::info!("Update relationship result: {}", response.message);Sourcepub async fn delete_relationship(
&self,
rel_id: u64,
) -> Result<DeleteRelResponse>
pub async fn delete_relationship( &self, rel_id: u64, ) -> Result<DeleteRelResponse>
Source§impl NexusClient
impl NexusClient
Sourcepub async fn get_query_statistics(&self) -> Result<QueryStatisticsResponse>
pub async fn get_query_statistics(&self) -> Result<QueryStatisticsResponse>
Get query statistics
§Example
let stats = client.get_query_statistics().await?;
tracing::info!("Total queries: {}", stats.statistics.total_queries);
tracing::info!("Average execution time: {}ms", stats.statistics.average_execution_time_ms);Sourcepub async fn get_slow_queries(&self) -> Result<SlowQueriesResponse>
pub async fn get_slow_queries(&self) -> Result<SlowQueriesResponse>
Get slow queries
§Example
let slow_queries = client.get_slow_queries().await?;
tracing::info!("Found {} slow queries", slow_queries.count);
for query in slow_queries.queries {
tracing::info!("Query: {} ({}ms)", query.query, query.execution_time_ms);
}Sourcepub async fn get_plan_cache_statistics(
&self,
) -> Result<PlanCacheStatisticsResponse>
pub async fn get_plan_cache_statistics( &self, ) -> Result<PlanCacheStatisticsResponse>
Get plan cache statistics
§Example
let cache_stats = client.get_plan_cache_statistics().await?;
tracing::info!("Cached plans: {}", cache_stats.cached_plans);
tracing::info!("Hit rate: {:.2}%", cache_stats.hit_rate * 100.0);Sourcepub async fn clear_plan_cache(&self) -> Result<Value>
pub async fn clear_plan_cache(&self) -> Result<Value>
Clear plan cache
§Example
let response = client.clear_plan_cache().await?;
tracing::info!("Plan cache cleared: {:?}", response);Source§impl NexusClient
impl NexusClient
Sourcepub async fn create_label(&self, name: String) -> Result<CreateLabelResponse>
pub async fn create_label(&self, name: String) -> Result<CreateLabelResponse>
Sourcepub async fn list_labels(&self) -> Result<ListLabelsResponse>
pub async fn list_labels(&self) -> Result<ListLabelsResponse>
List all labels
§Example
let response = client.list_labels().await?;
tracing::info!("Labels: {:?}", response.labels);Sourcepub async fn create_rel_type(
&self,
name: String,
) -> Result<CreateRelTypeResponse>
pub async fn create_rel_type( &self, name: String, ) -> Result<CreateRelTypeResponse>
Sourcepub async fn list_rel_types(&self) -> Result<ListRelTypesResponse>
pub async fn list_rel_types(&self) -> Result<ListRelTypesResponse>
List all relationship types
§Example
let response = client.list_rel_types().await?;
tracing::info!("Relationship types: {:?}", response.types);Source§impl NexusClient
impl NexusClient
Sourcepub async fn begin_transaction(&self) -> Result<Transaction>
pub async fn begin_transaction(&self) -> Result<Transaction>
Begin a new transaction
§Example
let mut tx: Transaction = client.begin_transaction().await?;
// Perform operations...
tx.commit().await?;Trait Implementations§
Source§impl Clone for NexusClient
impl Clone for NexusClient
Source§fn clone(&self) -> NexusClient
fn clone(&self) -> NexusClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more