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

#926 in Database interfaces

Download history 6/week @ 2024-06-10 7/week @ 2024-06-17 1/week @ 2024-06-24 2/week @ 2024-07-15 13/week @ 2024-07-22 6/week @ 2024-07-29 16/week @ 2024-08-26 6/week @ 2024-09-02 8/week @ 2024-09-09 29/week @ 2024-09-16 17/week @ 2024-09-23

60 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.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

~6.5–10MB
~191K SLoC