Libdatahike provides a C/C++ interface to Datahike, allowing you to use Datahike databases from native applications. This library is built using GraalVM Native Image.
This feature of Datahike is still early and is subject to change.
To build the native library and test executable you need GraalVM-JDK installed with native-compile, babashka and Clojure.
# Compile the native library
bb ni-compile
# Compile the C++ test executable
./libdatahike/compile-cpp
This will create:
libdatahike/target/libdatahike.so - The shared librarylibdatahike/target/test_cpp - Test executableThe library provides the following C functions (defined in libdatahike/target/libdatahike.h):
create_database(thread, config, format, callback) - Create a new databasedatabase_exists(thread, config, format, callback) - Check if database existsdelete_database(thread, config, format, callback) - Delete a databasetransact(thread, config, input_format, data, output_format, callback) - Execute transactionsquery(thread, query, num_inputs, input_formats, inputs, output_format, callback) - Execute queriespull(thread, config, format, pattern, entity_id, output_format, callback) - Pull entity datapull_many(thread, config, format, pattern, entity_ids, output_format, callback) - Pull multiple entitiesentity(thread, config, format, entity_id, output_format, callback) - Get entitydatoms(thread, config, format, index, components, callback) - Get datomsschema(thread, config, format, output_format, callback) - Get schemareverse_schema(thread, config, format, output_format, callback) - Get reverse schemametrics(thread, config, format, output_format, callback) - Get database metricsgc_storage(thread, config, older_than, output_format, callback) - Garbage collect storagePlease take a look at the C++ example that is part of our test suite: [../libdatahike/src/test_cpp.cpp]
The library supports multiple data formats:
"edn" - Extensible Data Notation (default)"json" - JSON format"cbor" - RFC 8949 Concise Binary Object RepresentationErrors are returned through the callback functions as strings. Always check the callback results for error conditions.
Each thread requires its own graal_isolatethread_t. For multi-threaded applications, create separate thread contexts for each thread that will use the library.
When building applications that use libdatahike:
# Compile your C++ code
g++ -I./libdatahike/target -L./libdatahike/target -ldatahike -o your_app your_app.cpp
# Run with library path
LD_LIBRARY_PATH=./libdatahike/target ./your_app
# or on MacOS
DYLD_LIBRARY_PATH=./libdatahike/target ./your_app
Can you improve this documentation?Edit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |