couchbase v0.0.5
CouchBase
Standalone Crystal client for Couchbase KV and N1QL/SQL++ Query services.
CouchBase currently covers:
- Couchbase endpoint discovery
- KV binary protocol with bucket vbucket-count discovery
- Query HTTP service
Not implemented:
- Search
- Analytics
- Index
- Eventing
- Views
Installation
dependencies:
couchbase:
github: shardscry/couchbase
version: ~> 0.0.5
Run shards install, then require "couchbase" in your application.
See release notes for the complete feature set and limitations.
Migrating From CryBase
Replace:
crybasedependency withcouchbaserequire "crybase"withrequire "couchbase"CryBase::CouchBasewithCouchBase
Shared helpers now live under CouchBase::Connectivity and CouchBase::Interfaces
the version is CouchBase::VERSION.
Index
Small Use Cases
require "couchbase"
kv = CouchBase::KV::Client.from_string(
"couchbase://Administrator:password@127.0.0.1/commerce",
)
kv.scope = "ecommerce_shop"
users = kv.collection("users")
users.set("some-uuid-here", %({"name":"Ada"}))
puts String.new(users.get("some-uuid-here"))
admins = kv.collection("admins")
admins.set("some-uuid-here", %({"name":"Grace"}))
require "couchbase"
client = CouchBase::Query::Client.from_string(
"couchbase://Administrator:password@127.0.0.1/commerce",
)
client.scope = "ecommerce_shop"
rows = client.query(
"SELECT META(u).id AS doc_key, u.name FROM users AS u LIMIT 5",
)
Examples
Each folder in examples/ is a standalone Crystal application with its own shard.yml, locked dependencies, README, and local models. Copy any folder elsewhere and run shards install followed by shards build. Each example's README includes its run command. Examples use the published CouchBase shard and require no shared example files.
| Example | Demonstrates |
|---|---|
| kemal_api | Kemal REST /users, UUID keys, SQL++ pagination, and HTTP/database specs. |
| kv_basics | Raw values and typed JSON documents in collections. |
| kv_expiration | Expiration, touch, and atomic get-and-touch. |
| kv_cluster | KV connection pools and seed failover. |
| cluster_probe | TCP reachability of service endpoints. |
| kv_endpoint_from_cluster | Connecting to a reachable KV endpoint. |
| query_basics | Parameters, typed rows, and row iteration. |
| query_cursor | Query cluster seeds and streaming typed rows without buffering the result. |
| query_prepared | Explicit prepared statements and cached plans. |
| query_mutations | SQL++ INSERT, UPDATE, array changes, UPSERT, and DELETE. |
| query_retry_policy | Retry policy configuration; policy-based retries are not implemented. |
For a local Couchbase server and the HTTP API:
cd examples/kemal_api
docker compose up -d --wait couchbase
docker compose run --rm couchbase-init
shards install
crystal run setup.cr
crystal run src/main.cr
The API listens at http://127.0.0.1:3000. See its README for endpoint examples, configuration, and spec commands. The same database supports the other examples:
cd ../query_basics
shards install
crystal run example.cr
CLI examples accept COUCHBASE_URL (default couchbase://Administrator:password@127.0.0.1/commerce), COUCHBASE_SCOPE, and COUCHBASE_COLLECTION (both _default). Query examples also accept COUCHBASE_QUERY_URL for a separate Query endpoint. They create their own data, clean up their UUID keys, and do not require a sample dataset.
couchbase
- 0
- 0
- 0
- 0
- 1
- 39 minutes ago
- October 19, 2026
MIT License
Mon, 19 Oct 2026 22:20:17 GMT