objectbox-java icon indicating copy to clipboard operation
objectbox-java copied to clipboard

[question] NodeJS support

Open silvioprog opened this issue 6 years ago • 8 comments

Hello.

Is there any plan to support NodeJS?

Thank you!

silvioprog avatar May 13 '19 15:05 silvioprog

While it's something we'd like to do, our small team is currently focused on different tasks.

Community volunteers could do this using ObjectBox C API; we'd definitely be supportive.

greenrobot avatar May 13 '19 15:05 greenrobot

Thanks a lot for answering! (should I keep this issue open to notify volunteers?)

silvioprog avatar May 15 '19 21:05 silvioprog

Yes, let's leave that open at least for reference and tracking user interest (give a :+1: at the top).

greenrobot avatar May 16 '19 09:05 greenrobot

Here's a crazy idea: transpile the ObjectBox C API, using Emscripten? And then store the data.mdb in window.localStorage?

Buggaboo avatar May 28 '19 17:05 Buggaboo

Update: so I was tinkering with transpiling objectbox-c to wasm/js:

Prepare the toolset:

#!/bin/bash
git clone https://github.com/emscripten-core/emsdk.git ; cd emsdk ; ./emsdk install latest ; ./emsdk activate latest ; source ./emsdk_env.sh
cd .. ; git clone https://github.com/objectbox/objectbox-c.git ; cd objectbox-c ; chmod +x download.sh ; ./download.sh

Then you can experiment with the following:

emcc -Werror -Llib -lobjectbox -Iinclude -Iexternal -o objectbox-js-test.html src-test/plain-c-test-main.c

Update: It seems that the drop-in objectbox core library (not ready yet for the public? #461 ) in the objectbox-c api has mangled names, so undefined symbols will prevent generating wast from it. Maybe the mac dylib version specifically has issues, dunno.

My conclusion: until the source code for the core is made available, transpiling to wasm for nodeJS support seems unlikely to happen. Wrapping the objectbox-c API for your target language X seems to be the way to provide support for objectbox.

Although, I was able to transpile the monster sample for flatcc to wasm.

# set up emscripten if necessary
cd .. ; git clone https://github.com/dvidelabs/flatcc ; cd flatcc
# compile c and generate from fbs
cmake . ; make
# transpile samples/monster
emcc -Werror -Iinclude -Isamples/monster/generated -o flatcc-js-monster.html src/runtime/*.c samples/monster/monster.c

Your express script to setup the correct mime type to run from a browser:

var express = require('express');
var app = express();
 
express.static.mime.types['wasm'] = 'application/wasm'; 
app.use(express.static(__dirname + '/'));

Direct your browser to http://localhost:8080/flatcc-js-monster.html

Theoretically, provided that we have the correct offsets, schema, versioning etc. required to read from the buffer (based on a objectbox database), you could read an objectbox database from the browser/nodejs, using a transpiled a flatcc program.

Buggaboo avatar Jun 27 '19 20:06 Buggaboo

There are thousands of native libraries for node, how hard can it be? Why transpile?

lanmower avatar Jul 02 '21 10:07 lanmower

Interested in using this database on the web platform..

swise0 avatar Mar 24 '22 03:03 swise0

Transpile for the necessary plumbing to put / get data from storage, based on your schema. IIRC, there's some work done on objectbox-dart support for the web. Maybe you could call the generated objectbox related javascript from objectbox-dart, on node, without flutter?

Buggaboo avatar Mar 28 '22 15:03 Buggaboo