MCPcopy Create free account
hub / github.com/WiseLibs/better-sqlite3 / Addon

Class Addon

src/addon.cpp:1–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1struct Addon {
2 explicit Addon(Napi::Env env) :
3 privileged_info(NULL),
4 next_id(0),
5 cs(env) {}
6
7 static void Cleanup(Addon* addon) {
8 for (Database* db : addon->dbs) db->CloseHandles();
9 addon->dbs.clear();
10 delete addon;
11 }
12
13 inline sqlite3_uint64 NextId() {
14 return next_id++;
15 }
16
17 static void ConfigureURI() {
18 static std::once_flag init_flag;
19 std::call_once(init_flag, [](){
20 const char* env = getenv("SQLITE_USE_URI");
21 if (env != NULL) {
22 if (strcmp(env, "1") == 0) {
23 int status = sqlite3_config(SQLITE_CONFIG_URI, 1);
24 assert(status == SQLITE_OK); ((void)status);
25 } else if (strcmp(env, "0") == 0) {
26 int status = sqlite3_config(SQLITE_CONFIG_URI, 0);
27 assert(status == SQLITE_OK); ((void)status);
28 }
29 }
30 });
31 }
32
33 static NODE_METHOD(JS_initialize) {
34 REQUIRE_ARGUMENT_FUNCTION(first, Napi::Function SqliteError);
35 REQUIRE_ARGUMENT_FUNCTION(second, Napi::Function ArrayFactory);
36 REQUIRE_ARGUMENT_FUNCTION(third, Napi::Function ArrayAppender);
37 REQUIRE_ARGUMENT_FUNCTION(fourth, Napi::Function RowFactory);
38 REQUIRE_ARGUMENT_FUNCTION(fifth, Napi::Function RecordFactory);
39 OnlyAddon->SqliteError = Napi::Persistent(SqliteError);
40 OnlyAddon->ArrayFactory = Napi::Persistent(ArrayFactory);
41 OnlyAddon->ArrayAppender = Napi::Persistent(ArrayAppender);
42 OnlyAddon->RowFactory = Napi::Persistent(RowFactory);
43 OnlyAddon->RecordFactory = Napi::Persistent(RecordFactory);
44 return info.Env().Undefined();
45 }
46
47 Napi::FunctionReference Statement;
48 Napi::FunctionReference StatementIterator;
49 Napi::FunctionReference Backup;
50 Napi::FunctionReference SqliteError;
51 Napi::FunctionReference ArrayFactory;
52 Napi::FunctionReference ArrayAppender;
53 Napi::FunctionReference RowFactory;
54 Napi::FunctionReference RecordFactory;
55 NODE_ARGUMENTS_POINTER privileged_info;
56 sqlite3_uint64 next_id;
57 CS cs;
58 std::set<Database*, Database::CompareDatabase> dbs;
59};

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected