• Stars
    star
    253
  • Rank 160,776 (Top 4 %)
  • Language
    C++
  • License
    Other
  • Created about 8 years ago
  • Updated about 1 month ago

Reviews

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

Repository Details

Cross-platform C++ core library for Couchbase Lite

Couchbase Lite Core (aka LiteCore) is the next-generation core storage and query engine for Couchbase Lite. It provides a cross-platform implementation of the database CRUD and query features, document versioning, and replication/sync.

All platform implementations of Couchbase Lite (from 2.0 onward) are built atop this core, adding higher-level language & platform bindings.

IMPORTANT: We do not recommend (or support) using LiteCore directly in other projects. Its API is unstable and can be tricky to use. Instead, use Couchbase Lite for C, a cross-platform version of Couchbase Lite with a C (and C++) API.

Features

  • Database CRUD (Create, Read, Update, Delete) operations:
    • Fast key-value storage, where keys and values are both opaque blobs
    • Iteration by key order
    • Iteration by sequence, reflecting the order in which changes were made to the database. (This is useful for tasks like updating indexes and replication)
    • Multi-version document format that tracks history using a revision tree (as in CouchDB)
    • Timed document expiration (as in Couchbase Server)
    • API support for database encryption (as provided by SQLCipher or SQLite's Encryption Extension)
    • Highly efficient Fleece binary data encoding: supports JSON data types but requires no parsing, making it extremely efficient to read
  • Direct querying of schemaless JSON documents:
    • Semantics based on SQL; supports most N1QL functionality
    • JSON query syntax, similar to a parse tree; easy to generate from platform APIs like NSPredicate
    • N1QL parser that translates to the above JSON syntax
    • Can search and index arbitrary document properties without requiring any schema
    • Can index arrays in documents, enabling efficient denormalized one-to-many relations
    • Queries compile into SQL and from there into SQLite compiled bytecode
    • Parameters can be substituted without having to recompile the query
    • Queries don't require indexes, but will run faster if indexes are created on the document properties being searched
    • Supports full-text search, using SQLite's FTS4 module
  • Replicator:
    • Multi-master bidirectional document sync
    • Replicator detects conflicts; temporarily stores both revisions, and notifies app-level handlers to resolve them
    • Replicator transfers document deltas, saving bandwidth when updating large documents
    • Uses BLIP multiplexing protocol over WebSockets
    • Pluggable transports mean it could run over Bluetooth or other protocols
  • REST API:
    • Implements a subset of the CouchDB / Sync Gateway / Couchbase Lite REST API
    • Currently incomplete; not ready for prime time
  • Pluggable storage engines:
    • SQLite is available by default
    • Others could be added by implementing C++ DataFile, KeyStore, Query interfaces
  • C and C++ APIs (rather low-level; not considered "public" APIs yet.)
  • Bindings to C# and Java (via Couchbase Lite)

Platform Support

LiteCore runs on Mac OS, iOS, Android, various other flavors of Unix, and Windows.

It is written in C++ (using C++17 features) and compiles with Clang, G++ and MSVC.

It has been experimentally built and run on the Raspberry Pi but this is not an actively maintained use.

Status

As of June 2020: LiteCore is in active use as the engine of Couchbase Lite 2! Development continues...

  • Active development usually happens on the master branch, which may therefore be temporarily broken.
  • There are various release branches (prefixed with release/, except for release/master which will be in the next point) which track along with releases of Couchbase Lite in the following manner until 3.1.x, which will start using release/x.y:
    • release/iridium : 2.5.x
    • release/cobalt : 2.6.x
    • release/mercury : 2.7.x
    • release/hydrogen : 2.8.x
    • release/lithium : 3.0.x
  • release/master tracks the latest stable master commit (with integration tests into Couchbase Lite), and staging/master is a place for candidates for a stable master build.
  • PR validation ensures that things keep building and passing tests (where possible) on all supported platforms.
  • CMake is available and used for all platforms except for iOS. There is also an Xcode project that is independently maintained in the Xcode folder.

Building It

We do not recommend (or support) using LiteCore directly in other projects. Its API is unstable and can be tricky to use. (Instead see Couchbase Lite for C, a cross-platform version of Couchbase Lite with a C (and C++) API.) The build instructions here are for the benefit of developers who want to debug or extend Couchbase Lite at the LiteCore level.

Very Important:

  • This repo has submodules. Make sure they're checked out. Either use git clone --recursive to download LiteCore, or else after the clone run git submodule update --init --recursive.

Once you've cloned or downloaded the source tree...

macOS, iOS

If you want to use Objective-C or Swift APIs, you should use Couchbase Lite instead — check out and build the [couchbase-lite-ios][CBL_iOS_2] repo, which itself includes LiteCore as a submodule.

The following instructions are to build just LiteCore on its own:

  • Make sure you have Xcode 12.2 or later.
  • Open Xcode/LiteCore.xcodeproj.
  • Select the scheme LiteCore static or LiteCore dylib.
  • Choose Product>Build (for a debug build) or Product>Build For>Profiling (for a release/optimized build).
  • Link the build product libLiteCoreStatic.a or libLiteCore.dylib into your target.

Linux

Important! LiteCore uses a couple of external libraries, which may or may not be installed in your system already. If not, please install the appropriate development packages via your package manager. You must have the following libraries present:

  • libz
  • libicu
  • libpthread

You can use either g++ or clang++ for compilation but you will need to honor the minimum versions of each, and only g++ is officially supported.

  • clang: 5.0+
    • libstdc++: 7.0+ or
    • libc++: Version from LLVM 5 or higher (unclear)
  • g++: 7.0+

Actually Building

Once you've got the dependencies and compiler installed, do this from the root directory of the source tree (works for both macOS and Linux):

mkdir build_cmake/unix
cd build_cmake/unix

# Use whatever compiler you have installed
cmake -DCMAKE_BUILD_TYPE=MinSizeRel ../..

# And a reasonable number (# of cores?) for the j flag
make -j8 LiteCore

If CMake's initial configuration checks fail, the setup may be left in a broken state and will then fail immediately. To remedy this simply delete the unix directory and try again.

Android

Android has a bit longer of a command line invocation but it is the same idea as the Linux build above. The current stance of Google is that CMake support for Android should be a part of the main CMake downstream now, which is a departure from the previous stance that Google would fork and maintain their own version of CMake which they then distributed. Similar story for the Ninja build system that Google favors.

  • Architecture: The architecture of the device being built for (x86, x86_64, armeabi-v7a [in example], arm64-v8a)
  • Version: The minimum Android API level that the library will support (22 in the following)

CMake must be 3.23 or higher for this technique.

# Set these appropriately for your system
export SDK_HOME=<path/to/android/sdk/root>
export NDK_VER="23.1.7779620" # Or whatever version you want, but if you go too much older you need to use a different technique

# Use the same name as the architecture being built for (e.g. armeabi-v7a)
mkdir -p build_cmake/android/lib/armeabi-v7a
cd build_cmake/android/lib/armeabi-v7a
cmake \
    -G Ninja \
    -DCMAKE_TOOLCHAIN_FILE="${SDK_HOME}/ndk/${NDK_VER}/build/cmake/android.toolchain.cmake" \
    -DCMAKE_MAKE_PROGRAM="ninja" \
    -DANDROID_NATIVE_API_LEVEL=22 \
    -DANDROID_ABI=armeabi-v7a \
    -DCMAKE_BUILD_TYPE=MinSizeRel \
    ../../../..

ninja LiteCore

Windows Desktop

Open the Visual Studio 2022 Developer Command Prompt and navigate to the repo root. Then execute:

cd build_make
"C:\Program Files (x86)\CMake\bin\cmake.exe" -G "Visual Studio 17 2022" -A x64 ..

This will create LiteCore.sln in the directory that you can open with Visual Studio. Note that only 64-bit x86 is supported now, but 32-bit x86 is still buildable.

Windows Store

Open the Visual Studio 2022 Developer Command Prompt and navigate to the repo root. Then execute:

cd build_make
"C:\Program Files (x86)\CMake\bin\cmake.exe" -G "Visual Studio 17 2022" -A x64 -DCMAKE_SYSTEM_NAME=WindowsStore
-D CMAKE_SYSTEM_VERSION="10.0"
-DCMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION="10.0.19041.0" ..

This will create LiteCore.sln in the directory that you can open with Visual Studio. Swap x64 with ARM64 in the above to get a 64-bit ARM build. Win32 and ARM will also build but are no longer supported.

Git Blame

If you are inspecting the Blame of this project, you may find it useful to run:

git config blame.ignoreRevsFile .git-blame-ignore-revs

This will ignore any commits that we have marked as such in that file (formatting, etc.)

Documentation

API

The C API headers are in C/include/. Generally you just need to include c4.h.

We have online C API documentation, generated by Doxygen from the headers.

If this is out of date, or you want a local copy, you can generate your own by running the following commands from a shell at the root directory of the repo:

cd C
doxygen

The main page is then located at ../docs/C/html/modules.html.

The C API is considered unstable and may change without notice, since it's considered an internal API of Couchbase Lite.

Do not call any C++ APIS, nor include any headers not in C/include/ -- these are the underlying implementation beneath the C API. They are even more unstable, expose internal functionality we don't support, and may blow up if used incorrectly. The exception is c4.hh, which provides some handy C++ wrappers around the C API and will make your life more pleasant if you code in C++.

Internal Implementation

For those interested in diving into the implementation, there is an overview of the major classes.

Current Authors

Jens Alfke (@snej), Jim Borden (@borrrden), Jianmin Zhao (@jianminzhao)

License

The source code in this repo is governed by the BSL 1.1 license.

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-java-client

The official Java client for Couchbase Server
Java
252
star
16

couchbase-python-client

Couchbase Python Client Library (Official)
Python
239
star
17

couchbase-elasticsearch-connector

The Official Couchbase Elasticsearch Connector
Java
176
star
18

libcouchbase

The couchbase client for C.
C
173
star
19

docker

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

cbft

Couchbase Full Text server
Go
136
star
21

couchdb

CouchDB
Erlang
129
star
22

kv_engine

Couchbase Key-Value Engine
C++
128
star
23

couchbase-spark-connector

The Official Couchbase Spark Connector
Scala
119
star
24

couchbase-lite-C

C language bindings for the Couchbase Lite embedded NoSQL database engine
C++
112
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