1 [![EJDB](http://ejdb.org/_images/ejdblogo3.png)](http://ejdb.org)
3 Embedded JSON Database engine C library (libejdb)
4 =================================================
6 **See http://ejdb.org**
8 It aims to be a fast [MongoDB](http://mongodb.org)-like library
9 **which can be embedded into C/C++, .Net, NodeJS, Python, Lua, Go, Java
10 and Ruby applications under terms of LGPL license.**
12 EJDB is the C library based on modified
13 version of [Tokyo Cabinet](http://fallabs.com/tokyocabinet/).
15 JSON representation of queries and data implemented with API based on
16 [C BSON](https://github.com/mongodb/mongo-c-driver/tree/master/src/)
19 ### NOTE: libejdb 1.2.x introduces some changes that break compatibility with 1.1.x versions:
20 * Library name was changed from `tcejdb9` to `ejdb`
21 * Library build system was switched to CMake
22 * [See the full 1.2.3 changelog](https://github.com/Softmotions/ejdb/blob/master/Changelog)
27 * LGPL license allows you to embed this library into proprietary software
28 * Simple C libejdb library can be easily embedded into any software
29 * Node.js/Python/Lua/Java/Ruby/.Net/Go/Pike/Mathlab/AdobeAIR bindings available
30 * MongoDB-like queries and overall philosophy.
31 * [Collection joins](https://github.com/Softmotions/ejdb/wiki/Collection-joins)
37 -----------------------------------
40 #include <ejdb/ejdb.h>
46 if (!ejdbopen(jb, "addressbook", JBOWRITER | JBOCREAT | JBOTRUNC)) {
50 //Get or create collection 'contacts'
51 EJCOLL *coll = ejdbcreatecoll(jb, "contacts", NULL);
57 //JSON: {'name' : 'Bruce', 'phone' : '333-222-333', 'age' : 58}
59 bson_append_string(&bsrec, "name", "Bruce");
60 bson_append_string(&bsrec, "phone", "333-222-333");
61 bson_append_int(&bsrec, "age", 58);
65 ejdbsavebson(coll, &bsrec, &oid);
66 fprintf(stderr, "\nSaved Bruce");
70 //QUERY: {'name' : {'$begin' : 'Bru'}} //Name starts with 'Bru' string
72 bson_init_as_query(&bq1);
73 bson_append_start_object(&bq1, "name");
74 bson_append_string(&bq1, "$begin", "Bru");
75 bson_append_finish_object(&bq1);
78 EJQ *q1 = ejdbcreatequery(jb, &bq1, NULL, 0, NULL);
81 TCLIST *res = ejdbqryexecute(coll, q1, &count, 0, NULL);
82 fprintf(stderr, "\n\nRecords found: %d\n", count);
84 //Now print the result set records
85 for (int i = 0; i < TCLISTNUM(res); ++i) {
86 void *bsdata = TCLISTVALPTR(res, i);
87 bson_print_raw(bsdata, 0);
89 fprintf(stderr, "\n");
105 Assuming libejdb installed on your system you can place the code above in `csnippet.c` and build program:
108 gcc -std=c99 -Wall -pedantic -c -o csnippet.o csnippet.c
109 gcc -o csnippet csnippet.o -lejdb
115 EJDB API exposed in **[ejdb.h](https://github.com/Softmotions/ejdb/blob/master/src/ejdb/ejdb.h)** C header file.
116 JSON processing API: **[bson.h](https://github.com/Softmotions/ejdb/blob/master/src/bson/bson.h)**
128 * gcc >= 4.7 or clang >= 3.4 C compiller
135 git clone https://github.com/Softmotions/ejdb.git
139 cmake -DCMAKE_BUILD_TYPE=Release ../
142 # Or you can create tgz package:
146 ### CMake basic build(-D) options
149 // Build ejdb sample projects
150 BUILD_SAMPLES:BOOL=ON
152 // Build shared libraries
153 BUILD_SHARED_LIBS:BOOL=ON
158 // Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo.
159 CMAKE_BUILD_TYPE:STRING=Release
161 // Install path prefix, prepended onto install directories.
162 CMAKE_INSTALL_PREFIX:PATH=/usr/local
164 // Enable PPA package build
167 // Build .deb instalation packages
170 // Build .tgz package archive
173 // Upload debian packages to the launchpad ppa repository
177 ### Building Windows libs
179 You need to checkout the [MXE cross build environment](http://mxe.cc)
180 Then create/edit MXE settings file:
183 cd <mxe checkout dir>
187 Save the following content in `settings.mk`:
191 MXE_TARGETS := x86_64-w64-mingw32.static i686-w64-mingw32.static
192 LOCAL_PKG_LIST := winpthreads pcre zlib lzo bzip2 cunit
193 .DEFAULT local-pkg-list:
194 local-pkg-list: $(LOCAL_PKG_LIST)
200 cd <mxe checkout dir>
204 Build libejdb windows binaries:
207 export MXE_HOME=<mxe checkout dir>
208 cd <ejdb checkout dir>
211 cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=../win64-tc.cmake ..
215 EJDB binary package installation
216 ===================================
222 sudo add-apt-repository ppa:adamansky/ejdb
224 sudo apt-get install ejdb ejdb-dbg