@rljson/io-sqlite 0.0.10 → 0.0.12
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/LICENSE +21 -21
- package/README.architecture.md +9 -9
- package/README.blog.md +11 -11
- package/README.contributors.md +32 -32
- package/README.md +24 -24
- package/README.piano.md +42 -42
- package/README.public.md +15 -15
- package/README.trouble.md +23 -23
- package/package.json +69 -69
- package/dist/README.architecture.md +0 -9
- package/dist/README.blog.md +0 -11
- package/dist/README.contributors.md +0 -32
- package/dist/README.md +0 -24
- package/dist/README.piano.md +0 -42
- package/dist/README.public.md +0 -15
- package/dist/README.trouble.md +0 -23
- package/dist/example.d.ts +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/io-sqlite.d.ts +0 -45
- package/dist/io-sqlite.js +0 -955
- package/dist/src/example.ts +0 -7
package/dist/io-sqlite.js
DELETED
|
@@ -1,955 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
-
import { hip, hsh } from "@rljson/hash";
|
|
5
|
-
import { IsReady } from "@rljson/is-ready";
|
|
6
|
-
function getDefaultExportFromCjs(x) {
|
|
7
|
-
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
8
|
-
}
|
|
9
|
-
function getAugmentedNamespace(n) {
|
|
10
|
-
if (Object.prototype.hasOwnProperty.call(n, "__esModule")) return n;
|
|
11
|
-
var f = n.default;
|
|
12
|
-
if (typeof f == "function") {
|
|
13
|
-
var a = function a2() {
|
|
14
|
-
if (this instanceof a2) {
|
|
15
|
-
return Reflect.construct(f, arguments, this.constructor);
|
|
16
|
-
}
|
|
17
|
-
return f.apply(this, arguments);
|
|
18
|
-
};
|
|
19
|
-
a.prototype = f.prototype;
|
|
20
|
-
} else a = {};
|
|
21
|
-
Object.defineProperty(a, "__esModule", { value: true });
|
|
22
|
-
Object.keys(n).forEach(function(k) {
|
|
23
|
-
var d = Object.getOwnPropertyDescriptor(n, k);
|
|
24
|
-
Object.defineProperty(a, k, d.get ? d : {
|
|
25
|
-
enumerable: true,
|
|
26
|
-
get: function() {
|
|
27
|
-
return n[k];
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
return a;
|
|
32
|
-
}
|
|
33
|
-
var lib = { exports: {} };
|
|
34
|
-
function commonjsRequire(path) {
|
|
35
|
-
throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
|
|
36
|
-
}
|
|
37
|
-
const __viteBrowserExternal = {};
|
|
38
|
-
const __viteBrowserExternal$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
39
|
-
__proto__: null,
|
|
40
|
-
default: __viteBrowserExternal
|
|
41
|
-
}, Symbol.toStringTag, { value: "Module" }));
|
|
42
|
-
const require$$1 = /* @__PURE__ */ getAugmentedNamespace(__viteBrowserExternal$1);
|
|
43
|
-
var util = {};
|
|
44
|
-
var hasRequiredUtil;
|
|
45
|
-
function requireUtil() {
|
|
46
|
-
if (hasRequiredUtil) return util;
|
|
47
|
-
hasRequiredUtil = 1;
|
|
48
|
-
util.getBooleanOption = (options, key) => {
|
|
49
|
-
let value = false;
|
|
50
|
-
if (key in options && typeof (value = options[key]) !== "boolean") {
|
|
51
|
-
throw new TypeError(`Expected the "${key}" option to be a boolean`);
|
|
52
|
-
}
|
|
53
|
-
return value;
|
|
54
|
-
};
|
|
55
|
-
util.cppdb = Symbol();
|
|
56
|
-
util.inspect = Symbol.for("nodejs.util.inspect.custom");
|
|
57
|
-
return util;
|
|
58
|
-
}
|
|
59
|
-
var sqliteError;
|
|
60
|
-
var hasRequiredSqliteError;
|
|
61
|
-
function requireSqliteError() {
|
|
62
|
-
if (hasRequiredSqliteError) return sqliteError;
|
|
63
|
-
hasRequiredSqliteError = 1;
|
|
64
|
-
const descriptor = { value: "SqliteError", writable: true, enumerable: false, configurable: true };
|
|
65
|
-
function SqliteError(message, code) {
|
|
66
|
-
if (new.target !== SqliteError) {
|
|
67
|
-
return new SqliteError(message, code);
|
|
68
|
-
}
|
|
69
|
-
if (typeof code !== "string") {
|
|
70
|
-
throw new TypeError("Expected second argument to be a string");
|
|
71
|
-
}
|
|
72
|
-
Error.call(this, message);
|
|
73
|
-
descriptor.value = "" + message;
|
|
74
|
-
Object.defineProperty(this, "message", descriptor);
|
|
75
|
-
Error.captureStackTrace(this, SqliteError);
|
|
76
|
-
this.code = code;
|
|
77
|
-
}
|
|
78
|
-
Object.setPrototypeOf(SqliteError, Error);
|
|
79
|
-
Object.setPrototypeOf(SqliteError.prototype, Error.prototype);
|
|
80
|
-
Object.defineProperty(SqliteError.prototype, "name", descriptor);
|
|
81
|
-
sqliteError = SqliteError;
|
|
82
|
-
return sqliteError;
|
|
83
|
-
}
|
|
84
|
-
var bindings = { exports: {} };
|
|
85
|
-
var fileUriToPath_1;
|
|
86
|
-
var hasRequiredFileUriToPath;
|
|
87
|
-
function requireFileUriToPath() {
|
|
88
|
-
if (hasRequiredFileUriToPath) return fileUriToPath_1;
|
|
89
|
-
hasRequiredFileUriToPath = 1;
|
|
90
|
-
var sep = require$$1.sep || "/";
|
|
91
|
-
fileUriToPath_1 = fileUriToPath;
|
|
92
|
-
function fileUriToPath(uri) {
|
|
93
|
-
if ("string" != typeof uri || uri.length <= 7 || "file://" != uri.substring(0, 7)) {
|
|
94
|
-
throw new TypeError("must pass in a file:// URI to convert to a file path");
|
|
95
|
-
}
|
|
96
|
-
var rest = decodeURI(uri.substring(7));
|
|
97
|
-
var firstSlash = rest.indexOf("/");
|
|
98
|
-
var host = rest.substring(0, firstSlash);
|
|
99
|
-
var path = rest.substring(firstSlash + 1);
|
|
100
|
-
if ("localhost" == host) host = "";
|
|
101
|
-
if (host) {
|
|
102
|
-
host = sep + sep + host;
|
|
103
|
-
}
|
|
104
|
-
path = path.replace(/^(.+)\|/, "$1:");
|
|
105
|
-
if (sep == "\\") {
|
|
106
|
-
path = path.replace(/\//g, "\\");
|
|
107
|
-
}
|
|
108
|
-
if (/^.+\:/.test(path)) ;
|
|
109
|
-
else {
|
|
110
|
-
path = sep + path;
|
|
111
|
-
}
|
|
112
|
-
return host + path;
|
|
113
|
-
}
|
|
114
|
-
return fileUriToPath_1;
|
|
115
|
-
}
|
|
116
|
-
var hasRequiredBindings;
|
|
117
|
-
function requireBindings() {
|
|
118
|
-
if (hasRequiredBindings) return bindings.exports;
|
|
119
|
-
hasRequiredBindings = 1;
|
|
120
|
-
(function(module, exports) {
|
|
121
|
-
var fs = require$$1, path = require$$1, fileURLToPath = requireFileUriToPath(), join = path.join, dirname = path.dirname, exists = fs.accessSync && function(path2) {
|
|
122
|
-
try {
|
|
123
|
-
fs.accessSync(path2);
|
|
124
|
-
} catch (e) {
|
|
125
|
-
return false;
|
|
126
|
-
}
|
|
127
|
-
return true;
|
|
128
|
-
} || fs.existsSync || path.existsSync, defaults = {
|
|
129
|
-
arrow: process.env.NODE_BINDINGS_ARROW || " → ",
|
|
130
|
-
compiled: process.env.NODE_BINDINGS_COMPILED_DIR || "compiled",
|
|
131
|
-
platform: process.platform,
|
|
132
|
-
arch: process.arch,
|
|
133
|
-
nodePreGyp: "node-v" + process.versions.modules + "-" + process.platform + "-" + process.arch,
|
|
134
|
-
version: process.versions.node,
|
|
135
|
-
bindings: "bindings.node",
|
|
136
|
-
try: [
|
|
137
|
-
// node-gyp's linked version in the "build" dir
|
|
138
|
-
["module_root", "build", "bindings"],
|
|
139
|
-
// node-waf and gyp_addon (a.k.a node-gyp)
|
|
140
|
-
["module_root", "build", "Debug", "bindings"],
|
|
141
|
-
["module_root", "build", "Release", "bindings"],
|
|
142
|
-
// Debug files, for development (legacy behavior, remove for node v0.9)
|
|
143
|
-
["module_root", "out", "Debug", "bindings"],
|
|
144
|
-
["module_root", "Debug", "bindings"],
|
|
145
|
-
// Release files, but manually compiled (legacy behavior, remove for node v0.9)
|
|
146
|
-
["module_root", "out", "Release", "bindings"],
|
|
147
|
-
["module_root", "Release", "bindings"],
|
|
148
|
-
// Legacy from node-waf, node <= 0.4.x
|
|
149
|
-
["module_root", "build", "default", "bindings"],
|
|
150
|
-
// Production "Release" buildtype binary (meh...)
|
|
151
|
-
["module_root", "compiled", "version", "platform", "arch", "bindings"],
|
|
152
|
-
// node-qbs builds
|
|
153
|
-
["module_root", "addon-build", "release", "install-root", "bindings"],
|
|
154
|
-
["module_root", "addon-build", "debug", "install-root", "bindings"],
|
|
155
|
-
["module_root", "addon-build", "default", "install-root", "bindings"],
|
|
156
|
-
// node-pre-gyp path ./lib/binding/{node_abi}-{platform}-{arch}
|
|
157
|
-
["module_root", "lib", "binding", "nodePreGyp", "bindings"]
|
|
158
|
-
]
|
|
159
|
-
};
|
|
160
|
-
function bindings2(opts) {
|
|
161
|
-
if (typeof opts == "string") {
|
|
162
|
-
opts = { bindings: opts };
|
|
163
|
-
} else if (!opts) {
|
|
164
|
-
opts = {};
|
|
165
|
-
}
|
|
166
|
-
Object.keys(defaults).map(function(i2) {
|
|
167
|
-
if (!(i2 in opts)) opts[i2] = defaults[i2];
|
|
168
|
-
});
|
|
169
|
-
if (!opts.module_root) {
|
|
170
|
-
opts.module_root = exports.getRoot(exports.getFileName());
|
|
171
|
-
}
|
|
172
|
-
if (path.extname(opts.bindings) != ".node") {
|
|
173
|
-
opts.bindings += ".node";
|
|
174
|
-
}
|
|
175
|
-
var requireFunc = typeof __webpack_require__ === "function" ? __non_webpack_require__ : commonjsRequire;
|
|
176
|
-
var tries = [], i = 0, l = opts.try.length, n, b, err;
|
|
177
|
-
for (; i < l; i++) {
|
|
178
|
-
n = join.apply(
|
|
179
|
-
null,
|
|
180
|
-
opts.try[i].map(function(p) {
|
|
181
|
-
return opts[p] || p;
|
|
182
|
-
})
|
|
183
|
-
);
|
|
184
|
-
tries.push(n);
|
|
185
|
-
try {
|
|
186
|
-
b = opts.path ? requireFunc.resolve(n) : requireFunc(n);
|
|
187
|
-
if (!opts.path) {
|
|
188
|
-
b.path = n;
|
|
189
|
-
}
|
|
190
|
-
return b;
|
|
191
|
-
} catch (e) {
|
|
192
|
-
if (e.code !== "MODULE_NOT_FOUND" && e.code !== "QUALIFIED_PATH_RESOLUTION_FAILED" && !/not find/i.test(e.message)) {
|
|
193
|
-
throw e;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
err = new Error(
|
|
198
|
-
"Could not locate the bindings file. Tried:\n" + tries.map(function(a) {
|
|
199
|
-
return opts.arrow + a;
|
|
200
|
-
}).join("\n")
|
|
201
|
-
);
|
|
202
|
-
err.tries = tries;
|
|
203
|
-
throw err;
|
|
204
|
-
}
|
|
205
|
-
module.exports = exports = bindings2;
|
|
206
|
-
exports.getFileName = function getFileName(calling_file) {
|
|
207
|
-
var origPST = Error.prepareStackTrace, origSTL = Error.stackTraceLimit, dummy = {}, fileName;
|
|
208
|
-
Error.stackTraceLimit = 10;
|
|
209
|
-
Error.prepareStackTrace = function(e, st) {
|
|
210
|
-
for (var i = 0, l = st.length; i < l; i++) {
|
|
211
|
-
fileName = st[i].getFileName();
|
|
212
|
-
if (fileName !== __filename) {
|
|
213
|
-
if (calling_file) {
|
|
214
|
-
if (fileName !== calling_file) {
|
|
215
|
-
return;
|
|
216
|
-
}
|
|
217
|
-
} else {
|
|
218
|
-
return;
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
};
|
|
223
|
-
Error.captureStackTrace(dummy);
|
|
224
|
-
dummy.stack;
|
|
225
|
-
Error.prepareStackTrace = origPST;
|
|
226
|
-
Error.stackTraceLimit = origSTL;
|
|
227
|
-
var fileSchema = "file://";
|
|
228
|
-
if (fileName.indexOf(fileSchema) === 0) {
|
|
229
|
-
fileName = fileURLToPath(fileName);
|
|
230
|
-
}
|
|
231
|
-
return fileName;
|
|
232
|
-
};
|
|
233
|
-
exports.getRoot = function getRoot(file) {
|
|
234
|
-
var dir = dirname(file), prev;
|
|
235
|
-
while (true) {
|
|
236
|
-
if (dir === ".") {
|
|
237
|
-
dir = process.cwd();
|
|
238
|
-
}
|
|
239
|
-
if (exists(join(dir, "package.json")) || exists(join(dir, "node_modules"))) {
|
|
240
|
-
return dir;
|
|
241
|
-
}
|
|
242
|
-
if (prev === dir) {
|
|
243
|
-
throw new Error(
|
|
244
|
-
'Could not find module root given file: "' + file + '". Do you have a `package.json` file? '
|
|
245
|
-
);
|
|
246
|
-
}
|
|
247
|
-
prev = dir;
|
|
248
|
-
dir = join(dir, "..");
|
|
249
|
-
}
|
|
250
|
-
};
|
|
251
|
-
})(bindings, bindings.exports);
|
|
252
|
-
return bindings.exports;
|
|
253
|
-
}
|
|
254
|
-
var wrappers = {};
|
|
255
|
-
var hasRequiredWrappers;
|
|
256
|
-
function requireWrappers() {
|
|
257
|
-
if (hasRequiredWrappers) return wrappers;
|
|
258
|
-
hasRequiredWrappers = 1;
|
|
259
|
-
const { cppdb } = requireUtil();
|
|
260
|
-
wrappers.prepare = function prepare(sql) {
|
|
261
|
-
return this[cppdb].prepare(sql, this, false);
|
|
262
|
-
};
|
|
263
|
-
wrappers.exec = function exec(sql) {
|
|
264
|
-
this[cppdb].exec(sql);
|
|
265
|
-
return this;
|
|
266
|
-
};
|
|
267
|
-
wrappers.close = function close() {
|
|
268
|
-
this[cppdb].close();
|
|
269
|
-
return this;
|
|
270
|
-
};
|
|
271
|
-
wrappers.loadExtension = function loadExtension(...args) {
|
|
272
|
-
this[cppdb].loadExtension(...args);
|
|
273
|
-
return this;
|
|
274
|
-
};
|
|
275
|
-
wrappers.defaultSafeIntegers = function defaultSafeIntegers(...args) {
|
|
276
|
-
this[cppdb].defaultSafeIntegers(...args);
|
|
277
|
-
return this;
|
|
278
|
-
};
|
|
279
|
-
wrappers.unsafeMode = function unsafeMode(...args) {
|
|
280
|
-
this[cppdb].unsafeMode(...args);
|
|
281
|
-
return this;
|
|
282
|
-
};
|
|
283
|
-
wrappers.getters = {
|
|
284
|
-
name: {
|
|
285
|
-
get: function name() {
|
|
286
|
-
return this[cppdb].name;
|
|
287
|
-
},
|
|
288
|
-
enumerable: true
|
|
289
|
-
},
|
|
290
|
-
open: {
|
|
291
|
-
get: function open() {
|
|
292
|
-
return this[cppdb].open;
|
|
293
|
-
},
|
|
294
|
-
enumerable: true
|
|
295
|
-
},
|
|
296
|
-
inTransaction: {
|
|
297
|
-
get: function inTransaction() {
|
|
298
|
-
return this[cppdb].inTransaction;
|
|
299
|
-
},
|
|
300
|
-
enumerable: true
|
|
301
|
-
},
|
|
302
|
-
readonly: {
|
|
303
|
-
get: function readonly() {
|
|
304
|
-
return this[cppdb].readonly;
|
|
305
|
-
},
|
|
306
|
-
enumerable: true
|
|
307
|
-
},
|
|
308
|
-
memory: {
|
|
309
|
-
get: function memory() {
|
|
310
|
-
return this[cppdb].memory;
|
|
311
|
-
},
|
|
312
|
-
enumerable: true
|
|
313
|
-
}
|
|
314
|
-
};
|
|
315
|
-
return wrappers;
|
|
316
|
-
}
|
|
317
|
-
var transaction;
|
|
318
|
-
var hasRequiredTransaction;
|
|
319
|
-
function requireTransaction() {
|
|
320
|
-
if (hasRequiredTransaction) return transaction;
|
|
321
|
-
hasRequiredTransaction = 1;
|
|
322
|
-
const { cppdb } = requireUtil();
|
|
323
|
-
const controllers = /* @__PURE__ */ new WeakMap();
|
|
324
|
-
transaction = function transaction2(fn) {
|
|
325
|
-
if (typeof fn !== "function") throw new TypeError("Expected first argument to be a function");
|
|
326
|
-
const db = this[cppdb];
|
|
327
|
-
const controller = getController(db, this);
|
|
328
|
-
const { apply } = Function.prototype;
|
|
329
|
-
const properties = {
|
|
330
|
-
default: { value: wrapTransaction(apply, fn, db, controller.default) },
|
|
331
|
-
deferred: { value: wrapTransaction(apply, fn, db, controller.deferred) },
|
|
332
|
-
immediate: { value: wrapTransaction(apply, fn, db, controller.immediate) },
|
|
333
|
-
exclusive: { value: wrapTransaction(apply, fn, db, controller.exclusive) },
|
|
334
|
-
database: { value: this, enumerable: true }
|
|
335
|
-
};
|
|
336
|
-
Object.defineProperties(properties.default.value, properties);
|
|
337
|
-
Object.defineProperties(properties.deferred.value, properties);
|
|
338
|
-
Object.defineProperties(properties.immediate.value, properties);
|
|
339
|
-
Object.defineProperties(properties.exclusive.value, properties);
|
|
340
|
-
return properties.default.value;
|
|
341
|
-
};
|
|
342
|
-
const getController = (db, self) => {
|
|
343
|
-
let controller = controllers.get(db);
|
|
344
|
-
if (!controller) {
|
|
345
|
-
const shared = {
|
|
346
|
-
commit: db.prepare("COMMIT", self, false),
|
|
347
|
-
rollback: db.prepare("ROLLBACK", self, false),
|
|
348
|
-
savepoint: db.prepare("SAVEPOINT ` _bs3. `", self, false),
|
|
349
|
-
release: db.prepare("RELEASE ` _bs3. `", self, false),
|
|
350
|
-
rollbackTo: db.prepare("ROLLBACK TO ` _bs3. `", self, false)
|
|
351
|
-
};
|
|
352
|
-
controllers.set(db, controller = {
|
|
353
|
-
default: Object.assign({ begin: db.prepare("BEGIN", self, false) }, shared),
|
|
354
|
-
deferred: Object.assign({ begin: db.prepare("BEGIN DEFERRED", self, false) }, shared),
|
|
355
|
-
immediate: Object.assign({ begin: db.prepare("BEGIN IMMEDIATE", self, false) }, shared),
|
|
356
|
-
exclusive: Object.assign({ begin: db.prepare("BEGIN EXCLUSIVE", self, false) }, shared)
|
|
357
|
-
});
|
|
358
|
-
}
|
|
359
|
-
return controller;
|
|
360
|
-
};
|
|
361
|
-
const wrapTransaction = (apply, fn, db, { begin, commit, rollback, savepoint, release, rollbackTo }) => function sqliteTransaction() {
|
|
362
|
-
let before, after, undo;
|
|
363
|
-
if (db.inTransaction) {
|
|
364
|
-
before = savepoint;
|
|
365
|
-
after = release;
|
|
366
|
-
undo = rollbackTo;
|
|
367
|
-
} else {
|
|
368
|
-
before = begin;
|
|
369
|
-
after = commit;
|
|
370
|
-
undo = rollback;
|
|
371
|
-
}
|
|
372
|
-
before.run();
|
|
373
|
-
try {
|
|
374
|
-
const result = apply.call(fn, this, arguments);
|
|
375
|
-
after.run();
|
|
376
|
-
return result;
|
|
377
|
-
} catch (ex) {
|
|
378
|
-
if (db.inTransaction) {
|
|
379
|
-
undo.run();
|
|
380
|
-
if (undo !== rollback) after.run();
|
|
381
|
-
}
|
|
382
|
-
throw ex;
|
|
383
|
-
}
|
|
384
|
-
};
|
|
385
|
-
return transaction;
|
|
386
|
-
}
|
|
387
|
-
var pragma;
|
|
388
|
-
var hasRequiredPragma;
|
|
389
|
-
function requirePragma() {
|
|
390
|
-
if (hasRequiredPragma) return pragma;
|
|
391
|
-
hasRequiredPragma = 1;
|
|
392
|
-
const { getBooleanOption, cppdb } = requireUtil();
|
|
393
|
-
pragma = function pragma2(source, options) {
|
|
394
|
-
if (options == null) options = {};
|
|
395
|
-
if (typeof source !== "string") throw new TypeError("Expected first argument to be a string");
|
|
396
|
-
if (typeof options !== "object") throw new TypeError("Expected second argument to be an options object");
|
|
397
|
-
const simple = getBooleanOption(options, "simple");
|
|
398
|
-
const stmt = this[cppdb].prepare(`PRAGMA ${source}`, this, true);
|
|
399
|
-
return simple ? stmt.pluck().get() : stmt.all();
|
|
400
|
-
};
|
|
401
|
-
return pragma;
|
|
402
|
-
}
|
|
403
|
-
var backup;
|
|
404
|
-
var hasRequiredBackup;
|
|
405
|
-
function requireBackup() {
|
|
406
|
-
if (hasRequiredBackup) return backup;
|
|
407
|
-
hasRequiredBackup = 1;
|
|
408
|
-
const fs = require$$1;
|
|
409
|
-
const path = require$$1;
|
|
410
|
-
const { promisify } = require$$1;
|
|
411
|
-
const { cppdb } = requireUtil();
|
|
412
|
-
const fsAccess = promisify(fs.access);
|
|
413
|
-
backup = async function backup2(filename, options) {
|
|
414
|
-
if (options == null) options = {};
|
|
415
|
-
if (typeof filename !== "string") throw new TypeError("Expected first argument to be a string");
|
|
416
|
-
if (typeof options !== "object") throw new TypeError("Expected second argument to be an options object");
|
|
417
|
-
filename = filename.trim();
|
|
418
|
-
const attachedName = "attached" in options ? options.attached : "main";
|
|
419
|
-
const handler = "progress" in options ? options.progress : null;
|
|
420
|
-
if (!filename) throw new TypeError("Backup filename cannot be an empty string");
|
|
421
|
-
if (filename === ":memory:") throw new TypeError('Invalid backup filename ":memory:"');
|
|
422
|
-
if (typeof attachedName !== "string") throw new TypeError('Expected the "attached" option to be a string');
|
|
423
|
-
if (!attachedName) throw new TypeError('The "attached" option cannot be an empty string');
|
|
424
|
-
if (handler != null && typeof handler !== "function") throw new TypeError('Expected the "progress" option to be a function');
|
|
425
|
-
await fsAccess(path.dirname(filename)).catch(() => {
|
|
426
|
-
throw new TypeError("Cannot save backup because the directory does not exist");
|
|
427
|
-
});
|
|
428
|
-
const isNewFile = await fsAccess(filename).then(() => false, () => true);
|
|
429
|
-
return runBackup(this[cppdb].backup(this, attachedName, filename, isNewFile), handler || null);
|
|
430
|
-
};
|
|
431
|
-
const runBackup = (backup2, handler) => {
|
|
432
|
-
let rate = 0;
|
|
433
|
-
let useDefault = true;
|
|
434
|
-
return new Promise((resolve, reject) => {
|
|
435
|
-
setImmediate(function step() {
|
|
436
|
-
try {
|
|
437
|
-
const progress = backup2.transfer(rate);
|
|
438
|
-
if (!progress.remainingPages) {
|
|
439
|
-
backup2.close();
|
|
440
|
-
resolve(progress);
|
|
441
|
-
return;
|
|
442
|
-
}
|
|
443
|
-
if (useDefault) {
|
|
444
|
-
useDefault = false;
|
|
445
|
-
rate = 100;
|
|
446
|
-
}
|
|
447
|
-
if (handler) {
|
|
448
|
-
const ret = handler(progress);
|
|
449
|
-
if (ret !== void 0) {
|
|
450
|
-
if (typeof ret === "number" && ret === ret) rate = Math.max(0, Math.min(2147483647, Math.round(ret)));
|
|
451
|
-
else throw new TypeError("Expected progress callback to return a number or undefined");
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
setImmediate(step);
|
|
455
|
-
} catch (err) {
|
|
456
|
-
backup2.close();
|
|
457
|
-
reject(err);
|
|
458
|
-
}
|
|
459
|
-
});
|
|
460
|
-
});
|
|
461
|
-
};
|
|
462
|
-
return backup;
|
|
463
|
-
}
|
|
464
|
-
var serialize;
|
|
465
|
-
var hasRequiredSerialize;
|
|
466
|
-
function requireSerialize() {
|
|
467
|
-
if (hasRequiredSerialize) return serialize;
|
|
468
|
-
hasRequiredSerialize = 1;
|
|
469
|
-
const { cppdb } = requireUtil();
|
|
470
|
-
serialize = function serialize2(options) {
|
|
471
|
-
if (options == null) options = {};
|
|
472
|
-
if (typeof options !== "object") throw new TypeError("Expected first argument to be an options object");
|
|
473
|
-
const attachedName = "attached" in options ? options.attached : "main";
|
|
474
|
-
if (typeof attachedName !== "string") throw new TypeError('Expected the "attached" option to be a string');
|
|
475
|
-
if (!attachedName) throw new TypeError('The "attached" option cannot be an empty string');
|
|
476
|
-
return this[cppdb].serialize(attachedName);
|
|
477
|
-
};
|
|
478
|
-
return serialize;
|
|
479
|
-
}
|
|
480
|
-
var _function;
|
|
481
|
-
var hasRequired_function;
|
|
482
|
-
function require_function() {
|
|
483
|
-
if (hasRequired_function) return _function;
|
|
484
|
-
hasRequired_function = 1;
|
|
485
|
-
const { getBooleanOption, cppdb } = requireUtil();
|
|
486
|
-
_function = function defineFunction(name, options, fn) {
|
|
487
|
-
if (options == null) options = {};
|
|
488
|
-
if (typeof options === "function") {
|
|
489
|
-
fn = options;
|
|
490
|
-
options = {};
|
|
491
|
-
}
|
|
492
|
-
if (typeof name !== "string") throw new TypeError("Expected first argument to be a string");
|
|
493
|
-
if (typeof fn !== "function") throw new TypeError("Expected last argument to be a function");
|
|
494
|
-
if (typeof options !== "object") throw new TypeError("Expected second argument to be an options object");
|
|
495
|
-
if (!name) throw new TypeError("User-defined function name cannot be an empty string");
|
|
496
|
-
const safeIntegers = "safeIntegers" in options ? +getBooleanOption(options, "safeIntegers") : 2;
|
|
497
|
-
const deterministic = getBooleanOption(options, "deterministic");
|
|
498
|
-
const directOnly = getBooleanOption(options, "directOnly");
|
|
499
|
-
const varargs = getBooleanOption(options, "varargs");
|
|
500
|
-
let argCount = -1;
|
|
501
|
-
if (!varargs) {
|
|
502
|
-
argCount = fn.length;
|
|
503
|
-
if (!Number.isInteger(argCount) || argCount < 0) throw new TypeError("Expected function.length to be a positive integer");
|
|
504
|
-
if (argCount > 100) throw new RangeError("User-defined functions cannot have more than 100 arguments");
|
|
505
|
-
}
|
|
506
|
-
this[cppdb].function(fn, name, argCount, safeIntegers, deterministic, directOnly);
|
|
507
|
-
return this;
|
|
508
|
-
};
|
|
509
|
-
return _function;
|
|
510
|
-
}
|
|
511
|
-
var aggregate;
|
|
512
|
-
var hasRequiredAggregate;
|
|
513
|
-
function requireAggregate() {
|
|
514
|
-
if (hasRequiredAggregate) return aggregate;
|
|
515
|
-
hasRequiredAggregate = 1;
|
|
516
|
-
const { getBooleanOption, cppdb } = requireUtil();
|
|
517
|
-
aggregate = function defineAggregate(name, options) {
|
|
518
|
-
if (typeof name !== "string") throw new TypeError("Expected first argument to be a string");
|
|
519
|
-
if (typeof options !== "object" || options === null) throw new TypeError("Expected second argument to be an options object");
|
|
520
|
-
if (!name) throw new TypeError("User-defined function name cannot be an empty string");
|
|
521
|
-
const start = "start" in options ? options.start : null;
|
|
522
|
-
const step = getFunctionOption(options, "step", true);
|
|
523
|
-
const inverse = getFunctionOption(options, "inverse", false);
|
|
524
|
-
const result = getFunctionOption(options, "result", false);
|
|
525
|
-
const safeIntegers = "safeIntegers" in options ? +getBooleanOption(options, "safeIntegers") : 2;
|
|
526
|
-
const deterministic = getBooleanOption(options, "deterministic");
|
|
527
|
-
const directOnly = getBooleanOption(options, "directOnly");
|
|
528
|
-
const varargs = getBooleanOption(options, "varargs");
|
|
529
|
-
let argCount = -1;
|
|
530
|
-
if (!varargs) {
|
|
531
|
-
argCount = Math.max(getLength(step), inverse ? getLength(inverse) : 0);
|
|
532
|
-
if (argCount > 0) argCount -= 1;
|
|
533
|
-
if (argCount > 100) throw new RangeError("User-defined functions cannot have more than 100 arguments");
|
|
534
|
-
}
|
|
535
|
-
this[cppdb].aggregate(start, step, inverse, result, name, argCount, safeIntegers, deterministic, directOnly);
|
|
536
|
-
return this;
|
|
537
|
-
};
|
|
538
|
-
const getFunctionOption = (options, key, required) => {
|
|
539
|
-
const value = key in options ? options[key] : null;
|
|
540
|
-
if (typeof value === "function") return value;
|
|
541
|
-
if (value != null) throw new TypeError(`Expected the "${key}" option to be a function`);
|
|
542
|
-
if (required) throw new TypeError(`Missing required option "${key}"`);
|
|
543
|
-
return null;
|
|
544
|
-
};
|
|
545
|
-
const getLength = ({ length }) => {
|
|
546
|
-
if (Number.isInteger(length) && length >= 0) return length;
|
|
547
|
-
throw new TypeError("Expected function.length to be a positive integer");
|
|
548
|
-
};
|
|
549
|
-
return aggregate;
|
|
550
|
-
}
|
|
551
|
-
var table;
|
|
552
|
-
var hasRequiredTable;
|
|
553
|
-
function requireTable() {
|
|
554
|
-
if (hasRequiredTable) return table;
|
|
555
|
-
hasRequiredTable = 1;
|
|
556
|
-
const { cppdb } = requireUtil();
|
|
557
|
-
table = function defineTable(name, factory) {
|
|
558
|
-
if (typeof name !== "string") throw new TypeError("Expected first argument to be a string");
|
|
559
|
-
if (!name) throw new TypeError("Virtual table module name cannot be an empty string");
|
|
560
|
-
let eponymous = false;
|
|
561
|
-
if (typeof factory === "object" && factory !== null) {
|
|
562
|
-
eponymous = true;
|
|
563
|
-
factory = defer(parseTableDefinition(factory, "used", name));
|
|
564
|
-
} else {
|
|
565
|
-
if (typeof factory !== "function") throw new TypeError("Expected second argument to be a function or a table definition object");
|
|
566
|
-
factory = wrapFactory(factory);
|
|
567
|
-
}
|
|
568
|
-
this[cppdb].table(factory, name, eponymous);
|
|
569
|
-
return this;
|
|
570
|
-
};
|
|
571
|
-
function wrapFactory(factory) {
|
|
572
|
-
return function virtualTableFactory(moduleName, databaseName, tableName, ...args) {
|
|
573
|
-
const thisObject = {
|
|
574
|
-
module: moduleName,
|
|
575
|
-
database: databaseName,
|
|
576
|
-
table: tableName
|
|
577
|
-
};
|
|
578
|
-
const def = apply.call(factory, thisObject, args);
|
|
579
|
-
if (typeof def !== "object" || def === null) {
|
|
580
|
-
throw new TypeError(`Virtual table module "${moduleName}" did not return a table definition object`);
|
|
581
|
-
}
|
|
582
|
-
return parseTableDefinition(def, "returned", moduleName);
|
|
583
|
-
};
|
|
584
|
-
}
|
|
585
|
-
function parseTableDefinition(def, verb, moduleName) {
|
|
586
|
-
if (!hasOwnProperty.call(def, "rows")) {
|
|
587
|
-
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition without a "rows" property`);
|
|
588
|
-
}
|
|
589
|
-
if (!hasOwnProperty.call(def, "columns")) {
|
|
590
|
-
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition without a "columns" property`);
|
|
591
|
-
}
|
|
592
|
-
const rows = def.rows;
|
|
593
|
-
if (typeof rows !== "function" || Object.getPrototypeOf(rows) !== GeneratorFunctionPrototype) {
|
|
594
|
-
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "rows" property (should be a generator function)`);
|
|
595
|
-
}
|
|
596
|
-
let columns = def.columns;
|
|
597
|
-
if (!Array.isArray(columns) || !(columns = [...columns]).every((x) => typeof x === "string")) {
|
|
598
|
-
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "columns" property (should be an array of strings)`);
|
|
599
|
-
}
|
|
600
|
-
if (columns.length !== new Set(columns).size) {
|
|
601
|
-
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with duplicate column names`);
|
|
602
|
-
}
|
|
603
|
-
if (!columns.length) {
|
|
604
|
-
throw new RangeError(`Virtual table module "${moduleName}" ${verb} a table definition with zero columns`);
|
|
605
|
-
}
|
|
606
|
-
let parameters;
|
|
607
|
-
if (hasOwnProperty.call(def, "parameters")) {
|
|
608
|
-
parameters = def.parameters;
|
|
609
|
-
if (!Array.isArray(parameters) || !(parameters = [...parameters]).every((x) => typeof x === "string")) {
|
|
610
|
-
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "parameters" property (should be an array of strings)`);
|
|
611
|
-
}
|
|
612
|
-
} else {
|
|
613
|
-
parameters = inferParameters(rows);
|
|
614
|
-
}
|
|
615
|
-
if (parameters.length !== new Set(parameters).size) {
|
|
616
|
-
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with duplicate parameter names`);
|
|
617
|
-
}
|
|
618
|
-
if (parameters.length > 32) {
|
|
619
|
-
throw new RangeError(`Virtual table module "${moduleName}" ${verb} a table definition with more than the maximum number of 32 parameters`);
|
|
620
|
-
}
|
|
621
|
-
for (const parameter of parameters) {
|
|
622
|
-
if (columns.includes(parameter)) {
|
|
623
|
-
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with column "${parameter}" which was ambiguously defined as both a column and parameter`);
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
let safeIntegers = 2;
|
|
627
|
-
if (hasOwnProperty.call(def, "safeIntegers")) {
|
|
628
|
-
const bool = def.safeIntegers;
|
|
629
|
-
if (typeof bool !== "boolean") {
|
|
630
|
-
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "safeIntegers" property (should be a boolean)`);
|
|
631
|
-
}
|
|
632
|
-
safeIntegers = +bool;
|
|
633
|
-
}
|
|
634
|
-
let directOnly = false;
|
|
635
|
-
if (hasOwnProperty.call(def, "directOnly")) {
|
|
636
|
-
directOnly = def.directOnly;
|
|
637
|
-
if (typeof directOnly !== "boolean") {
|
|
638
|
-
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "directOnly" property (should be a boolean)`);
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
|
-
const columnDefinitions = [
|
|
642
|
-
...parameters.map(identifier).map((str) => `${str} HIDDEN`),
|
|
643
|
-
...columns.map(identifier)
|
|
644
|
-
];
|
|
645
|
-
return [
|
|
646
|
-
`CREATE TABLE x(${columnDefinitions.join(", ")});`,
|
|
647
|
-
wrapGenerator(rows, new Map(columns.map((x, i) => [x, parameters.length + i])), moduleName),
|
|
648
|
-
parameters,
|
|
649
|
-
safeIntegers,
|
|
650
|
-
directOnly
|
|
651
|
-
];
|
|
652
|
-
}
|
|
653
|
-
function wrapGenerator(generator, columnMap, moduleName) {
|
|
654
|
-
return function* virtualTable(...args) {
|
|
655
|
-
const output = args.map((x) => Buffer.isBuffer(x) ? Buffer.from(x) : x);
|
|
656
|
-
for (let i = 0; i < columnMap.size; ++i) {
|
|
657
|
-
output.push(null);
|
|
658
|
-
}
|
|
659
|
-
for (const row of generator(...args)) {
|
|
660
|
-
if (Array.isArray(row)) {
|
|
661
|
-
extractRowArray(row, output, columnMap.size, moduleName);
|
|
662
|
-
yield output;
|
|
663
|
-
} else if (typeof row === "object" && row !== null) {
|
|
664
|
-
extractRowObject(row, output, columnMap, moduleName);
|
|
665
|
-
yield output;
|
|
666
|
-
} else {
|
|
667
|
-
throw new TypeError(`Virtual table module "${moduleName}" yielded something that isn't a valid row object`);
|
|
668
|
-
}
|
|
669
|
-
}
|
|
670
|
-
};
|
|
671
|
-
}
|
|
672
|
-
function extractRowArray(row, output, columnCount, moduleName) {
|
|
673
|
-
if (row.length !== columnCount) {
|
|
674
|
-
throw new TypeError(`Virtual table module "${moduleName}" yielded a row with an incorrect number of columns`);
|
|
675
|
-
}
|
|
676
|
-
const offset = output.length - columnCount;
|
|
677
|
-
for (let i = 0; i < columnCount; ++i) {
|
|
678
|
-
output[i + offset] = row[i];
|
|
679
|
-
}
|
|
680
|
-
}
|
|
681
|
-
function extractRowObject(row, output, columnMap, moduleName) {
|
|
682
|
-
let count = 0;
|
|
683
|
-
for (const key of Object.keys(row)) {
|
|
684
|
-
const index = columnMap.get(key);
|
|
685
|
-
if (index === void 0) {
|
|
686
|
-
throw new TypeError(`Virtual table module "${moduleName}" yielded a row with an undeclared column "${key}"`);
|
|
687
|
-
}
|
|
688
|
-
output[index] = row[key];
|
|
689
|
-
count += 1;
|
|
690
|
-
}
|
|
691
|
-
if (count !== columnMap.size) {
|
|
692
|
-
throw new TypeError(`Virtual table module "${moduleName}" yielded a row with missing columns`);
|
|
693
|
-
}
|
|
694
|
-
}
|
|
695
|
-
function inferParameters({ length }) {
|
|
696
|
-
if (!Number.isInteger(length) || length < 0) {
|
|
697
|
-
throw new TypeError("Expected function.length to be a positive integer");
|
|
698
|
-
}
|
|
699
|
-
const params = [];
|
|
700
|
-
for (let i = 0; i < length; ++i) {
|
|
701
|
-
params.push(`$${i + 1}`);
|
|
702
|
-
}
|
|
703
|
-
return params;
|
|
704
|
-
}
|
|
705
|
-
const { hasOwnProperty } = Object.prototype;
|
|
706
|
-
const { apply } = Function.prototype;
|
|
707
|
-
const GeneratorFunctionPrototype = Object.getPrototypeOf(function* () {
|
|
708
|
-
});
|
|
709
|
-
const identifier = (str) => `"${str.replace(/"/g, '""')}"`;
|
|
710
|
-
const defer = (x) => () => x;
|
|
711
|
-
return table;
|
|
712
|
-
}
|
|
713
|
-
var inspect;
|
|
714
|
-
var hasRequiredInspect;
|
|
715
|
-
function requireInspect() {
|
|
716
|
-
if (hasRequiredInspect) return inspect;
|
|
717
|
-
hasRequiredInspect = 1;
|
|
718
|
-
const DatabaseInspection = function Database2() {
|
|
719
|
-
};
|
|
720
|
-
inspect = function inspect2(depth, opts) {
|
|
721
|
-
return Object.assign(new DatabaseInspection(), this);
|
|
722
|
-
};
|
|
723
|
-
return inspect;
|
|
724
|
-
}
|
|
725
|
-
var database;
|
|
726
|
-
var hasRequiredDatabase;
|
|
727
|
-
function requireDatabase() {
|
|
728
|
-
if (hasRequiredDatabase) return database;
|
|
729
|
-
hasRequiredDatabase = 1;
|
|
730
|
-
const fs = require$$1;
|
|
731
|
-
const path = require$$1;
|
|
732
|
-
const util2 = requireUtil();
|
|
733
|
-
const SqliteError = requireSqliteError();
|
|
734
|
-
let DEFAULT_ADDON;
|
|
735
|
-
function Database2(filenameGiven, options) {
|
|
736
|
-
if (new.target == null) {
|
|
737
|
-
return new Database2(filenameGiven, options);
|
|
738
|
-
}
|
|
739
|
-
let buffer;
|
|
740
|
-
if (Buffer.isBuffer(filenameGiven)) {
|
|
741
|
-
buffer = filenameGiven;
|
|
742
|
-
filenameGiven = ":memory:";
|
|
743
|
-
}
|
|
744
|
-
if (filenameGiven == null) filenameGiven = "";
|
|
745
|
-
if (options == null) options = {};
|
|
746
|
-
if (typeof filenameGiven !== "string") throw new TypeError("Expected first argument to be a string");
|
|
747
|
-
if (typeof options !== "object") throw new TypeError("Expected second argument to be an options object");
|
|
748
|
-
if ("readOnly" in options) throw new TypeError('Misspelled option "readOnly" should be "readonly"');
|
|
749
|
-
if ("memory" in options) throw new TypeError('Option "memory" was removed in v7.0.0 (use ":memory:" filename instead)');
|
|
750
|
-
const filename = filenameGiven.trim();
|
|
751
|
-
const anonymous = filename === "" || filename === ":memory:";
|
|
752
|
-
const readonly = util2.getBooleanOption(options, "readonly");
|
|
753
|
-
const fileMustExist = util2.getBooleanOption(options, "fileMustExist");
|
|
754
|
-
const timeout = "timeout" in options ? options.timeout : 5e3;
|
|
755
|
-
const verbose = "verbose" in options ? options.verbose : null;
|
|
756
|
-
const nativeBinding = "nativeBinding" in options ? options.nativeBinding : null;
|
|
757
|
-
if (readonly && anonymous && !buffer) throw new TypeError("In-memory/temporary databases cannot be readonly");
|
|
758
|
-
if (!Number.isInteger(timeout) || timeout < 0) throw new TypeError('Expected the "timeout" option to be a positive integer');
|
|
759
|
-
if (timeout > 2147483647) throw new RangeError('Option "timeout" cannot be greater than 2147483647');
|
|
760
|
-
if (verbose != null && typeof verbose !== "function") throw new TypeError('Expected the "verbose" option to be a function');
|
|
761
|
-
if (nativeBinding != null && typeof nativeBinding !== "string" && typeof nativeBinding !== "object") throw new TypeError('Expected the "nativeBinding" option to be a string or addon object');
|
|
762
|
-
let addon;
|
|
763
|
-
if (nativeBinding == null) {
|
|
764
|
-
addon = DEFAULT_ADDON || (DEFAULT_ADDON = requireBindings()("better_sqlite3.node"));
|
|
765
|
-
} else if (typeof nativeBinding === "string") {
|
|
766
|
-
const requireFunc = typeof __non_webpack_require__ === "function" ? __non_webpack_require__ : commonjsRequire;
|
|
767
|
-
addon = requireFunc(path.resolve(nativeBinding).replace(/(\.node)?$/, ".node"));
|
|
768
|
-
} else {
|
|
769
|
-
addon = nativeBinding;
|
|
770
|
-
}
|
|
771
|
-
if (!addon.isInitialized) {
|
|
772
|
-
addon.setErrorConstructor(SqliteError);
|
|
773
|
-
addon.isInitialized = true;
|
|
774
|
-
}
|
|
775
|
-
if (!anonymous && !fs.existsSync(path.dirname(filename))) {
|
|
776
|
-
throw new TypeError("Cannot open database because the directory does not exist");
|
|
777
|
-
}
|
|
778
|
-
Object.defineProperties(this, {
|
|
779
|
-
[util2.cppdb]: { value: new addon.Database(filename, filenameGiven, anonymous, readonly, fileMustExist, timeout, verbose || null, buffer || null) },
|
|
780
|
-
...wrappers2.getters
|
|
781
|
-
});
|
|
782
|
-
}
|
|
783
|
-
const wrappers2 = requireWrappers();
|
|
784
|
-
Database2.prototype.prepare = wrappers2.prepare;
|
|
785
|
-
Database2.prototype.transaction = requireTransaction();
|
|
786
|
-
Database2.prototype.pragma = requirePragma();
|
|
787
|
-
Database2.prototype.backup = requireBackup();
|
|
788
|
-
Database2.prototype.serialize = requireSerialize();
|
|
789
|
-
Database2.prototype.function = require_function();
|
|
790
|
-
Database2.prototype.aggregate = requireAggregate();
|
|
791
|
-
Database2.prototype.table = requireTable();
|
|
792
|
-
Database2.prototype.loadExtension = wrappers2.loadExtension;
|
|
793
|
-
Database2.prototype.exec = wrappers2.exec;
|
|
794
|
-
Database2.prototype.close = wrappers2.close;
|
|
795
|
-
Database2.prototype.defaultSafeIntegers = wrappers2.defaultSafeIntegers;
|
|
796
|
-
Database2.prototype.unsafeMode = wrappers2.unsafeMode;
|
|
797
|
-
Database2.prototype[util2.inspect] = requireInspect();
|
|
798
|
-
database = Database2;
|
|
799
|
-
return database;
|
|
800
|
-
}
|
|
801
|
-
var hasRequiredLib;
|
|
802
|
-
function requireLib() {
|
|
803
|
-
if (hasRequiredLib) return lib.exports;
|
|
804
|
-
hasRequiredLib = 1;
|
|
805
|
-
lib.exports = requireDatabase();
|
|
806
|
-
lib.exports.SqliteError = requireSqliteError();
|
|
807
|
-
return lib.exports;
|
|
808
|
-
}
|
|
809
|
-
var libExports = requireLib();
|
|
810
|
-
const Database = /* @__PURE__ */ getDefaultExportFromCjs(libExports);
|
|
811
|
-
// @license
|
|
812
|
-
class IoSqlite {
|
|
813
|
-
// ...........................................................................
|
|
814
|
-
// Constructor & example
|
|
815
|
-
constructor(dbPath) {
|
|
816
|
-
__publicField(this, "_db");
|
|
817
|
-
__publicField(this, "_dbPath");
|
|
818
|
-
// ######################
|
|
819
|
-
// Private
|
|
820
|
-
// ######################
|
|
821
|
-
__publicField(this, "_isReady", new IsReady());
|
|
822
|
-
// ...........................................................................
|
|
823
|
-
__publicField(this, "_initTableCfgs", () => {
|
|
824
|
-
const tableCfg = {
|
|
825
|
-
version: 1,
|
|
826
|
-
key: "tableCfgs",
|
|
827
|
-
type: "ingredients",
|
|
828
|
-
columns: {
|
|
829
|
-
key: { key: "key", type: "string", previous: "string" },
|
|
830
|
-
type: { key: "type", type: "string", previous: "string" }
|
|
831
|
-
}
|
|
832
|
-
};
|
|
833
|
-
hip(tableCfg);
|
|
834
|
-
const tableCfgHashed = hsh(tableCfg);
|
|
835
|
-
try {
|
|
836
|
-
this._db.prepare(
|
|
837
|
-
`
|
|
838
|
-
CREATE TABLE IF NOT EXISTS tableCfgs (
|
|
839
|
-
_hash TEXT PRIMARY KEY,
|
|
840
|
-
version INTEGER,
|
|
841
|
-
key TEXT KEY,
|
|
842
|
-
type TEXT,
|
|
843
|
-
previous TEXT
|
|
844
|
-
);
|
|
845
|
-
`
|
|
846
|
-
).run();
|
|
847
|
-
} catch (error) {
|
|
848
|
-
console.error(error);
|
|
849
|
-
}
|
|
850
|
-
this._db.prepare(
|
|
851
|
-
`
|
|
852
|
-
INSERT INTO tableCfgs (_hash, version, key, type) VALUES (?, ?, ?, ?);
|
|
853
|
-
`
|
|
854
|
-
).run(tableCfgHashed._hash, tableCfg.version, tableCfg.key, tableCfg.type);
|
|
855
|
-
});
|
|
856
|
-
this.dbPath = dbPath;
|
|
857
|
-
this._dbPath = dbPath;
|
|
858
|
-
this._db = new Database(dbPath);
|
|
859
|
-
this._init();
|
|
860
|
-
}
|
|
861
|
-
async deleteDatabase() {
|
|
862
|
-
this._db.close();
|
|
863
|
-
delete this._dbPath;
|
|
864
|
-
}
|
|
865
|
-
// ...........................................................................
|
|
866
|
-
// General
|
|
867
|
-
isReady() {
|
|
868
|
-
return this._isReady.promise;
|
|
869
|
-
}
|
|
870
|
-
// ...........................................................................
|
|
871
|
-
// Dump (export all data from database)
|
|
872
|
-
dump() {
|
|
873
|
-
return this._dump();
|
|
874
|
-
}
|
|
875
|
-
dumpTable(request) {
|
|
876
|
-
return this._dumpTable(request);
|
|
877
|
-
}
|
|
878
|
-
// ...........................................................................
|
|
879
|
-
// Rows
|
|
880
|
-
readRow(request) {
|
|
881
|
-
return this._readRow(request);
|
|
882
|
-
}
|
|
883
|
-
readRows(request) {
|
|
884
|
-
return this._readRows(request);
|
|
885
|
-
}
|
|
886
|
-
// ...........................................................................
|
|
887
|
-
// Write
|
|
888
|
-
write(request) {
|
|
889
|
-
return this._write(request);
|
|
890
|
-
}
|
|
891
|
-
// ...........................................................................
|
|
892
|
-
// Table management
|
|
893
|
-
createTable(request) {
|
|
894
|
-
return this._createTable(request);
|
|
895
|
-
}
|
|
896
|
-
async tables() {
|
|
897
|
-
return this._tables();
|
|
898
|
-
}
|
|
899
|
-
// ...........................................................................
|
|
900
|
-
async _init() {
|
|
901
|
-
this._initTableCfgs();
|
|
902
|
-
this._isReady.resolve();
|
|
903
|
-
}
|
|
904
|
-
// ...........................................................................
|
|
905
|
-
async _createTable(request) {
|
|
906
|
-
const config = {};
|
|
907
|
-
if (!config) {
|
|
908
|
-
throw new Error(`Table config ${request.tableCfg} not found`);
|
|
909
|
-
}
|
|
910
|
-
console.log(request.tableCfg);
|
|
911
|
-
}
|
|
912
|
-
// ...........................................................................
|
|
913
|
-
async _tables() {
|
|
914
|
-
throw new Error("Not implemented");
|
|
915
|
-
}
|
|
916
|
-
// ...........................................................................
|
|
917
|
-
async _readRow(request) {
|
|
918
|
-
throw new Error("Not implemented " + request);
|
|
919
|
-
}
|
|
920
|
-
// ...........................................................................
|
|
921
|
-
async _readRows(request) {
|
|
922
|
-
throw new Error("Not implemented " + request);
|
|
923
|
-
}
|
|
924
|
-
// ...........................................................................
|
|
925
|
-
async _dump() {
|
|
926
|
-
const tablesQuery = `
|
|
927
|
-
SELECT name
|
|
928
|
-
FROM sqlite_master
|
|
929
|
-
WHERE type='table' AND name NOT LIKE 'sqlite_%';
|
|
930
|
-
`;
|
|
931
|
-
const returnFile = {};
|
|
932
|
-
const tables = this._db.prepare(tablesQuery).all();
|
|
933
|
-
for (const table2 of tables) {
|
|
934
|
-
const tableDump = await this._dumpTable({ table: table2.name });
|
|
935
|
-
const tableDumpJson = JSON.parse(JSON.stringify(tableDump));
|
|
936
|
-
returnFile[table2.name] = tableDumpJson;
|
|
937
|
-
}
|
|
938
|
-
return returnFile;
|
|
939
|
-
}
|
|
940
|
-
// ...........................................................................
|
|
941
|
-
async _dumpTable(request) {
|
|
942
|
-
const query = `SELECT * FROM ${request.table}`;
|
|
943
|
-
let returnFile = {};
|
|
944
|
-
const returnValue = this._db.prepare(query).all();
|
|
945
|
-
returnFile = JSON.parse(JSON.stringify(returnValue));
|
|
946
|
-
return returnFile;
|
|
947
|
-
}
|
|
948
|
-
// ...........................................................................
|
|
949
|
-
async _write(request) {
|
|
950
|
-
throw new Error("Not implemented " + request);
|
|
951
|
-
}
|
|
952
|
-
}
|
|
953
|
-
export {
|
|
954
|
-
IoSqlite
|
|
955
|
-
};
|