in src/database.cc [191:224]
void Database::Work_AfterOpen(napi_env e, napi_status status, void* data) {
std::unique_ptr<OpenBaton> baton(static_cast<OpenBaton*>(data));
Database* db = baton->db;
Napi::Env env = db->Env();
Napi::HandleScope scope(env);
Napi::Value argv[1];
if (baton->status != SQLITE_OK) {
EXCEPTION(Napi::String::New(env, baton->message.c_str()), baton->status, exception);
argv[0] = exception;
}
else {
db->open = true;
argv[0] = env.Null();
}
Napi::Function cb = baton->callback.Value();
if (!cb.IsUndefined() && cb.IsFunction()) {
TRY_CATCH_CALL(db->Value(), cb, 1, argv);
}
else if (!db->open) {
Napi::Value info[] = { Napi::String::New(env, "error"), argv[0] };
EMIT_EVENT(db->Value(), 2, info);
}
if (db->open) {
Napi::Value info[] = { Napi::String::New(env, "open") };
EMIT_EVENT(db->Value(), 1, info);
db->Process();
}
}