• Stars
    star
    112
  • Rank 312,240 (Top 7 %)
  • Language
    C++
  • License
    Apache License 2.0
  • Created almost 6 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

C language bindings for the Couchbase Lite embedded NoSQL database engine

Couchbase Lite For C

This is a cross-platform version of the Couchbase Lite embedded NoSQL syncable database, with a plain C API. The API can be used directly, or as the substrate for binding to other languages like Python, JavaScript or Rust.

Goals

  • C API
    • Similar to to other Couchbase Lite platforms (Java, C#, Swift, Objective-C)
    • Clean and regular design
    • Comes with a C++ wrapper API, implemented as inline calls to C
    • Can be bound to other languages like Python, Go, or JavaScript
  • Same feature set as other Couchbase Lite platforms
    • Schemaless JSON data model
      • Standard CRUD operations
      • Efficient binary blob support
      • Timed document expiration
      • Database encryption (Enterprise Edition only)
    • Powerful query language based on Couchbase's N1QL
      • Index arbitrary JSON properties or derived expression values
      • Full-text search (FTS)
    • Multi-master bidirectional replication (sync) with Couchbase Server
      • Fast WebSocket-based protocol
      • Transfers document deltas for minimal bandwidth
      • Replicator event listeners
      • Replicator online/offline support and retry behavior
      • Replicator TLS/SSL support
      • Peer-to-peer replication
  • Minimal platform dependencies: C++ standard library, filesystem, TCP/IP, libz (macOS / Linux), libicu (Linux)
  • Broad official OS support
    • macOS (x86_64 and arm64)
    • Debian 9/10 (including Raspbian / Raspberry Pi OS) and Ubuntu 20.04 (x86_64, armhf, arm64)
    • Windows (x86_64 only)
    • iOS (device and simulator archs)
    • Android (armeabi-v7a, arm64-v8a, x86, x86_64)
  • Runs on Raspberry-Pi-level embedded platforms with…
    • 32-bit or 64-bit CPU
    • ARM or x86
    • Hundreds of MB RAM, hundreds of MHz CPU, tens of MB storage
    • Linux-based OS

Examples

C

// Open a database:
CBLError error;
CBLDatabaseConfiguration config = {FLSTR("/tmp")};
CBLDatabase* db = CBLDatabase_Open(FLSTR("my_db"), &config, &error);

// Create a document:
CBLDocument* doc = CBLDocument_CreateWithID(FLSTR("foo"));
FLMutableDict props = CBLDocument_MutableProperties(doc);
FLSlot_SetString(FLMutableDict_Set(props, FLStr("greeting")), FLStr("Howdy!"));

// Save the document:
CBLDatabase_SaveDocument(db, doc, &error);
CBLDocument_Release(doc);

// Read it back:
const CBLDocument *readDoc = CBLDatabase_GetDocument(db, FLSTR("foo"), &error);
FLDict readProps = CBLDocument_Properties(readDoc);
FLSlice greeting = FLValue_AsString( FLDict_Get(readProps, FLStr("greeting")) );
CBLDocument_Release(readDoc);

C++

NOTE: The C++ API is a volatile API which means that the API is not finalized, and may change in future releases.

// Open a database:
cbl::Database db(kDatabaseName, {"/tmp"});

// Create a document:
cbl::MutableDocument doc("foo");
doc["greeting"] = "Howdy!";
db.saveDocument(doc);

// Read it back:
cbl::Document readDoc = db.getMutableDocument("foo");
fleece::Dict readProps = readDoc.properties();
fleece::slice greeting = readProps["greeting"].asString();

Documentation

Building It

Source Code

This project contains submodules in multiple levels. Please make sure all submodules are checked out before building the project.

git clone https://github.com/couchbase/couchbase-lite-C.git
cd couchbase-lite-C
git submodule update --init --recursive

Unix (Linux / macOS)

Dependencies:

  • GCC 7+ or Clang
  • CMake 3.10+
  • (Linux) ICU development libraries (apt-get install icu-dev)
  • (Linux) ZLIB development libraries (apt-get install zlib1g-dev)

Steps:

  1. Prepare and build project with CMake.

    # At the project directory, create a build directory:
    mkdir build && cd build
    
    # Prepare project. Specify CMAKE_INSTALL_PREFIX for the installation directory when running `make install`.
    # Add -DSTRIP_SYMBOLS=ON to generate a separate debug symbol file and strip private symbols from the built shared library.
    cmake -DCMAKE_BUILD_TYPE=MinSizeRel -DCMAKE_INSTALL_PREFIX=`pwd`/output ..
    
    # Build:
    make
    
  2. Install the built library and headers to the location specified by CMAKE_INSTALL_PREFIX

    make install
    

    The installation will contain header files in the include folder and a shared library file in the lib folder.

Linux (Cross Compile)

NOTE: Due to the complexity of cross compiling, these instructions are very high level on purpose. If you are curious about more fine-grained details you can check out the cross compilation script we use.

Dependencies:

  • Cross compiler based on GCC 7+ or clang
  • CMake 3.10+
  • (in sysroot) ICU development libraries
  • (in sysroot) ZLIB development libraries

Steps:

The steps are similar to the steps for building the regular linux library above. The difference is that you will also need to prepare the CMake toolchain file that sets up the cross compiler and sysroot for the cross compilation.

When running the cmake to prepare the build project, add CMAKE_TOOLCHAIN_FILE option to specify the CMake toolchain file:

cmake -DCMAKE_TOOLCHAIN_FILE=<YOUR/toolchain.cmake> -DCMAKE_BUILD_TYPE=MinSizeRel -DCMAKE_INSTALL_PREFIX=`pwd`/output ..

Windows

Dependencies:

  • Visual Studio Toolset v141+ (Visual Studio 2017+)
  • CMake 3.10+

Steps:

  1. Prepare project with CMake.

    # Using powershell, at the project directory, create a build directory:
    md build
    cd build
    
    # Prepare project. Specify CMAKE_INSTALL_PREFIX for the installation directory:
    cmake -G "Visual Studio 15 2017" -A x64 -DCMAKE_INSTALL_PREFIX="$pwd/output" ..
    
    
  2. Build and Install

    cmake --build . --config MinSizeRel --target install
    

    The installation will contain header files in the include folder, a dll file in the bin folder and a lib file in the lib folder.

Xcode on macOS

⚠️ Do not use Xcode 13 because of a downstream issue ⚠️

  1. Open the Xcode project CBL_C.xcodeproj
  2. Select scheme CBL_C Framework
  3. Build

The result is CouchbaseLite.framework in your Xcode Build Products/Debug directory (the path depends on your Xcode settings.)

Testing It

CMake on Unix

  1. Follow the steps in building
  2. Build the test project make CBL_C_Tests
  3. Run the tests in test directory ./CBL_C_Tests -r list (for cross compile, this step needs to be done on the target system)

CMake on Windows

  1. Follow the steps in building
  2. Build the test project cmake --build . --target CBL_C_Tests
  3. Run the tests in test\Debug directory .\CBL_C_Tests.exe -r list

With Xcode on macOS

  1. Open the Xcode project from the Building section
  2. Select scheme CBL_Tests
  3. Run

Using It

Generic instructions

  • In your build settings, add the paths include and vendor/couchbase-lite-core/vendor/fleece/API (relative to this repo) to your header search paths.
  • In your linker settings, add the dynamic library.
  • In source files, add #include "cbl/CouchbaseLite.h".

With Xcode on macOS

  • Add CouchbaseLite.framework (see instructions above) to your project.
  • In source files, add #include "CouchbaseLite/CouchbaseLite.h".
  • You may need to add a build step to your target, to copy the framework into your app bundle.

Other Language Bindings

All of these (even C++) have no official support by Couchbase.

If you've created a language binding, please let us know by filing an issue, or a PR that updates the list below.

More Repositories

1

couchbase-lite-ios

Lightweight, embedded, syncable NoSQL database engine for iOS and MacOS apps.
Objective-C
1,603
star
2

forestdb

A Fast Key-Value Storage Engine Based on Hierarchical B+-Tree Trie
C++
1,284
star
3

couchbase-lite-android

Lightweight, embedded, syncable NoSQL database engine for Android.
Java
1,173
star
4

moss

moss - a simple, fast, ordered, persistable, key-val storage library for golang
Go
947
star
5

geocouch

GeoCouch, a spatial index for CouchDB
Erlang
513
star
6

vellum

A Go library implementing an FST (finite state transducer)
Go
497
star
7

couchnode

Couchbase Node.js Client Library (Official)
C++
462
star
8

sync_gateway

Manages access and synchronization between Couchbase Lite and Couchbase Server
Go
447
star
9

couchbase-lite-net

A lightweight, document-oriented (NoSQL), syncable database engine for .NET
C#
436
star
10

go-slab

slab allocator in go
Go
364
star
11

gocb

The Couchbase Go SDK
Go
359
star
12

go-couchbase

Couchbase client in Go
Go
318
star
13

fleece

A super-fast, compact, JSON-equivalent binary data format
C++
309
star
14

couchbase-net-client

The official Couchbase SDK for .NET Core and Full Frameworks
C#
271
star
15

couchbase-lite-core

Cross-platform C++ core library for Couchbase Lite
C++
253
star
16

couchbase-java-client

The official Java client for Couchbase Server
Java
252
star
17

couchbase-python-client

Couchbase Python Client Library (Official)
Python
239
star
18

couchbase-elasticsearch-connector

The Official Couchbase Elasticsearch Connector
Java
176
star
19

libcouchbase

The couchbase client for C.
C
173
star
20

docker

Dockerfiles and configuration scripts for the Docker Hub Official Couchbase images
Dockerfile
140
star
21

cbft

Couchbase Full Text server
Go
136
star
22

couchdb

CouchDB
Erlang
129
star
23

kv_engine

Couchbase Key-Value Engine
C++
128
star
24

couchbase-spark-connector

The Official Couchbase Spark Connector
Scala
119
star
25

nitro

A high performance in-memory index storage engine
Go
107
star
26

couchbase-ruby-client

Couchbase Ruby Client Library (Official)
Ruby
107
star
27

query

Query engine.
Go
103
star
28

kafka-connect-couchbase

Kafka Connect connector for Couchbase Server
Java
70
star
29

couchbase-kafka-connector

Legacy Couchbase to Kafka connector, superseded by Kafka Connect based.
Java
69
star
30

couchbase-lite-java-core

Couchbase Lite Java core library
Java
68
star
31

CouchbaseMock

A Java mock for Couchbase
Java
62
star
32

couchbase-ruby-model

The Active Model implementation for Couchbase Server built on couchbase-ruby-client
Ruby
61
star
33

memcached

Memcached work planned for contribution back to memcached/memcached
C++
56
star
34

couchstore

couchbase storage file library
C
54
star
35

couchbase-lite-java

Portable java version of Couchbase Lite
Java
52
star
36

java-dcp-client

Couchbase Java DCP Client
Java
48
star
37

couchbase-lite-java-ce-root

The root workspace for the Community Editions of the Java language family of products (Java Desktop, Java WebService, and Android)
Shell
47
star
38

ns_server

The Membase Server Superdupervisor.
JavaScript
44
star
39

couchbase-jvm-clients

The Couchbase Monorepo for JVM Clients: Java, Scala, io-core…
Java
44
star
40

kubernetes

Deprecated. Please use the Couchbase Autonomous Operator
Shell
43
star
41

couchbase-cli

Command Line tools for Administering a Couchbase Cluster
Python
39
star
42

moxi

a memcached proxy with energy and pep
C
39
star
43

indexing

Couchbase Indexes
Go
38
star
44

tlm

top level makefile
CMake
35
star
45

docs-site

The Antora playbook project, contributing documentation, and home page for the new Couchbase Docs site.
JavaScript
34
star
46

go_n1ql

N1QL Driver for Go lang's database/sql package
Go
33
star
47

couchbase-jvm-core

The JVM core for Couchbase SDKs.
Java
32
star
48

docs-cb4

Documentation for Couchbase Server 4.x and 5.x GA releases
HTML
28
star
49

ep-engine

Eventually Persistent Couchbase Data Layer.
C++
28
star
50

couchbase-exporter

Couchbase Prometheus Exporter
Go
27
star
51

eventing

Couchbase Eventing Engine
Go
26
star
52

couchbase-lite-android-liteserv

An HTTP (ReST) interface to the Couchbase-Lite database running on the device/emulator
Java
24
star
53

gocbcore

The IO component of gocb
Go
22
star
54

cbgt

The cbgt project provides a generic golang library that manages partitions or data shards across a cluster of servers.
Go
22
star
55

testrunner

The TestRunner (Extracted from carlin).
Python
21
star
56

perfrunner

Performance TAF for Couchbase Server
Python
20
star
57

couchbase-lite-java-native

This is a shared native SQLite library used for Couchbase Lite Android/Java.
C++
20
star
58

couchbase-examples

Ruby
19
star
59

chronicle

Erlang
19
star
60

docs-server

The Couchbase Server documentation source files (in AsciiDoc) used in the Couchbase Docs site.
HTML
18
star
61

service-broker

An Open Service Broker Based Kubernetes Templating Engine
Go
17
star
62

build

jenkins scripts for executing builds, cgi scripts for status and reporting
Shell
17
star
63

goxdcr

Go
16
star
64

phosphor

High performance event tracing
C++
16
star
65

couchbase-fluent-bit

Fast and Lightweight Log processor and forwarder. Based on upstream Fluent Bit, this includes some additional Couchbase specific configuration and support - https://github.com/fluent/fluent-bit
Go
13
star
66

subjson

High performance JSON manipulation library
C++
13
star
67

gperftools

C++
12
star
68

platform

Small library providing a platform layer
C++
12
star
69

docs-ui-old

Produces the UI bundle used by the Couchbase documentation site.
CSS
12
star
70

couchbase-lite-java-listener

Embedded web server to expose Couchbase Lite REST API on an http socket
Java
12
star
71

cbmonitor

cbmonitor
Python
11
star
72

docs-couchbase-lite

Documentation for Couchbase Lite
Java
10
star
73

couchbase-lite-java-javascript

Javascript view engine for Couchbase Lite Android
Java
10
star
74

sg-bucket

Sync Gateway Bucket interface and common code used by all Sync Gateway bucket implementations.
Go
10
star
75

query-ui

The Couchbase query workbench UI for SQL++ / N1QL.
JavaScript
10
star
76

godbc

Golang database connectivity API. This API is more flexible and extensible than golang's built-in database/sql package, because like JDBC, the API uses interfaces instead of concrete types. This allows it to be extended to handle both SQL and NoSQL / JSON data sources.
Go
10
star
77

couchbase-lite-android-ce

The community edition of couchbase lite for android
9
star
78

clog

Couchbase logging for go.
Go
9
star
79

gometa

Go
9
star
80

cbbootstrap

REST API to help bootstrap Couchbase Server clusters
Go
8
star
81

build-infra

Various programs and scripts used by the Build & Release team not directly related to specific software build processes
Dockerfile
7
star
82

gocbmgr

A library for the making Couchbase REST API calls in golang
Go
7
star
83

sigar

System Information Gatherer And Reporter
C++
7
star
84

Android-EmptyApp

The android empty app.
Java
7
star
85

product-metadata

Various configuration files describing products we build
Jinja
6
star
86

go-blip

Go language implementation of BLIP-over-WebSocket protocol
Go
6
star
87

docs-sdk-go

The Go SDK documentation source files used in the new Couchbase Docs site.
Go
5
star
88

build-manifests

Internal build manifests for all products.
5
star
89

tools-common

Go
5
star
90

couchbase-php-client

Couchbase PHP Client Library (Official)
PHP
5
star
91

docs-sdk-java

The Java SDK documentation source files used in the Couchbase Docs site.
Java
5
star
92

couchbase-lite-java-common

Common code for the Java language family of products (Java Desktop, Java WebService, and Android)
Java
5
star
93

server-sandbox

Dockerfiles for couchbase/server-sandbox automated build
Shell
5
star
94

couchbase-hadoop-plugin

A Couchbase to Hadoop (Sqoop) plugin for importing and exporting data
Java
5
star
95

n1k1

n1k1, pronounced "nicky", is a prototype execution compiler and engine for N1QL query plans
Go
4
star
96

gocb-opentelemetry

Go
4
star
97

stellar-gateway

Go
4
star
98

rhmap

robinhood hashmap in golang
Go
4
star
99

spring

Simple Couchbase CRUD-workload generator based on pylibcouchbase
Python
4
star
100

product-texts

Repository for product-specific documents (e.g. READMEs, license files, etc.)
Rich Text Format
3
star