Expand description
Blocking Rust client for TriCoreDB: SQL, documents, cache, vectors, graphs and LLM context over one connection.
It speaks TriCoreDB’s own tricore protocol directly over TCP, optionally
inside TLS. There is no async runtime: calls block, and a Pool is what
serves concurrent work.
use tricoredb::{params, Client, Options};
let mut db = Client::connect(&Options::new("127.0.0.1", 8427).user("admin").secret("pw"))?;
db.execute("CREATE TABLE IF NOT EXISTS users (id INT PRIMARY KEY, name TEXT)")?;
db.execute_params("INSERT INTO users VALUES (?, ?)", ¶ms![1, "O'Hara"])?;
let rows = db.query_params("SELECT name FROM users WHERE id = ?", ¶ms![1])?;
assert_eq!(rows.get(0, "name"), Some("O'Hara"));
db.cache_set("sessions", "u1", b"token")?;
let token = db.cache_get("sessions", "u1")?; // None on a miss§One connection, one request at a time
The protocol is a single request/response stream, so every call takes
&mut self. Sharing a Client between threads does not compile, which is
the frame interleaving this design rules out rather than documents. Use a
Pool when you need several requests at once.
§Values are bound by the server
Client::execute_params and Client::query_params send the values
beside the statement; the server substitutes them at positions its grammar
has already fixed, so a value can never be read as SQL. When a server does
not offer that capability, those calls fail before sending anything instead
of quietly building the statement text here — see ErrorKind::FeatureNotGranted.
§Errors
Every fallible call returns Error. Branch on Error::kind and
Error::code, never on the message text. A write refused by a follower in
a cluster has Error::is_redirect true and, when the cluster knows one,
Error::leader_hint. By default the client follows it itself: see
Options::follow_leader.
§Features
tls(default): TLS and mutual TLS throughTlsOptions, built on rustls. Turn it off for a build with no cryptography dependencies.
Macros§
- params
- Build a
Vec<Param>from heterogeneous values.
Structs§
- Accumulator
Op - One reduction inside a group stage.
- Aggregate
Stage - One stage of an aggregation pipeline.
- Bulk
Write Result - What
Client::document_bulk_writeapplied. - Cache
Command - One cache operation inside
Client::cache_pipeline,Client::cache_transactionor a script. - Cache
Entry - One key and its value, as
Client::cache_msetandClient::cache_warmtake them. - Cache
Eviction Stats - The evictor in
CacheStats. - Cache
KeyInfo - One live key in a namespace.
- Cache
Lock - The answer to
Client::cache_lock_acquire. - Cache
Lock Renewal - The answer to
Client::cache_lock_renew. - Cache
Memory Stats - The memory budget in
CacheStats. - Cache
Pair - One
(field, value)entry of a hash or a stream. - Cache
Stats - What one node’s cache is doing. Node-wide, not per database.
- Centrality
Options - What
Client::graph_centralityshould compute over. - Channel
Message - One message read by
Client::cache_poll. - Client
- One session with a TriCoreDB server.
- Collection
Options - Rules a collection applies to every document written into it.
- Community
Options - What
Client::graph_communitiesshould consider. - Compare
AndSwap - The answer to
Client::cache_compare_and_swap. - Component
Options - What
Client::graph_connected_componentsshould consider. - Document
Commit - What
Client::document_commit_transactionlanded. - Document
Filter - A query predicate.
- Document
Index - One secondary index on a collection.
- Document
Plan - How a find ran, as
Client::document_explainreports it. - Document
Schema - A document shape: required paths, per-path rules, and whether top-level fields the schema does not name are allowed.
- Document
Stats - What
Client::document_analyzemeasured. - Document
Update - Field changes applied to one document:
setoverwrites the value at a dot path,incadds a number to it. Everysethappens before everyinc. - Embedding
- What
Client::vector_embedproduced. - Error
- Any failure from the transport, the protocol or the server.
- Expire
AtOutcome - What
Client::cache_expire_atdid. - Explain
Options - What
Client::document_explainshould run. The default explains an unbounded, unsorted find. - Field
Rule - What one field may hold. Every rule given must pass.
- Frame
- One decoded frame.
- Fresh
Read - The answer to
Client::cache_get_fresh. - Fused
Hit - One hit of a fused ranking.
- Fused
Search Result - The answer to
Client::vector_search_multi. - Graph
Centrality - The answer to
Client::graph_centrality. - Graph
Communities - The communities of a graph, largest first.
- Graph
Components - The connected components of a graph, largest first.
- Graph
Consistency - The answer to
Client::graph_check_consistency. - Graph
Constraint - One constraint.
- Graph
Counts - How many nodes and edges a batch write or a copy handled.
- Graph
Cycle - One cycle, as the evidence
Client::graph_detect_cyclereturns. - Graph
Cycle Check - The answer to
Client::graph_detect_cycle. - Graph
Edge - One stored edge, directed from one node to another.
- Graph
Edge Input - One edge of
Client::graph_add_many. - Graph
Edge Page - One page of a graph’s edges.
- Graph
Edge Type Schema - One edge type in a
GraphSchema. - Graph
Findings - One class of finding in a
GraphConsistency. - Graph
Found Nodes - The answer to
Client::graph_find_nodes. - Graph
Group - One group of nodes: a connected component, or a community.
- Graph
Index - One node index.
- Graph
Label Schema - One node label, or the unlabelled nodes, in a
GraphSchema. - Graph
Mirror Check - How the resident mirror compares with storage.
- Graph
Neighbor - One edge incident to a node, and the node at its other end.
- Graph
Node - One stored node.
- Graph
Node Input - One node of
Client::graph_add_many. - Graph
Node Page - One page of a graph’s nodes.
- Graph
Node Triangles - One node’s triangles.
- Graph
Page Rank - The answer to
Client::graph_page_rank. - Graph
Path - The outcome of a path search.
- Graph
Path Entry - One path of a
GraphPaths. - Graph
Paths - Several paths between two nodes.
- Graph
Property Schema - One property key seen on a label or an edge type.
- Graph
Removed - What
Client::graph_remove_manydeleted. - Graph
Rows - The result of a Cypher query.
- Graph
Schema - What a graph’s data looks like.
- Graph
Schema Objects - A graph’s indexes and constraints.
- Graph
Score - One node and the score an algorithm gave it.
- Graph
Stats - Counts describing a graph.
- Graph
Subgraph - The part of a graph around some seed nodes.
- Graph
Traversal - The outcome of a bounded breadth-first walk.
- Graph
Triangles - The answer to
Client::graph_triangle_count. - Graph
Visit - One node reached by a traversal.
- Graph
Write Summary - What a Cypher write changed.
- Group
Accumulator - An accumulator and the field it writes into the grouped document.
- Group
Key - How
AggregateStage::groupderives a group key. - Index
Rebuild - What
Client::document_rebuild_indexrebuilt. - KPath
Options - What
Client::graph_k_shortest_pathsshould search. - LlmOptions
- What to include in an export, and what to hide.
- LlmSource
- One read-only source contributing to a context bundle.
- Named
Vector - One named vector declared on a collection.
- Namespace
Limit - A namespace’s limit and what it holds now.
- Neighbor
Options - What
Client::graph_neighborsshould include. The default follows outgoing edges of every label, up to the server’s cap. - Node
Update - What
Client::graph_update_nodeshould change. The default changes nothing. - Options
- What to connect to, and how.
- Page
Rank Options - What
Client::graph_page_rankshould compute. - Path
Options - What
Client::graph_shortest_pathshould search. - Polled
Messages - One page of messages from
Client::cache_poll. - Pool
- A bounded, thread-safe pool of connections.
- Purge
Counts - What
Client::document_purge_expiredremoved. - Recall
Options - What
Client::vector_measure_recallshould sample. EveryNoneleaves the server’s default. - Replace
Options - How
Client::document_replacebehaves. The default refuses a missing document, returns no document and checks no version. - Replace
Result - What
Client::document_replacedid. - Response
- A decoded
RESPONSEframe. - Rows
- A SQL result set: the column names, and each row’s values as the server rendered them.
- Score
Bound - One end of a score range.
- Scored
Member - One member of a sorted set and its score.
- Similarity
Options - What
Client::graph_node_similarityshould compare. - SortKey
- One sort key. After a group stage the addressable fields are
_idand the accumulator outputs, not the original document’s fields. - Sparse
Vector - A sparse vector: parallel lists of term indices and their weights.
- Statement
- One statement of a transaction script, with the values bound to its placeholders.
- Stream
Entry - One entry of a stream.
- Text
Upsert - One text of
Client::vector_upsert_text. - TlsOptions
- How the TLS session is set up.
- Transaction
Result - What the server did with a transaction.
- Traverse
Options - What
Client::graph_traverseshould walk. The default walks outgoing edges of every label to the server’s default depth and node limit. - Trim
Counts - What
Client::cache_ltrimleft behind. - Update
Counts - What
Client::document_update_manychanged. - Vector
Alias - One alias and the collection it names.
- Vector
Collection Info - A collection’s metadata and its live vector count.
- Vector
Collection Summary - One entry of
Client::vector_list_collections. - Vector
Config - A collection’s configuration after
Client::vector_set_collection_config. - Vector
Config Change - What
Client::vector_set_collection_configshould change. ANoneleaves that setting as it is. - Vector
Hit - One search result.
- Vector
Index Rebuild - What
Client::vector_rebuild_indexdid. - Vector
Index Stats - The shape of a collection’s search index.
- Vector
Item - One stored vector and its metadata.
- Vector
Page - One page of
Client::vector_list_vectors. - Vector
Partition - One partition of a collection.
- Vector
Partitions - The partitions of a collection, as
Client::vector_list_partitionsreports them. - Vector
Recall - The recall
Client::vector_measure_recallmeasured. - Vector
Search Options - What a batch or example search should apply beyond its query vectors.
- Vector
Search Result - A search’s hits, and which path answered it.
- Vector
Upsert - One vector of
Client::vector_upsert_many. - Warm
Counts - What
Client::cache_warmdid. - Weighted
Path Options - What
Client::graph_weighted_shortest_pathshould search. - ZAdd
Counts - What
Client::cache_zaddchanged.
Enums§
- AnnIndex
- Which approximate index a search uses.
- BitOp
Kind - The bitwise operation
Client::cache_bit_opapplies across its sources. - BulkOp
- One operation of
Client::document_bulk_write. - Cache
Expiry - What an operation does with a key’s deadline.
- Cache
Reply - What one operation of a pipeline, transaction or script answered.
- Centrality
Measure - The measure
Client::graph_centralitycomputes. - Component
Kind - How
Client::graph_connected_componentsgroups nodes. - Constraint
Kind - The rule a constraint enforces.
- Constraint
Target - What a constraint applies to.
- Error
Kind - What category of failure an
Erroris. - Field
Type - A JSON type a
FieldRulecan demand.Integeris a number with no fractional part. - Filter
Strategy - How a filtered search combines the filter with the index.
- Fresh
State - Which of its four answers
Client::cache_get_freshgave. - Fusion
Method - How
Client::vector_search_multimerges its queries’ rankings. - Graph
Direction - Which edges of a node an operation follows.
- ListEnd
- Which end of a list an element leaves or joins.
- Output
Format - How the server should render an export.
- Param
- One SQL parameter.
- Return
Document - Whether a by-id write hands back the document it touched, and which version of it.
- Score
Metric - The measure a search scores by, when it should differ from the collection’s own metric.
- SetCondition
- When
Client::cache_set_ifis allowed to write. - Similarity
Metric - How
Client::graph_node_similaritycompares neighbour sets. - Tag
- A frame tag as it appears on the wire.
- Vector
Example - One example for
Client::vector_search_by_examples: a stored vector named by id, or a vector given outright. - Vector
Metric - How a collection measures closeness. Fixed when the collection is created.
- Vector
Quantization - How the search index stores vectors in memory.
Constants§
- ALL_
FEATURES - Every capability this build understands, and what
Optionsannounces unlessOptions::featuresnarrows it. - DEFAULT_
DATABASE - The database a request names when none was chosen.
- DEFAULT_
PORT - The port
tricore-serverlistens on unless it was configured otherwise. - FEATURE_
CORRELATION_ ID - The client understands a request-scoped correlation id that the server joins to its access log, audit trail and cancel registry.
- FEATURE_
SERVER_ PARAMS - The server binds
?placeholders to a typed array sent beside the statement, instead of the client rendering values into the SQL text. - FEATURE_
SESSION_ TXN BEGIN, the statements, andCOMMIT/ROLLBACKas separate requests on one connection, with a real rollback boundary between them.- FRAME_
VERSION - The frame header format version this client writes and the highest it reads.
- MAX_
CONTROL_ PAYLOAD - Payload ceiling for every other (control) frame (64 KiB).
- MAX_
DATA_ PAYLOAD - Payload ceiling for
REQUESTandRESPONSEframes (16 MiB). - NOT_
LEADER - The error code a Raft follower attaches when it cannot serve a request.
- OUTCOME_
UNKNOWN - The code of a request a follower handed to the leader and lost the answer to, or one the leader could not confirm in time. It may or may not have been applied, so this client never sends it again.
- VERSION
- This crate’s own version, so an application can report the client it uses.