1 [![EJDB](http://ejdb.org/_images/ejdblogo3.png)](http://ejdb.org)
3 [EJDB v1.2.11 released (2017-16-03)](https://github.com/Softmotions/ejdb/releases/tag/v1.2.11)
5 Embedded JSON Database engine C library (libejdb)
6 =================================================
8 [![Join the chat at https://gitter.im/Softmotions/ejdb](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/Softmotions/ejdb?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
10 **See http://ejdb.org**
12 It aims to be a fast [MongoDB](http://mongodb.org)-like library
13 **which can be embedded into C/C++, .Net, NodeJS, Python, Lua, Go, Java
14 and Ruby applications under terms of LGPL license.**
16 EJDB is the C library based on modified
17 version of [Tokyo Cabinet](http://fallabs.com/tokyocabinet/).
19 JSON representation of queries and data implemented with API based on
20 [C BSON](https://github.com/mongodb/mongo-c-driver/tree/master/src/)
23 ### NOTE: libejdb 1.2.x introduces some changes that break compatibility with 1.1.x versions:
24 * Library name was changed from `tcejdb9` to `ejdb`
25 * Library build system was switched to CMake
26 * [See the full 1.2.3 changelog](https://github.com/Softmotions/ejdb/blob/master/Changelog)
31 * LGPL license allows you to embed this library into proprietary software
32 * Simple C libejdb library can be easily embedded into any software
33 * Node.js/Python/Lua/Java/Ruby/.Net/Go/Pike/Mathlab/AdobeAIR bindings available
34 * MongoDB-like queries and overall philosophy.
35 * [Collection joins](https://github.com/Softmotions/ejdb/wiki/Collection-joins)
41 -----------------------------------
44 #include <ejdb/ejdb.h>
50 if (!ejdbopen(jb, "addressbook", JBOWRITER | JBOCREAT | JBOTRUNC)) {
54 //Get or create collection 'contacts'
55 EJCOLL *coll = ejdbcreatecoll(jb, "contacts", NULL);
61 //JSON: {'name' : 'Bruce', 'phone' : '333-222-333', 'age' : 58}
63 bson_append_string(&bsrec, "name", "Bruce");
64 bson_append_string(&bsrec, "phone", "333-222-333");
65 bson_append_int(&bsrec, "age", 58);
69 ejdbsavebson(coll, &bsrec, &oid);
70 fprintf(stderr, "\nSaved Bruce");
74 //QUERY: {'name' : {'$begin' : 'Bru'}} //Name starts with 'Bru' string
76 bson_init_as_query(&bq1);
77 bson_append_start_object(&bq1, "name");
78 bson_append_string(&bq1, "$begin", "Bru");
79 bson_append_finish_object(&bq1);
82 EJQ *q1 = ejdbcreatequery(jb, &bq1, NULL, 0, NULL);
85 TCLIST *res = ejdbqryexecute(coll, q1, &count, 0, NULL);
86 fprintf(stderr, "\n\nRecords found: %d\n", count);
88 //Now print the result set records
89 for (int i = 0; i < TCLISTNUM(res); ++i) {
90 void *bsdata = TCLISTVALPTR(res, i);
91 bson_print_raw(bsdata, 0);
93 fprintf(stderr, "\n");
109 Assuming libejdb installed on your system you can place the code above in `csnippet.c` and build program:
112 gcc -std=c99 -Wall -pedantic -c -o csnippet.o csnippet.c
113 gcc -o csnippet csnippet.o -lejdb
119 EJDB API exposed in **[ejdb.h](https://github.com/Softmotions/ejdb/blob/master/src/ejdb/ejdb.h)** C header file.
120 JSON processing API: **[bson.h](https://github.com/Softmotions/ejdb/blob/master/src/bson/bson.h)**
132 * gcc >= 4.7 or clang >= 3.4 C compiller
139 git clone https://github.com/Softmotions/ejdb.git
143 cmake -DCMAKE_BUILD_TYPE=Release ../
146 # Or you can create tgz package:
150 ### CMake basic build(-D) options
153 // Build ejdb sample projects
154 BUILD_SAMPLES:BOOL=ON
156 // Build shared libraries
157 BUILD_SHARED_LIBS:BOOL=ON
162 // Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo.
163 CMAKE_BUILD_TYPE:STRING=Release
165 // Install path prefix, prepended onto install directories.
166 CMAKE_INSTALL_PREFIX:PATH=/usr/local
168 // Enable PPA package build
171 // Build .deb instalation packages
174 // Build .tgz package archive
177 // Upload debian packages to the launchpad ppa repository
181 ### Building Windows libs
183 You need to checkout the [MXE cross build environment](http://mxe.cc)
184 Then create/edit MXE settings file:
187 cd <mxe checkout dir>
191 Save the following content in `settings.mk`:
195 MXE_TARGETS := x86_64-w64-mingw32.static i686-w64-mingw32.static
196 LOCAL_PKG_LIST := winpthreads pcre zlib lzo bzip2 cunit
197 .DEFAULT local-pkg-list:
198 local-pkg-list: $(LOCAL_PKG_LIST)
204 cd <mxe checkout dir>
208 Build libejdb windows binaries:
211 export MXE_HOME=<mxe checkout dir>
212 cd <ejdb checkout dir>
215 cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=../win64-tc.cmake ..
219 EJDB binary package installation
220 ===================================
226 sudo add-apt-repository ppa:adamansky/ejdb
228 sudo apt-get install ejdb ejdb-dbg