Rust SDK quick reference for agents
Baseline: crate ekodb_client 0.37.0. Install with cargo add ekodb_client@=0.37.0 and use the application's Tokio runtime. Checked against the client, record types and CRUD example.
Runnable Examples (Check Before Guessing)
Before writing SDK code, consult the matching runnable example below for exact imports, method signatures and error handling. These links follow the SDK's main branch; compare them with the version installed in your application. Follow the language directory's run instructions and use a disposable deployment when executing examples that write data.
| Task | Runnable example |
|---|---|
| CRUD | examples/client_simple_crud.rs |
| QueryBuilder | examples/client_query_builder.rs |
| Joins | examples/client_joins.rs |
| Schemas | examples/client_schema.rs |
| TTL | examples/client_document_ttl.rs |
| Transactions | examples/client_transactions.rs |
| Stored Functions | examples/client_functions.rs |
| Concurrency / Locks / RateLimits | examples/client_concurrency_stages.rs |
| Chat / RAG | examples/client_chat_basic.rs, examples/rag_conversation_system.rs |
| Search | examples/client_search.rs |
| WebSockets | examples/client_websocket_subscribe.rs |
| Admin / Permissions | examples/client_admin.rs |
Initialize and query
use ekodb_client::{Client, QueryBuilder, Record};
async fn list_active(
base_url: &str,
api_key: &str,
) -> Result<Vec<Record>, Box<dyn std::error::Error>> {
let client = Client::builder().base_url(base_url).api_key(api_key).build()?;
let query = QueryBuilder::new().eq("active", true).limit(25).build();
Ok(client.find("agent_tasks", query, None).await?)
}
The application supplies runtime credentials. The client exchanges and refreshes tokens. Builder build() is synchronous; database operations are async. The third find argument is an optional ripple flag, not a query options object.
Method map
| Task | Call shape (await the result) |
|---|---|
| Insert | client.insert(collection, record, None) |
| Find | client.find(collection, query, None) |
| Point read | client.find_by_id(collection, id, None) |
| Merge update | client.update(collection, id, fields, None) |
| Delete | client.delete(collection, id, None) |
| Read schema | client.get_schema(collection) |
| Save / call a function | client.save_user_function(definition) / client.call_function(id_or_label, params) |
| Transactions | client.begin_transaction(None), client.commit_transaction(id), client.rollback_transaction(id) |
The explicit None arguments matter: Rust does not omit optional parameters. The last insert/update arguments are Option<InsertOptions> / Option<UpdateOptions>; find/point-read's last argument is Option<bool>. Use the separate find_in_transaction / find_by_id_in_transaction methods for transactional reads, and write option structs carrying transaction_id for staged writes.
Values, TTL and failures
- Build data with
Record::new()andrecord.insert(name, value). UseFieldType::array, theFieldType::Objectvariant or native JSON conversion for nested data; do not serialize an object into a string. - Records contain
FieldType.record.get_string("id")andget_bool("active")handle plain values and typed wrappers. Match the enum or use the appropriate extraction helper for other types. Record::with_ttl("5m")carries the TTL directive. Include it on the update only to set a new expiry; omitting it preserves the stored expiry.- A function call returns
FunctionResult; readresult.records[0]for aCountresult, then its named output field.Countreplaces the input rows. - Return
Resulterrors to the caller.Error::Transaction { code, message, .. }preserves transaction status and displaysTransaction error (409)for a conflict response. Commit is not automatically retried; distinguish a concurrency conflict from legacyApply(...)failures before starting a new transaction.
See canonical formats, the error type and versioned Rust examples.