After a two-year public gestation period, the newest member of the Couchbase Lite family is ready for its birthday! Couchbase Lite for C enters the world with the Couchbase Lite 3.0 release—it’s skipped a few grades to join its siblings.
What is Couchbase Lite for C? Couchbase Lite is our client-side document-database library with rich queries and full data sync support. Couchbase Lite for C adds an ANSI C API so you can link it into C or C++ apps.
You get:
- The same great feature set, architecture and API, with classes and methods becoming C structs and functions
- A single small native library, with no dependence on a language runtime
- Even broader OS compatibility
- Modest hardware needs
Why is this a big deal? After all, mobile app developers usually develop for iOS or Android by coding in C#, Java, Objective-C or Swift and we already have versions of Couchbase Lite tailored to all of those. We also have desktop Mac and Windows support.
What’s left that we haven’t covered?
Internet Of Things
Embedded devices! There are a lot of these, and even if you rule out light bulbs, toasters, etc., that have no need for a database, the burgeoning Internet Of Things category has many use cases that need access to structured data. They often need to share this data with a server or another IoT device. For example, hospitals use specialized medical devices that store patient records and vital signs. This data needs to be available wherever that patient is being treated.
The main focus of Couchbase Lite for C are data-rich IoT devices that run Linux. We’ve made a best-in-class mobile database, with data sync technology, available to products running on hardware similar to the Raspberry-Pi, i.e., ARM SoCs with an MMU and a few hundred megabytes of RAM.
Desktop Linux
Non-embedded Linux distributions can now join in too. Couchbase Lite for C opens the door to desktop and laptop Linux apps, with Ubuntu and Debian support in 3.0 and more distros to be added over time. It also supports macOS and Windows.
Couchbase Lite can even be an attractive choice for lightweight servers. Couchbase Lite’s JSON-document data model is the same as Couchbase Server, but with a much smaller footprint and zero configuration. It is not designed to match the scalability of Couchbase Server.
Cross-Platform Apps
With the same API across Linux, Mac, Windows, Android and iOS, Couchbase Lite for C is also a boon for applications with cross-platform C/C++ core code: their core can use it as a persistence and sync solution without needing any awkward upward dependencies on platform-specific libraries.
Other Languages
With the many, many programming languages in use today, we know we cannot support them all directly. It’s not hard to bridge the Java and C# versions of Couchbase Lite to other JVM and .NET CLR languages. But what about exotic, niche languages like Python, JavaScript, or Rust?
C may not be everyone’s favorite language, but, like English, it’s a lingua Franca for developers. (Wait, doesn’t Franca mean “French”?) Every language can interoperate with C, using a foreign function interface (FFI). So that means every language could have a Couchbase Lite API if someone wrote glue code to tie its FFI to Couchbase Lite for C.
Couchbase can’t write all that glue code, let alone support it, but we have provided two examples to get people started: a Python binding and a Rust binding. Think of these as sample code: they work, but they’re incomplete, unsupported, and only lightly tested. However, as they’re Apache-licensed, we encourage the community to improve and extend them. And just as importantly, they can serve as examples for developers writing other bindings — a great example of this is the 3rd party Dart binding.
Further Reading And Viewing
To learn more, check out my presentation on Couchbase Lite for C from the 2021 Couchbase Connect conference. It goes into more detail on the API, especially the ways in which the C translation differs from other platforms.
Other reference material and sample bindings links are available for you to dig deeper: