8 releases (2 breaking)

1.0.0-alpha.4 Aug 26, 2020
1.0.0-alpha.3 Feb 4, 2020
1.0.0-alpha.2 Jun 9, 2019
1.0.0-alpha.1 May 12, 2019
0.1.1 Jan 30, 2017

#1961 in Database interfaces

37 downloads per month
Used in 2 crates (via couchbase)

Apache-2.0

3.5MB
82K SLoC

C++ 55K SLoC // 0.1% comments C 26K SLoC // 0.1% comments Rust 672 SLoC // 0.1% comments Perl 460 SLoC // 0.0% comments D 161 SLoC // 0.1% comments Ruby 127 SLoC // 0.2% comments OCaml 57 SLoC Shell 34 SLoC // 0.1% comments Batch 14 SLoC Ruby HTML 9 SLoC

Couchbase Rust SDK

LICENSE Crates.io Version

This is the repository for the official, community supported Couchbase Rust SDK. It is currently a work in progress and built on top of libcouchbase.

Requirements

Make sure to have all libcouchbase requirements satisfied to build it properly. Also bindgen requirements need to be in place. You need a rust version newer or equal to 1.77.2 because this SDK makes heavy use of async/await.

Installation

[dependencies]
couchbase = "1.0.0-alpha.5"

Usage

The examples folder has a bunch more, but here is a basic getting started doing a kv op:

pub fn main() {
    // Connect to the cluster with a connection string and credentials
    let cluster = Cluster::connect("couchbase://127.0.0.1", "Administrator", "password");
    // Open a bucket
    let bucket = cluster.bucket("travel-sample");
    // Use the default collection (needs to be used for all server 6.5 and earlier)
    let collection = bucket.default_collection();

    // Fetch a document
    match block_on(collection.get("airline_10", GetOptions::default())) {
        Ok(r) => println!("get result: {:?}", r),
        Err(e) => println!("get failed! {}", e),
    };

    // Upsert a document as JSON
    let mut content = HashMap::new();
    content.insert("Hello", "Rust!");

    match block_on(collection.upsert("foo", content, UpsertOptions::default())) {
        Ok(r) => println!("upsert result: {:?}", r),
        Err(e) => println!("upsert failed! {}", e),
    };
}

Examples

More examples can be found in the examples folder. Please open a ticket if something is not present or does not showcase what you need.

Unsafe Code

This code contains unsafe {} code blocks. Breathe slowly and calm down, it's going to be okay. The reason why we use unsafe code is so that we can call into libcouchbase which is a C library. The only unsafe code is found in the lcb part of the IO module. So if you experience a segfault, it will likely come from there. We are trying to even keep unsafe in there minimal, but by the nature of it, it is all over the place. We are also working on a pure Rust SDK with no unsafe code (hopefully), but until this ships and is mature we have to live with it.

Dependencies