@rocicorp/zero-sqlite3 1.0.16 → 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.
- package/lib/database.js +1 -0
- package/lib/index.d.ts +1 -1
- package/lib/methods/wrappers.js +5 -0
- package/package.json +1 -1
- package/src/objects/database.cpp +26 -1
- package/src/objects/database.hpp +1 -0
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>;
|
package/lib/methods/wrappers.js
CHANGED
|
@@ -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
package/src/objects/database.cpp
CHANGED
|
@@ -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,
|
|
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);
|
package/src/objects/database.hpp
CHANGED
|
@@ -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);
|