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

Function NODE_METHOD

src/objects/backup.cpp:40–88  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38}
39
40NODE_METHOD(Backup::JS_new) {
41 UseAddon;
42 if (!addon->privileged_info) return ThrowTypeError(info.Env(), "Disabled constructor");
43 assert(info.IsConstructCall());
44 const Napi::CallbackInfo& pinfo = *addon->privileged_info;
45 Database* db = ::Unwrap<Database>(pinfo.This());
46 REQUIRE_DATABASE_OPEN(db->GetState());
47 REQUIRE_DATABASE_NOT_BUSY(db->GetState());
48
49 Napi::Object database = pinfo[0].As<Napi::Object>();
50 Napi::String attachedName = pinfo[1].As<Napi::String>();
51 Napi::String destFile = pinfo[2].As<Napi::String>();
52 bool unlink = pinfo[3].As<Napi::Boolean>().Value();
53
54 UseIsolate;
55 sqlite3* dest_handle;
56 std::string dest_file = destFile.Utf8Value();
57 std::string attached_name = attachedName.Utf8Value();
58 int mask = (SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);
59
60 if (sqlite3_open_v2(dest_file.c_str(), &dest_handle, mask, NULL) != SQLITE_OK) {
61 Database::ThrowSqliteError(env, addon, dest_handle);
62 int status = sqlite3_close(dest_handle);
63 assert(status == SQLITE_OK); ((void)status);
64 return env.Undefined();
65 }
66
67 sqlite3_extended_result_codes(dest_handle, 1);
68 sqlite3_limit(dest_handle, SQLITE_LIMIT_LENGTH, INT_MAX);
69 sqlite3_backup* backup_handle = sqlite3_backup_init(dest_handle, "main", db->GetHandle(), attached_name.c_str());
70 if (backup_handle == NULL) {
71 Database::ThrowSqliteError(env, addon, dest_handle);
72 int status = sqlite3_close(dest_handle);
73 assert(status == SQLITE_OK); ((void)status);
74 return env.Undefined();
75 }
76
77 this->db = db;
78 this->dest_handle = dest_handle;
79 this->backup_handle = backup_handle;
80 this->id = addon->NextId();
81 this->unlink = unlink;
82 this->alive = true;
83 db->AddBackup(this);
84
85 SetFrozen(env, info.This().As<Napi::Object>(), addon->cs.database, database);
86
87 return info.This();
88}
89
90NODE_METHOD(Backup::JS_transfer) {
91 Backup* backup = ::Unwrap<Backup>(info.This());

Callers

nothing calls this directly

Calls 9

ThrowTypeErrorFunction · 0.85
SetFrozenFunction · 0.85
GetStateMethod · 0.80
GetHandleMethod · 0.80
NextIdMethod · 0.80
AddBackupMethod · 0.80
GetAddonMethod · 0.80
RemoveBackupMethod · 0.80
CloseHandlesMethod · 0.45

Tested by

no test coverage detected