Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/env_properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@
V(socketaddress_constructor_template, v8::FunctionTemplate) \
V(space_stats_template, v8::DictionaryTemplate) \
V(sqlite_column_template, v8::DictionaryTemplate) \
V(sqlite_database_constructor_template, v8::FunctionTemplate) \
V(sqlite_limits_template, v8::ObjectTemplate) \
V(sqlite_run_result_template, v8::DictionaryTemplate) \
V(sqlite_statement_sync_constructor_template, v8::FunctionTemplate) \
Expand Down
9 changes: 6 additions & 3 deletions src/node_sqlite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3208,9 +3208,11 @@ void Database::CreateSession(const FunctionCallbackInfo<Value>& args) {

void Backup(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
if (args.Length() < 1 || !args[0]->IsObject()) {
THROW_ERR_INVALID_ARG_TYPE(env->isolate(),
"The \"sourceDb\" argument must be an object.");
if (!args[0]->IsObject() ||
!env->sqlite_database_constructor_template()->HasInstance(args[0])) {
THROW_ERR_INVALID_ARG_TYPE(
env->isolate(),
"The \"sourceDb\" argument must be a DatabaseSync instance.");
return;
}

Expand Down Expand Up @@ -5425,6 +5427,7 @@ static void Initialize(Local<Object> target,
FIXED_ONE_BYTE_STRING(isolate, "node:sqlite");
db_tmpl->InstanceTemplate()->Set(sqlite_type_symbol, database_sync_string);

env->set_sqlite_database_constructor_template(db_tmpl);
SetConstructorFunction(context, target, "Database", db_tmpl);
SetConstructorFunction(context,
target,
Expand Down
18 changes: 17 additions & 1 deletion test/parallel/test-sqlite-backup.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,26 @@ describe('backup()', () => {
backup();
}, {
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "sourceDb" argument must be an object.'
message: 'The "sourceDb" argument must be a DatabaseSync instance.'
});
});

test('throws if the source is not a DatabaseSync', (t) => {
const database = makeSourceDb();
for (const source of [
{},
database.prepare('SELECT 1'),
database.createSession(),
]) {
t.assert.throws(() => {
backup(source, 'out.db');
}, {
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "sourceDb" argument must be a DatabaseSync instance.'
});
}
});

test('throws if path is not a string, URL, or Buffer', (t) => {
const database = makeSourceDb();

Expand Down
Loading