#include #include "dal.h" static void _InitSQLite(const Napi::CallbackInfo& args) { Napi::Buffer buf = args[0].As>(); GoString charstr = {reinterpret_cast(buf.Data()), long(buf.Length())}; InitSQLite(charstr); } static Napi::Object RowIterator(const Napi::CallbackInfo& args) { Napi::Env env = args.Env(); Napi::Object it = Napi::Object::New( env ); Napi::Buffer buf = args[0].As>(); GoSlice input = {reinterpret_cast(buf.Data()), long(buf.Length()), long(buf.Length())}; int iter = CreateRowIterator(input); auto next_row = [=](const Napi::CallbackInfo& a){ void* next = NextRow(iter); if (next == nullptr) { FreeIter(iter); return Napi::Buffer::New(env, 0); } Napi::Buffer val = Napi::Buffer::Copy(env, reinterpret_cast(next), GetLen(iter)); free(next); return val; }; auto free_iter = [=](const Napi::CallbackInfo& a){ FreeIter(iter); }; it.Set("next", Napi::Function::New(env, next_row)); it.Set("free", Napi::Function::New(env, free_iter)); return it; } static Napi::Object Init(Napi::Env env, Napi::Object exports) { exports["InitSQLite"] = Napi::Function::New(env, _InitSQLite); exports["RowIterator"] = Napi::Function::New(env, RowIterator); return exports; } NODE_API_MODULE(NODE_GYP_MODULE_NAME, Init)