Coder Social home page Coder Social logo

swarmfarm / couchbase-rs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from couchbaselabs/couchbase-rs

0.0 0.0 0.0 10.61 MB

The official, community supported Couchbase Rust SDK

Home Page: https://couchbase.com

License: Apache License 2.0

Shell 0.10% JavaScript 0.18% Ruby 0.09% C++ 39.33% Perl 0.07% C 48.55% Go 0.03% Rust 8.57% CSS 0.29% Makefile 0.09% HTML 0.04% CMake 1.36% Batchfile 0.01% Roff 1.31%

couchbase-rs's Introduction

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.

couchbase-rs's People

Contributors

daschl avatar chvck avatar avsej avatar kkharji avatar adamhjk avatar mikegoldsmith avatar jsatka avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.