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

#1046 in Database interfaces

Download history 24/week @ 2024-01-29 18/week @ 2024-02-05 20/week @ 2024-02-12 19/week @ 2024-02-19 52/week @ 2024-02-26 13/week @ 2024-03-04

106 downloads per month
Used in kcore

Apache-2.0

1MB
25K SLoC

C++ 14K SLoC // 0.1% comments C 6.5K SLoC // 0.1% comments Rust 5K SLoC // 0.0% comments Perl 115 SLoC // 0.0% comments D 40 SLoC // 0.1% comments Ruby 31 SLoC // 0.2% comments OCaml 14 SLoC Shell 8 SLoC Batch 3 SLoC Ruby HTML 2 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.39 because this SDK makes heavy use of async/await.

Installation

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

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

~5.5–8.5MB
~187K SLoC