File tree Expand file tree Collapse file tree 2 files changed +44
-2
lines changed Expand file tree Collapse file tree 2 files changed +44
-2
lines changed Original file line number Diff line number Diff line change @@ -318,9 +318,14 @@ void DatabaseSync::ApplyChangeset(const FunctionCallbackInfo<Value>& args) {
318318
319319 Local<Object> options = args[1 ].As <Object>();
320320
321- Local<String> conflictKey = String::NewFromUtf8 (env->isolate (), " onConflict" , v8::NewStringType::kNormal ).ToLocalChecked ();
321+ Local<String> conflictKey = String::NewFromUtf8 (
322+ env->isolate (),
323+ " onConflict" ,
324+ v8::NewStringType::kNormal ).ToLocalChecked ();
322325 if (options->HasOwnProperty (env->context (), conflictKey).FromJust ()) {
323- Local<Value> conflictValue = options->Get (env->context (), conflictKey).ToLocalChecked ();
326+ Local<Value> conflictValue = options->Get (
327+ env->context (),
328+ conflictKey).ToLocalChecked ();
324329
325330 if (!conflictValue->IsNumber ()) {
326331 node::THROW_ERR_INVALID_ARG_TYPE (
Original file line number Diff line number Diff line change 1+ const {
2+ DatabaseSync,
3+ StatementSync,
4+ SQLITE_CHANGESET_OMIT ,
5+ SQLITE_CHANGESET_REPLACE ,
6+ SQLITE_CHANGESET_ABORT
7+ } = require ( 'node:sqlite' ) ;
8+
9+ const prepareConflict = ( ) => {
10+ const database1 = new DatabaseSync ( ':memory:' ) ;
11+ const database2 = new DatabaseSync ( ':memory:' ) ;
12+
13+ const createDataTableSql = `CREATE TABLE data (
14+ key INTEGER PRIMARY KEY,
15+ value TEXT
16+ ) STRICT
17+ ` ;
18+ database1 . exec ( createDataTableSql ) ;
19+ database2 . exec ( createDataTableSql ) ;
20+
21+ const insertSql = 'INSERT INTO data (key, value) VALUES (?, ?)' ;
22+ const session = database1 . createSession ( ) ;
23+ database1 . prepare ( insertSql ) . run ( 1 , 'hello' ) ;
24+ database1 . prepare ( insertSql ) . run ( 2 , 'foo' ) ;
25+ database2 . prepare ( insertSql ) . run ( 1 , 'world' ) ;
26+ return {
27+ database2,
28+ changeset : session . changeset ( )
29+ }
30+ }
31+
32+ const { database2, changeset } = prepareConflict ( ) ;
33+ const result = database2 . applyChangeset ( changeset , {
34+ conflict : SQLITE_CHANGESET_OMIT
35+ } ) ;
36+
37+ console . log ( database2 . prepare ( 'SELECT value from data ORDER BY key ASC' ) . all ( ) ) ;
You can’t perform that action at this time.
0 commit comments