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

Function NODE_METHOD

src/objects/backup.cpp:39–87  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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