Skip to content

Commit

Permalink
src, test: lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
louwers committed Aug 3, 2024
1 parent b62c955 commit 768d950
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/node_sqlite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,14 @@ void DatabaseSync::ApplyChangeset(const FunctionCallbackInfo<Value>& args) {

Local<Object> options = args[1].As<Object>();

Local<String> conflictKey = String::NewFromUtf8(env->isolate(), "onConflict", v8::NewStringType::kNormal).ToLocalChecked();
Local<String> conflictKey = String::NewFromUtf8(
env->isolate(),
"onConflict",
v8::NewStringType::kNormal).ToLocalChecked();
if (options->HasOwnProperty(env->context(), conflictKey).FromJust()) {
Local<Value> conflictValue = options->Get(env->context(), conflictKey).ToLocalChecked();
Local<Value> conflictValue = options->Get(
env->context(),
conflictKey).ToLocalChecked();

if (!conflictValue->IsNumber()) {
node::THROW_ERR_INVALID_ARG_TYPE(
Expand Down
37 changes: 37 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const {
DatabaseSync,
StatementSync,
SQLITE_CHANGESET_OMIT,
SQLITE_CHANGESET_REPLACE,
SQLITE_CHANGESET_ABORT
} = require('node:sqlite');

const prepareConflict = () => {
const database1 = new DatabaseSync(':memory:');
const database2 = new DatabaseSync(':memory:');

const createDataTableSql = `CREATE TABLE data (
key INTEGER PRIMARY KEY,
value TEXT
) STRICT
`;
database1.exec(createDataTableSql);
database2.exec(createDataTableSql);

const insertSql = 'INSERT INTO data (key, value) VALUES (?, ?)';
const session = database1.createSession();
database1.prepare(insertSql).run(1, 'hello');
database1.prepare(insertSql).run(2, 'foo');
database2.prepare(insertSql).run(1, 'world');
return {
database2,
changeset: session.changeset()
}
}

const { database2, changeset } = prepareConflict();
const result = database2.applyChangeset(changeset, {
conflict: SQLITE_CHANGESET_OMIT
});

console.log(database2.prepare('SELECT value from data ORDER BY key ASC').all());

0 comments on commit 768d950

Please sign in to comment.