Skip to content

Commit

Permalink
sqlite: expose backup api
Browse files Browse the repository at this point in the history
  • Loading branch information
geeksilva97 committed Dec 14, 2024
1 parent e698bd0 commit 6ae971a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/node_sqlite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,33 @@ inline void THROW_ERR_SQLITE_ERROR(Isolate* isolate, const char* message) {
}
}

class Backup {
public:
Backup(Environment* env, DatabaseSync* dest, DatabaseSync* source)
: env_(env), dest_(dest), source_(source) {
backup_ = sqlite3_backup_init(dest_->Connection(),
"main",
source_->Connection(),
"main");
if (backup_ == nullptr) {
THROW_ERR_SQLITE_ERROR(env->isolate(), dest_->Connection());
}
}

~Backup() {
sqlite3_backup_finish(backup_);
}

static void Start(const FunctionCallbackInfo<Value>& args) {
}

private:
Environment* env_;
DatabaseSync* dest_;
DatabaseSync* source_;
sqlite3_backup* backup_;
}

class UserDefinedFunction {
public:
explicit UserDefinedFunction(Environment* env,
Expand Down Expand Up @@ -664,6 +691,10 @@ void DatabaseSync::CustomFunction(const FunctionCallbackInfo<Value>& args) {
CHECK_ERROR_OR_THROW(env->isolate(), db->connection_, r, SQLITE_OK, void());
}

void DatabaseSync::Backup(const FunctionCallbackInfo<Value>& args) {

}

void DatabaseSync::CreateSession(const FunctionCallbackInfo<Value>& args) {
std::string table;
std::string db_name = "main";
Expand Down Expand Up @@ -1669,6 +1700,7 @@ static void Initialize(Local<Object> target,
db_tmpl->InstanceTemplate()->SetInternalFieldCount(
DatabaseSync::kInternalFieldCount);

SetProtoMethod(isolate, db_tmpl, "backup", DatabaseSync::Backup);
SetProtoMethod(isolate, db_tmpl, "open", DatabaseSync::Open);
SetProtoMethod(isolate, db_tmpl, "close", DatabaseSync::Close);
SetProtoMethod(isolate, db_tmpl, "prepare", DatabaseSync::Prepare);
Expand Down
1 change: 1 addition & 0 deletions src/node_sqlite.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class DatabaseSync : public BaseObject {
static void Prepare(const v8::FunctionCallbackInfo<v8::Value>& args);
static void Exec(const v8::FunctionCallbackInfo<v8::Value>& args);
static void CustomFunction(const v8::FunctionCallbackInfo<v8::Value>& args);
static void Backup(const v8::FunctionCallbackInfo<v8::Value>& args);
static void CreateSession(const v8::FunctionCallbackInfo<v8::Value>& args);
static void ApplyChangeset(const v8::FunctionCallbackInfo<v8::Value>& args);
static void EnableLoadExtension(
Expand Down

0 comments on commit 6ae971a

Please sign in to comment.