1 [![EJDB](http://ejdb.org/_images/ejdblogo3.png)](http://ejdb.org)
3 [EJDB v1.2.12 released (2017-21-03)](https://github.com/Softmotions/ejdb/releases/tag/v1.2.12)
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/)
22 **[Roadmap and thoughts for the next major EJDB 2.0 release](https://github.com/Softmotions/ejdb/issues/183)**
26 * LGPL license allows you to embed this library into proprietary software
27 * Simple C libejdb library can be easily embedded into any software
28 * Node.js/Python/Lua/Java/Ruby/.Net/Go/Pike/Mathlab/AdobeAIR bindings available
29 * MongoDB-like queries and overall philosophy.
30 * [Collection joins](https://github.com/Softmotions/ejdb/wiki/Collection-joins)
36 -----------------------------------
39 #include <ejdb/ejdb.h>
45 if (!ejdbopen(jb, "addressbook", JBOWRITER | JBOCREAT | JBOTRUNC)) {
49 //Get or create collection 'contacts'
50 EJCOLL *coll = ejdbcreatecoll(jb, "contacts", NULL);
56 //JSON: {'name' : 'Bruce', 'phone' : '333-222-333', 'age' : 58}
58 bson_append_string(&bsrec, "name", "Bruce");
59 bson_append_string(&bsrec, "phone", "333-222-333");
60 bson_append_int(&bsrec, "age", 58);
64 ejdbsavebson(coll, &bsrec, &oid);
65 fprintf(stderr, "\nSaved Bruce");
69 //QUERY: {'name' : {'$begin' : 'Bru'}} //Name starts with 'Bru' string
71 bson_init_as_query(&bq1);
72 bson_append_start_object(&bq1, "name");
73 bson_append_string(&bq1, "$begin", "Bru");
74 bson_append_finish_object(&bq1);
77 EJQ *q1 = ejdbcreatequery(jb, &bq1, NULL, 0, NULL);
80 TCLIST *res = ejdbqryexecute(coll, q1, &count, 0, NULL);
81 fprintf(stderr, "\n\nRecords found: %d\n", count);
83 //Now print the result set records
84 for (int i = 0; i < TCLISTNUM(res); ++i) {
85 void *bsdata = TCLISTVALPTR(res, i);
86 bson_print_raw(bsdata, 0);
88 fprintf(stderr, "\n");
104 Assuming libejdb installed on your system you can place the code above in `csnippet.c` and build program:
107 gcc -std=c99 -Wall -pedantic -c -o csnippet.o csnippet.c
108 gcc -o csnippet csnippet.o -lejdb
114 EJDB API exposed in **[ejdb.h](https://github.com/Softmotions/ejdb/blob/master/src/ejdb/ejdb.h)** C header file.
115 JSON processing API: **[bson.h](https://github.com/Softmotions/ejdb/blob/master/src/bson/bson.h)**
127 * gcc >= 4.7 or clang >= 3.4 C compiller
134 git clone https://github.com/Softmotions/ejdb.git
138 cmake -DCMAKE_BUILD_TYPE=Release ../
141 # Or you can create tgz package:
145 ### CMake basic build(-D) options
148 // Build ejdb sample projects
149 BUILD_SAMPLES:BOOL=ON
151 // Build shared libraries
152 BUILD_SHARED_LIBS:BOOL=ON
157 // Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo.
158 CMAKE_BUILD_TYPE:STRING=Release
160 // Install path prefix, prepended onto install directories.
161 CMAKE_INSTALL_PREFIX:PATH=/usr/local
163 // Enable PPA package build
166 // Build .deb instalation packages
169 // Build .tgz package archive
172 // Upload debian packages to the launchpad ppa repository
176 ### Building Windows libs
178 You need to checkout the [MXE cross build environment](http://mxe.cc)
179 Then create/edit MXE settings file:
182 cd <mxe checkout dir>
186 Save the following content in `settings.mk`:
190 MXE_TARGETS := x86_64-w64-mingw32.static i686-w64-mingw32.static
191 LOCAL_PKG_LIST := winpthreads pcre zlib lzo bzip2 cunit
192 .DEFAULT local-pkg-list:
193 local-pkg-list: $(LOCAL_PKG_LIST)
199 cd <mxe checkout dir>
203 Build libejdb windows binaries:
206 export MXE_HOME=<mxe checkout dir>
207 cd <ejdb checkout dir>
210 cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=../win64-tc.cmake ..
214 EJDB binary package installation
215 ===================================
221 sudo add-apt-repository ppa:adamansky/ejdb
223 sudo apt-get install ejdb ejdb-dbg