2024-08-20 01:36:41 +00:00
|
|
|
#include <napi.h>
|
|
|
|
#include "dal.h"
|
|
|
|
|
|
|
|
static void _InitSQLite(const Napi::CallbackInfo& args) {
|
|
|
|
Napi::Buffer<uint8_t> buf = args[0].As<Napi::Buffer<uint8_t>>();
|
2024-08-20 11:09:35 +00:00
|
|
|
GoString charstr = {reinterpret_cast<char *>(buf.Data()), long(buf.Length())};
|
2024-08-20 01:36:41 +00:00
|
|
|
InitSQLite(charstr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Napi::Value Handle(const Napi::CallbackInfo& args) {
|
|
|
|
Napi::Buffer<uint8_t> buf = args[0].As<Napi::Buffer<uint8_t>>();
|
2024-08-20 11:09:35 +00:00
|
|
|
GoSlice input = {reinterpret_cast<void *>(buf.Data()), long(buf.Length()), long(buf.Length())};
|
|
|
|
GoSlice result = HandleQuery(input);
|
2024-08-20 01:36:41 +00:00
|
|
|
return Napi::Buffer<char>::Copy(args.Env(), reinterpret_cast<char *>(result.data), result.len);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static Napi::Object Init(Napi::Env env, Napi::Object exports) {
|
|
|
|
exports["InitSQLite"] = Napi::Function::New(env, _InitSQLite);
|
|
|
|
exports["Handle"] = Napi::Function::New(env, Handle);
|
|
|
|
return exports;
|
|
|
|
}
|
|
|
|
|
|
|
|
NODE_API_MODULE(NODE_GYP_MODULE_NAME, Init)
|
|
|
|
|