@rocicorp/zero-sqlite3 1.0.15 → 1.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -368,6 +368,10 @@ struct sqlite3_api_routines {
368
368
  int (*set_clientdata)(sqlite3*, const char*, void*, void(*)(void*));
369
369
  /* Version 3.50.0 and later */
370
370
  int (*setlk_timeout)(sqlite3*,int,int);
371
+ /* Version 3.51.0 and later */
372
+ int (*set_errmsg)(sqlite3*,int,const char*);
373
+ int (*db_status64)(sqlite3*,int,sqlite3_int64*,sqlite3_int64*,int);
374
+
371
375
  };
372
376
 
373
377
  /*
@@ -703,6 +707,9 @@ typedef int (*sqlite3_loadext_entry)(
703
707
  #define sqlite3_set_clientdata sqlite3_api->set_clientdata
704
708
  /* Version 3.50.0 and later */
705
709
  #define sqlite3_setlk_timeout sqlite3_api->setlk_timeout
710
+ /* Version 3.51.0 and later */
711
+ #define sqlite3_set_errmsg sqlite3_api->set_errmsg
712
+ #define sqlite3_db_status64 sqlite3_api->db_status64
706
713
  #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
707
714
 
708
715
  #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
package/lib/database.js CHANGED
@@ -84,6 +84,7 @@ Database.prototype.exec = wrappers.exec;
84
84
  Database.prototype.close = wrappers.close;
85
85
  Database.prototype.defaultSafeIntegers = wrappers.defaultSafeIntegers;
86
86
  Database.prototype.unsafeMode = wrappers.unsafeMode;
87
+ Database.prototype.loadExtension = wrappers.loadExtension;
87
88
  Database.prototype[util.inspect] = require('./methods/inspect');
88
89
 
89
90
  // Export SQLITE_SCANSTAT_* constants from native addon
package/lib/index.d.ts CHANGED
@@ -96,7 +96,7 @@ declare namespace BetterSqlite3 {
96
96
  result?: ((total: T) => unknown) | undefined;
97
97
  },
98
98
  ): this;
99
- loadExtension(path: string): this;
99
+ loadExtension(path: string, entryPoint?: string): this;
100
100
  close(): this;
101
101
  defaultSafeIntegers(toggleState?: boolean): this;
102
102
  backup(destinationFile: string, options?: Database.BackupOptions): Promise<Database.BackupMetadata>;
@@ -25,6 +25,11 @@ exports.unsafeMode = function unsafeMode(...args) {
25
25
  return this;
26
26
  };
27
27
 
28
+ exports.loadExtension = function loadExtension(...args) {
29
+ this[cppdb].loadExtension(...args);
30
+ return this;
31
+ };
32
+
28
33
  exports.getters = {
29
34
  name: {
30
35
  get: function name() { return this[cppdb].name; },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rocicorp/zero-sqlite3",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
4
4
  "description": "better-sqlite3 on bedrock",
5
5
  "homepage": "https://github.com/rocicorp/zero-sqlite3",
6
6
  "author": "Rocicorp",
@@ -20,7 +20,7 @@
20
20
  "shell.js"
21
21
  ],
22
22
  "engines": {
23
- "node": "20.x || 22.x || 23.x || 24.x",
23
+ "node": "20.x || 22.x || 23.x || 24.x || 25.x",
24
24
  "bun": ">=1.1.0"
25
25
  },
26
26
  "types": "lib/index.d.ts",
@@ -30,7 +30,7 @@
30
30
  },
31
31
  "overrides": {
32
32
  "prebuild": {
33
- "node-abi": "4.13.1"
33
+ "node-abi": "^4.25.0"
34
34
  }
35
35
  },
36
36
  "devDependencies": {
@@ -46,7 +46,12 @@ class Backup;
46
46
  #include "objects/statement-iterator.cpp"
47
47
 
48
48
  NODE_MODULE_INIT(/* exports, context */) {
49
+ #if defined(NODE_MODULE_VERSION) && NODE_MODULE_VERSION >= 140
50
+ // Use Isolate::GetCurrent as stated in deprecation message within v8_context.h 13.9.72320122
51
+ v8::Isolate* isolate = v8::Isolate::GetCurrent();
52
+ #else
49
53
  v8::Isolate* isolate = context->GetIsolate();
54
+ #endif
50
55
  v8::HandleScope scope(isolate);
51
56
  Addon::ConfigureURI();
52
57
 
@@ -62,7 +67,7 @@ NODE_MODULE_INIT(/* exports, context */) {
62
67
  exports->Set(context, InternalizedFromLatin1(isolate, "Backup"), Backup::Init(isolate, data)).FromJust();
63
68
  exports->Set(context, InternalizedFromLatin1(isolate, "setErrorConstructor"), v8::FunctionTemplate::New(isolate, Addon::JS_setErrorConstructor, data)->GetFunction(context).ToLocalChecked()).FromJust();
64
69
 
65
- // Export SQLITE_SCANSTAT_* constants
70
+ // Export SQLITE_SCANSTAT_* constants
66
71
  exports->Set(context, InternalizedFromLatin1(isolate, "SQLITE_SCANSTAT_NLOOP"), v8::Int32::New(isolate, SQLITE_SCANSTAT_NLOOP)).FromJust();
67
72
  exports->Set(context, InternalizedFromLatin1(isolate, "SQLITE_SCANSTAT_NVISIT"), v8::Int32::New(isolate, SQLITE_SCANSTAT_NVISIT)).FromJust();
68
73
  exports->Set(context, InternalizedFromLatin1(isolate, "SQLITE_SCANSTAT_EST"), v8::Int32::New(isolate, SQLITE_SCANSTAT_EST)).FromJust();
@@ -132,6 +132,7 @@ INIT(Database::Init) {
132
132
  SetPrototypeMethod(isolate, data, t, "function", JS_function);
133
133
  SetPrototypeMethod(isolate, data, t, "aggregate", JS_aggregate);
134
134
  SetPrototypeMethod(isolate, data, t, "table", JS_table);
135
+ SetPrototypeMethod(isolate, data, t, "loadExtension", JS_loadExtension);
135
136
  SetPrototypeMethod(isolate, data, t, "close", JS_close);
136
137
  SetPrototypeMethod(isolate, data, t, "defaultSafeIntegers", JS_defaultSafeIntegers);
137
138
  SetPrototypeMethod(isolate, data, t, "unsafeMode", JS_unsafeMode);
@@ -171,7 +172,9 @@ NODE_METHOD(Database::JS_new) {
171
172
  sqlite3_busy_timeout(db_handle, timeout);
172
173
  sqlite3_limit(db_handle, SQLITE_LIMIT_LENGTH, MAX_BUFFER_SIZE < MAX_STRING_SIZE ? MAX_BUFFER_SIZE : MAX_STRING_SIZE);
173
174
  sqlite3_limit(db_handle, SQLITE_LIMIT_SQL_LENGTH, MAX_STRING_SIZE);
174
- int status = sqlite3_db_config(db_handle, SQLITE_DBCONFIG_DEFENSIVE, 1, NULL);
175
+ int status = sqlite3_db_config(db_handle, SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, 1, NULL);
176
+ assert(status == SQLITE_OK);
177
+ status = sqlite3_db_config(db_handle, SQLITE_DBCONFIG_DEFENSIVE, 1, NULL);
175
178
  assert(status == SQLITE_OK); ((void)status);
176
179
 
177
180
  if (node::Buffer::HasInstance(buffer) && !Deserialize(buffer.As<v8::Object>(), addon, db_handle, readonly)) {
@@ -206,6 +209,28 @@ NODE_METHOD(Database::JS_prepare) {
206
209
  if (!maybeStatement.IsEmpty()) info.GetReturnValue().Set(maybeStatement.ToLocalChecked());
207
210
  }
208
211
 
212
+ NODE_METHOD(Database::JS_loadExtension) {
213
+ Database* db = Unwrap<Database>(info.This());
214
+ REQUIRE_ARGUMENT_STRING(first, v8::Local<v8::String> filename);
215
+ v8::Local<v8::String> entryPoint;
216
+ if (info.Length() > 1) { REQUIRE_ARGUMENT_STRING(second, entryPoint); }
217
+ REQUIRE_DATABASE_OPEN(db);
218
+ REQUIRE_DATABASE_NOT_BUSY(db);
219
+ REQUIRE_DATABASE_NO_ITERATORS(db);
220
+ UseIsolate;
221
+ char* error;
222
+ int status = sqlite3_load_extension(
223
+ db->db_handle,
224
+ *v8::String::Utf8Value(isolate, filename),
225
+ entryPoint.IsEmpty() ? NULL : *v8::String::Utf8Value(isolate, entryPoint),
226
+ &error
227
+ );
228
+ if (status != SQLITE_OK) {
229
+ ThrowSqliteError(db->addon, error, status);
230
+ }
231
+ sqlite3_free(error);
232
+ }
233
+
209
234
  NODE_METHOD(Database::JS_exec) {
210
235
  Database* db = Unwrap<Database>(info.This());
211
236
  REQUIRE_ARGUMENT_STRING(first, v8::Local<v8::String> source);
@@ -383,10 +408,10 @@ NODE_METHOD(Database::JS_unsafeMode) {
383
408
  }
384
409
 
385
410
  NODE_GETTER(Database::JS_open) {
386
- info.GetReturnValue().Set(Unwrap<Database>(info.This())->open);
411
+ info.GetReturnValue().Set(Unwrap<Database>(PROPERTY_HOLDER(info))->open);
387
412
  }
388
413
 
389
414
  NODE_GETTER(Database::JS_inTransaction) {
390
- Database* db = Unwrap<Database>(info.This());
415
+ Database* db = Unwrap<Database>(PROPERTY_HOLDER(info));
391
416
  info.GetReturnValue().Set(db->open && !static_cast<bool>(sqlite3_get_autocommit(db->db_handle)));
392
417
  }
@@ -75,6 +75,7 @@ private:
75
75
  static NODE_METHOD(JS_function);
76
76
  static NODE_METHOD(JS_aggregate);
77
77
  static NODE_METHOD(JS_table);
78
+ static NODE_METHOD(JS_loadExtension);
78
79
  static NODE_METHOD(JS_close);
79
80
  static NODE_METHOD(JS_defaultSafeIntegers);
80
81
  static NODE_METHOD(JS_unsafeMode);
@@ -450,7 +450,7 @@ NODE_METHOD(Statement::JS_columns) {
450
450
  );
451
451
  columns.emplace_back(
452
452
  v8::Object::New(isolate,
453
- v8::Object::New(isolate)->GetPrototype(),
453
+ GET_PROTOTYPE(v8::Object::New(isolate)),
454
454
  keys.data(),
455
455
  values.data(),
456
456
  keys.size()
@@ -546,6 +546,6 @@ NODE_METHOD(Statement::JS_scanStatusReset) {
546
546
  }
547
547
 
548
548
  NODE_GETTER(Statement::JS_busy) {
549
- Statement* stmt = Unwrap<Statement>(info.This());
549
+ Statement* stmt = Unwrap<Statement>(PROPERTY_HOLDER(info));
550
550
  info.GetReturnValue().Set(stmt->alive && stmt->locked);
551
551
  }
@@ -33,10 +33,10 @@ private:
33
33
  };
34
34
 
35
35
  static bool IsPlainObject(v8::Isolate* isolate, v8::Local<v8::Object> obj) {
36
- v8::Local<v8::Value> proto = obj->GetPrototype();
36
+ v8::Local<v8::Value> proto = GET_PROTOTYPE(obj);
37
37
  v8::Local<v8::Context> ctx = obj->GetCreationContext().ToLocalChecked();
38
38
  ctx->Enter();
39
- v8::Local<v8::Value> baseProto = v8::Object::New(isolate)->GetPrototype();
39
+ v8::Local<v8::Value> baseProto = GET_PROTOTYPE(v8::Object::New(isolate));
40
40
  ctx->Exit();
41
41
  return proto->StrictEquals(baseProto) || proto->StrictEquals(v8::Null(isolate));
42
42
  }
package/src/util/data.cpp CHANGED
@@ -146,7 +146,7 @@ namespace Data {
146
146
  }
147
147
  return v8::Object::New(
148
148
  isolate,
149
- v8::Object::New(isolate)->GetPrototype(),
149
+ GET_PROTOTYPE(v8::Object::New(isolate)),
150
150
  keys.data(),
151
151
  values.data(),
152
152
  column_count
@@ -4,6 +4,26 @@
4
4
  #define NODE_GETTER(name) void name(v8::Local<v8::Name> _, const v8::PropertyCallbackInfo<v8::Value>& info)
5
5
  #define INIT(name) v8::Local<v8::Function> name(v8::Isolate* isolate, v8::Local<v8::External> data)
6
6
 
7
+ #if defined(V8_MAJOR_VERSION) && V8_MAJOR_VERSION >= 13
8
+ // v8::Object::GetPrototype has been deprecated. See http://crbug.com/333672197
9
+ #define GET_PROTOTYPE(obj) ((obj)->GetPrototypeV2())
10
+ #else
11
+ #define GET_PROTOTYPE(obj) ((obj)->GetPrototype())
12
+ #endif
13
+
14
+ // PropertyCallbackInfo::This() and Holder() were removed; use HolderV2().
15
+ // Tracking bug for V8 API removals: http://crbug.com/333672197
16
+ // V8 head has since restored Holder() and deprecated HolderV2():
17
+ // https://chromium.googlesource.com/v8/v8/+/main/include/v8-function-callback.h
18
+ // V8_INLINE Local<Object> Holder() const;
19
+ // V8_DEPRECATE_SOON("Use Holder().")
20
+ // V8_INLINE Local<Object> HolderV2() const;
21
+ #if defined(V8_MAJOR_VERSION) && V8_MAJOR_VERSION >= 13
22
+ #define PROPERTY_HOLDER(info) (info).HolderV2()
23
+ #else
24
+ #define PROPERTY_HOLDER(info) (info).This()
25
+ #endif
26
+
7
27
  #define EasyIsolate v8::Isolate* isolate = v8::Isolate::GetCurrent()
8
28
  #define OnlyIsolate info.GetIsolate()
9
29
  #define OnlyContext isolate->GetCurrentContext()
@@ -33,7 +33,7 @@ public:
33
33
  }
34
34
 
35
35
  return v8::Object::New(isolate,
36
- v8::Object::New(isolate)->GetPrototype(),
36
+ GET_PROTOTYPE(v8::Object::New(isolate)),
37
37
  keys.data(),
38
38
  values.data(),
39
39
  column_count
@@ -1,15 +0,0 @@
1
- diff --git a/deps/sqlite3/sqlite3.c b/deps/sqlite3/sqlite3.c
2
- index b1a807f..38bd1e6 100644
3
- --- a/deps/sqlite3/sqlite3.c
4
- +++ b/deps/sqlite3/sqlite3.c
5
- @@ -24887,8 +24887,8 @@ static const struct {
6
- /* 1 */ { 6, "minute", 7.7379e+12, 60.0 },
7
- /* 2 */ { 4, "hour", 1.2897e+11, 3600.0 },
8
- /* 3 */ { 3, "day", 5373485.0, 86400.0 },
9
- - /* 4 */ { 5, "month", 176546.0, 30.0*86400.0 },
10
- - /* 5 */ { 4, "year", 14713.0, 365.0*86400.0 },
11
- + /* 4 */ { 5, "month", 176546.0, 2592000.0 },
12
- + /* 5 */ { 4, "year", 14713.0, 31536000.0 },
13
- };
14
-
15
- /*