pi-para 0.7.7 → 0.7.9
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/CHANGELOG.md +10 -0
- package/node_modules/better-sqlite3/LICENSE +21 -0
- package/node_modules/better-sqlite3/README.md +99 -0
- package/node_modules/better-sqlite3/binding.gyp +60 -0
- package/node_modules/better-sqlite3/deps/common.gypi +68 -0
- package/node_modules/better-sqlite3/deps/copy.js +31 -0
- package/node_modules/better-sqlite3/deps/defines.gypi +42 -0
- package/node_modules/better-sqlite3/deps/download.sh +123 -0
- package/node_modules/better-sqlite3/deps/patches/1208.patch +15 -0
- package/node_modules/better-sqlite3/deps/sqlite3/sqlite3.c +269668 -0
- package/node_modules/better-sqlite3/deps/sqlite3/sqlite3.h +14349 -0
- package/node_modules/better-sqlite3/deps/sqlite3/sqlite3ext.h +739 -0
- package/node_modules/better-sqlite3/deps/sqlite3.gyp +80 -0
- package/node_modules/better-sqlite3/deps/test_extension.c +21 -0
- package/node_modules/better-sqlite3/lib/binding.js +62 -0
- package/node_modules/better-sqlite3/lib/darwin-arm64.js +3 -0
- package/node_modules/better-sqlite3/lib/darwin-x64.js +3 -0
- package/node_modules/better-sqlite3/lib/database.js +109 -0
- package/node_modules/better-sqlite3/lib/index.js +3 -0
- package/node_modules/better-sqlite3/lib/linux-arm64.js +3 -0
- package/node_modules/better-sqlite3/lib/linux-x64.js +3 -0
- package/node_modules/better-sqlite3/lib/linuxmusl-arm64.js +4 -0
- package/node_modules/better-sqlite3/lib/linuxmusl-x64.js +4 -0
- package/node_modules/better-sqlite3/lib/methods/aggregate.js +43 -0
- package/node_modules/better-sqlite3/lib/methods/backup.js +67 -0
- package/node_modules/better-sqlite3/lib/methods/explain.js +9 -0
- package/node_modules/better-sqlite3/lib/methods/function.js +31 -0
- package/node_modules/better-sqlite3/lib/methods/inspect.js +7 -0
- package/node_modules/better-sqlite3/lib/methods/pragma.js +12 -0
- package/node_modules/better-sqlite3/lib/methods/serialize.js +16 -0
- package/node_modules/better-sqlite3/lib/methods/table.js +195 -0
- package/node_modules/better-sqlite3/lib/methods/transaction.js +78 -0
- package/node_modules/better-sqlite3/lib/methods/wrappers.js +54 -0
- package/node_modules/better-sqlite3/lib/sqlite-error.js +25 -0
- package/node_modules/better-sqlite3/lib/util.js +12 -0
- package/node_modules/better-sqlite3/lib/win32-arm64.js +3 -0
- package/node_modules/better-sqlite3/lib/win32-x64.js +3 -0
- package/node_modules/better-sqlite3/package.json +67 -0
- package/node_modules/better-sqlite3/prebuilds/darwin-arm64.node +0 -0
- package/node_modules/better-sqlite3/prebuilds/darwin-x64.node +0 -0
- package/node_modules/better-sqlite3/prebuilds/linux-arm64.node +0 -0
- package/node_modules/better-sqlite3/prebuilds/linux-x64.node +0 -0
- package/node_modules/better-sqlite3/prebuilds/linuxmusl-arm64.node +0 -0
- package/node_modules/better-sqlite3/prebuilds/linuxmusl-x64.node +0 -0
- package/node_modules/better-sqlite3/prebuilds/win32-arm64.node +0 -0
- package/node_modules/better-sqlite3/prebuilds/win32-x64.node +0 -0
- package/node_modules/better-sqlite3/src/addon.cpp +59 -0
- package/node_modules/better-sqlite3/src/better_sqlite3.cpp +73 -0
- package/node_modules/better-sqlite3/src/objects/backup.cpp +121 -0
- package/node_modules/better-sqlite3/src/objects/backup.hpp +32 -0
- package/node_modules/better-sqlite3/src/objects/database.cpp +432 -0
- package/node_modules/better-sqlite3/src/objects/database.hpp +100 -0
- package/node_modules/better-sqlite3/src/objects/statement-iterator.cpp +119 -0
- package/node_modules/better-sqlite3/src/objects/statement-iterator.hpp +71 -0
- package/node_modules/better-sqlite3/src/objects/statement.cpp +380 -0
- package/node_modules/better-sqlite3/src/objects/statement.hpp +65 -0
- package/node_modules/better-sqlite3/src/util/bind-map.cpp +73 -0
- package/node_modules/better-sqlite3/src/util/binder.cpp +210 -0
- package/node_modules/better-sqlite3/src/util/constants.cpp +172 -0
- package/node_modules/better-sqlite3/src/util/custom-aggregate.cpp +121 -0
- package/node_modules/better-sqlite3/src/util/custom-function.cpp +59 -0
- package/node_modules/better-sqlite3/src/util/custom-table.cpp +406 -0
- package/node_modules/better-sqlite3/src/util/data-converter.cpp +17 -0
- package/node_modules/better-sqlite3/src/util/data.cpp +134 -0
- package/node_modules/better-sqlite3/src/util/helpers.cpp +190 -0
- package/node_modules/better-sqlite3/src/util/macros.cpp +74 -0
- package/node_modules/better-sqlite3/src/util/query-macros.cpp +71 -0
- package/node_modules/better-sqlite3/src/util/row-builder.cpp +53 -0
- package/node_modules/better-sqlite3/src/util/row-builder.hpp +22 -0
- package/node_modules/node-addon-api/LICENSE.md +9 -0
- package/node_modules/node-addon-api/README.md +95 -0
- package/node_modules/node-addon-api/common.gypi +21 -0
- package/node_modules/node-addon-api/except.gypi +25 -0
- package/node_modules/node-addon-api/index.js +14 -0
- package/node_modules/node-addon-api/napi-inl.deprecated.h +186 -0
- package/node_modules/node-addon-api/napi-inl.h +7165 -0
- package/node_modules/node-addon-api/napi.h +3364 -0
- package/node_modules/node-addon-api/node_addon_api.gyp +42 -0
- package/node_modules/node-addon-api/node_api.gyp +9 -0
- package/node_modules/node-addon-api/noexcept.gypi +26 -0
- package/node_modules/node-addon-api/nothing.c +0 -0
- package/node_modules/node-addon-api/package-support.json +21 -0
- package/node_modules/node-addon-api/package.json +480 -0
- package/node_modules/node-addon-api/tools/README.md +73 -0
- package/node_modules/node-addon-api/tools/check-napi.js +99 -0
- package/node_modules/node-addon-api/tools/clang-format.js +71 -0
- package/node_modules/node-addon-api/tools/conversion.js +301 -0
- package/package.json +6 -3
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# ===
|
|
2
|
+
# This configuration defines options specific to compiling SQLite itself.
|
|
3
|
+
# Compile-time options are loaded by the auto-generated file "defines.gypi".
|
|
4
|
+
# The --sqlite3 option can be provided to use a custom amalgamation instead.
|
|
5
|
+
# ===
|
|
6
|
+
|
|
7
|
+
{
|
|
8
|
+
'includes': ['common.gypi'],
|
|
9
|
+
'targets': [
|
|
10
|
+
{
|
|
11
|
+
'target_name': 'locate_sqlite3',
|
|
12
|
+
'type': 'none',
|
|
13
|
+
'hard_dependency': 1,
|
|
14
|
+
'conditions': [
|
|
15
|
+
['sqlite3 == ""', {
|
|
16
|
+
'actions': [{
|
|
17
|
+
'action_name': 'copy_builtin_sqlite3',
|
|
18
|
+
'inputs': [
|
|
19
|
+
'sqlite3/sqlite3.c',
|
|
20
|
+
'sqlite3/sqlite3.h',
|
|
21
|
+
'sqlite3/sqlite3ext.h',
|
|
22
|
+
],
|
|
23
|
+
'outputs': [
|
|
24
|
+
'<(SHARED_INTERMEDIATE_DIR)/sqlite3/sqlite3.c',
|
|
25
|
+
'<(SHARED_INTERMEDIATE_DIR)/sqlite3/sqlite3.h',
|
|
26
|
+
'<(SHARED_INTERMEDIATE_DIR)/sqlite3/sqlite3ext.h',
|
|
27
|
+
],
|
|
28
|
+
'action': ['node', 'copy.js', '<(SHARED_INTERMEDIATE_DIR)/sqlite3', ''],
|
|
29
|
+
}],
|
|
30
|
+
}, {
|
|
31
|
+
'actions': [{
|
|
32
|
+
'action_name': 'copy_custom_sqlite3',
|
|
33
|
+
'inputs': [
|
|
34
|
+
'<(sqlite3)/sqlite3.c',
|
|
35
|
+
'<(sqlite3)/sqlite3.h',
|
|
36
|
+
],
|
|
37
|
+
'outputs': [
|
|
38
|
+
'<(SHARED_INTERMEDIATE_DIR)/sqlite3/sqlite3.c',
|
|
39
|
+
'<(SHARED_INTERMEDIATE_DIR)/sqlite3/sqlite3.h',
|
|
40
|
+
],
|
|
41
|
+
'action': ['node', 'copy.js', '<(SHARED_INTERMEDIATE_DIR)/sqlite3', '<(sqlite3)'],
|
|
42
|
+
}],
|
|
43
|
+
}],
|
|
44
|
+
],
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
'target_name': 'sqlite3',
|
|
48
|
+
'type': 'static_library',
|
|
49
|
+
'dependencies': ['locate_sqlite3'],
|
|
50
|
+
'sources': ['<(SHARED_INTERMEDIATE_DIR)/sqlite3/sqlite3.c'],
|
|
51
|
+
'include_dirs': ['<(SHARED_INTERMEDIATE_DIR)/sqlite3/'],
|
|
52
|
+
'direct_dependent_settings': {
|
|
53
|
+
'include_dirs': ['<(SHARED_INTERMEDIATE_DIR)/sqlite3/'],
|
|
54
|
+
},
|
|
55
|
+
'cflags': ['-std=c99', '-w'],
|
|
56
|
+
'xcode_settings': {
|
|
57
|
+
'OTHER_CFLAGS': ['-std=c99'],
|
|
58
|
+
'WARNING_CFLAGS': ['-w'],
|
|
59
|
+
},
|
|
60
|
+
'conditions': [
|
|
61
|
+
['sqlite3 == ""', {
|
|
62
|
+
'includes': ['defines.gypi'],
|
|
63
|
+
}, {
|
|
64
|
+
'defines': [
|
|
65
|
+
# This is currently required by better-sqlite3.
|
|
66
|
+
'SQLITE_ENABLE_COLUMN_METADATA',
|
|
67
|
+
],
|
|
68
|
+
}]
|
|
69
|
+
],
|
|
70
|
+
'configurations': {
|
|
71
|
+
'Debug': {
|
|
72
|
+
'msvs_settings': { 'VCCLCompilerTool': { 'RuntimeLibrary': 1 } }, # static debug
|
|
73
|
+
},
|
|
74
|
+
'Release': {
|
|
75
|
+
'msvs_settings': { 'VCCLCompilerTool': { 'RuntimeLibrary': 0 } }, # static release
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#include <sqlite3ext.h>
|
|
2
|
+
SQLITE_EXTENSION_INIT1
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
This SQLite extension is used only for testing purposes (npm test).
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
static void TestExtensionFunction(sqlite3_context* pCtx, int nVal, sqlite3_value** _) {
|
|
9
|
+
sqlite3_result_double(pCtx, (double)nVal);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
#ifdef _WIN32
|
|
13
|
+
__declspec(dllexport)
|
|
14
|
+
#endif
|
|
15
|
+
|
|
16
|
+
int sqlite3_extension_init(sqlite3* db, char** pzErrMsg, const sqlite3_api_routines* pApi) {
|
|
17
|
+
SQLITE_EXTENSION_INIT2(pApi)
|
|
18
|
+
if (pzErrMsg != 0) *pzErrMsg = 0;
|
|
19
|
+
sqlite3_create_function(db, "testExtensionFunction", -1, SQLITE_UTF8, 0, TestExtensionFunction, 0, 0);
|
|
20
|
+
return SQLITE_OK;
|
|
21
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
|
|
5
|
+
const PREBUILD_PLATFORMS = ['linux', 'darwin', 'win32'];
|
|
6
|
+
const PREBUILD_ARCHS = ['x64', 'arm64'];
|
|
7
|
+
let DEFAULT_ADDON;
|
|
8
|
+
|
|
9
|
+
function getBinding(nativeBinding) {
|
|
10
|
+
// If a path was provided, load the binding from the filesystem.
|
|
11
|
+
if (typeof nativeBinding === 'string') {
|
|
12
|
+
// See <https://webpack.js.org/api/module-variables/#__non_webpack_require__-webpack-specific>
|
|
13
|
+
const requireFunc = typeof __non_webpack_require__ === 'function' ? __non_webpack_require__ : require;
|
|
14
|
+
return requireFunc(path.resolve(nativeBinding).replace(/(\.node)?$/, '.node'));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// If an object was provided, use it as the binding directly.
|
|
18
|
+
if (typeof nativeBinding === 'object' && nativeBinding !== null) {
|
|
19
|
+
return nativeBinding;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// If we're using the default binding and it already exists, just return it.
|
|
23
|
+
if (DEFAULT_ADDON) {
|
|
24
|
+
return DEFAULT_ADDON;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Otherwise, try to find the binding as a prebuilt binary.
|
|
28
|
+
let filename = getPrebuildPath();
|
|
29
|
+
if (filename) {
|
|
30
|
+
return DEFAULT_ADDON = require(filename);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// If no prebuilt binary was found, try the default node-gyp locations.
|
|
34
|
+
filename = path.join(__dirname, '..', 'build', 'Debug', 'better_sqlite3.node');
|
|
35
|
+
if (!fs.existsSync(filename)) {
|
|
36
|
+
filename = path.join(__dirname, '..', 'build', 'Release', 'better_sqlite3.node');
|
|
37
|
+
}
|
|
38
|
+
return DEFAULT_ADDON = require(filename);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function getPrebuildPath() {
|
|
42
|
+
if (PREBUILD_PLATFORMS.includes(process.platform) && PREBUILD_ARCHS.includes(process.arch)) {
|
|
43
|
+
const target = `${isLinuxMusl() ? 'linuxmusl' : process.platform}-${process.arch}`;
|
|
44
|
+
const filename = path.join(__dirname, '..', 'prebuilds', `${target}.node`);
|
|
45
|
+
if (fs.existsSync(filename)) {
|
|
46
|
+
return filename;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function isLinuxMusl() {
|
|
53
|
+
return process.platform === 'linux' && !process.report.getReport().header.glibcVersionRuntime;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
exports.getBinding = getBinding;
|
|
57
|
+
exports.getPrebuildPath = getPrebuildPath;
|
|
58
|
+
|
|
59
|
+
// This script is executed directly by binding.gyp to detect prebuilt binaries.
|
|
60
|
+
if (require.main === module) {
|
|
61
|
+
process.stdout.write(getPrebuildPath() ? '1' : '0');
|
|
62
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const util = require('./util');
|
|
5
|
+
const SqliteError = require('./sqlite-error');
|
|
6
|
+
|
|
7
|
+
module.exports = function createDatabase(getAddon, allowNativeBinding) {
|
|
8
|
+
function Database(filenameGiven, options) {
|
|
9
|
+
if (new.target == null) {
|
|
10
|
+
return new Database(filenameGiven, options);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// Apply defaults
|
|
14
|
+
let buffer;
|
|
15
|
+
if (Buffer.isBuffer(filenameGiven)) {
|
|
16
|
+
buffer = filenameGiven;
|
|
17
|
+
filenameGiven = ':memory:';
|
|
18
|
+
}
|
|
19
|
+
if (filenameGiven == null) filenameGiven = '';
|
|
20
|
+
if (options == null) options = {};
|
|
21
|
+
|
|
22
|
+
// Validate arguments
|
|
23
|
+
if (typeof filenameGiven !== 'string') throw new TypeError('Expected first argument to be a string');
|
|
24
|
+
if (typeof options !== 'object') throw new TypeError('Expected second argument to be an options object');
|
|
25
|
+
if ('readOnly' in options) throw new TypeError('Misspelled option "readOnly" should be "readonly"');
|
|
26
|
+
if ('memory' in options) throw new TypeError('Option "memory" was removed in v7.0.0 (use ":memory:" filename instead)');
|
|
27
|
+
|
|
28
|
+
// Interpret options
|
|
29
|
+
const filename = filenameGiven.trim();
|
|
30
|
+
const anonymous = filename === '' || filename === ':memory:';
|
|
31
|
+
const readonly = util.getBooleanOption(options, 'readonly');
|
|
32
|
+
const fileMustExist = util.getBooleanOption(options, 'fileMustExist');
|
|
33
|
+
const timeout = 'timeout' in options ? options.timeout : 5000;
|
|
34
|
+
const verbose = 'verbose' in options ? options.verbose : null;
|
|
35
|
+
const nativeBinding = 'nativeBinding' in options ? options.nativeBinding : null;
|
|
36
|
+
|
|
37
|
+
// Validate interpreted options
|
|
38
|
+
if (readonly && anonymous && !buffer) throw new TypeError('In-memory/temporary databases cannot be readonly');
|
|
39
|
+
if (!Number.isInteger(timeout) || timeout < 0) throw new TypeError('Expected the "timeout" option to be a positive integer');
|
|
40
|
+
if (timeout > 0x7fffffff) throw new RangeError('Option "timeout" cannot be greater than 2147483647');
|
|
41
|
+
if (verbose != null && typeof verbose !== 'function') throw new TypeError('Expected the "verbose" option to be a function');
|
|
42
|
+
if (!allowNativeBinding && 'nativeBinding' in options) throw new TypeError('The "nativeBinding" option is only supported by the default better-sqlite3 entrypoint');
|
|
43
|
+
if (allowNativeBinding && nativeBinding != null && typeof nativeBinding !== 'string' && typeof nativeBinding !== 'object') throw new TypeError('Expected the "nativeBinding" option to be a string or addon object');
|
|
44
|
+
|
|
45
|
+
// Load the native addon
|
|
46
|
+
const addon = getAddon(nativeBinding);
|
|
47
|
+
if (!addon.isInitialized) {
|
|
48
|
+
addon.initialize(SqliteError, arrayFactory, arrayAppender, rowFactory, recordFactory);
|
|
49
|
+
addon.isInitialized = true;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Make sure the specified directory exists
|
|
53
|
+
if (!anonymous && !filename.startsWith('file:') && !fs.existsSync(path.dirname(filename))) {
|
|
54
|
+
throw new TypeError('Cannot open database because the directory does not exist');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
Object.defineProperties(this, {
|
|
58
|
+
[util.cppdb]: { value: new addon.Database(filename, filenameGiven, anonymous, readonly, fileMustExist, timeout, verbose || null, buffer || null) },
|
|
59
|
+
...wrappers.getters,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const wrappers = require('./methods/wrappers');
|
|
64
|
+
Database.prototype.prepare = wrappers.prepare;
|
|
65
|
+
Database.prototype.transaction = require('./methods/transaction');
|
|
66
|
+
Database.prototype.pragma = require('./methods/pragma');
|
|
67
|
+
Database.prototype.explain = require('./methods/explain');
|
|
68
|
+
Database.prototype.backup = require('./methods/backup');
|
|
69
|
+
Database.prototype.serialize = require('./methods/serialize');
|
|
70
|
+
Database.prototype.function = require('./methods/function');
|
|
71
|
+
Database.prototype.aggregate = require('./methods/aggregate');
|
|
72
|
+
Database.prototype.table = require('./methods/table');
|
|
73
|
+
Database.prototype.loadExtension = wrappers.loadExtension;
|
|
74
|
+
Database.prototype.exec = wrappers.exec;
|
|
75
|
+
Database.prototype.close = wrappers.close;
|
|
76
|
+
Database.prototype.defaultSafeIntegers = wrappers.defaultSafeIntegers;
|
|
77
|
+
Database.prototype.unsafeMode = wrappers.unsafeMode;
|
|
78
|
+
Database.prototype[util.inspect] = require('./methods/inspect');
|
|
79
|
+
|
|
80
|
+
return Database;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
function arrayFactory(...values) {
|
|
84
|
+
return values;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function arrayAppender(array, ...values) {
|
|
88
|
+
const offset = array.length;
|
|
89
|
+
for (let i = 0; i < values.length; ++i) {
|
|
90
|
+
array[offset + i] = values[i];
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function rowFactory(...keys) {
|
|
95
|
+
if (!keys.includes('__proto__')) {
|
|
96
|
+
const parameters = keys.map((_, index) => `v${index}`).join(',');
|
|
97
|
+
const properties = keys.map((key, index) => `${JSON.stringify(key)}:v${index}`).join(',');
|
|
98
|
+
return Function(`return (${parameters}) => ({${properties}})`)();
|
|
99
|
+
}
|
|
100
|
+
return (...values) => {
|
|
101
|
+
const row = {};
|
|
102
|
+
for (let i = 0; i < keys.length; ++i) row[keys[i]] = values[i];
|
|
103
|
+
return row;
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function recordFactory(value) {
|
|
108
|
+
return { value, done: false };
|
|
109
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const { getBooleanOption, cppdb } = require('../util');
|
|
3
|
+
|
|
4
|
+
module.exports = function defineAggregate(name, options) {
|
|
5
|
+
// Validate arguments
|
|
6
|
+
if (typeof name !== 'string') throw new TypeError('Expected first argument to be a string');
|
|
7
|
+
if (typeof options !== 'object' || options === null) throw new TypeError('Expected second argument to be an options object');
|
|
8
|
+
if (!name) throw new TypeError('User-defined function name cannot be an empty string');
|
|
9
|
+
|
|
10
|
+
// Interpret options
|
|
11
|
+
const start = 'start' in options ? options.start : null;
|
|
12
|
+
const step = getFunctionOption(options, 'step', true);
|
|
13
|
+
const inverse = getFunctionOption(options, 'inverse', false);
|
|
14
|
+
const result = getFunctionOption(options, 'result', false);
|
|
15
|
+
const safeIntegers = 'safeIntegers' in options ? +getBooleanOption(options, 'safeIntegers') : 2;
|
|
16
|
+
const deterministic = getBooleanOption(options, 'deterministic');
|
|
17
|
+
const directOnly = getBooleanOption(options, 'directOnly');
|
|
18
|
+
const varargs = getBooleanOption(options, 'varargs');
|
|
19
|
+
let argCount = -1;
|
|
20
|
+
|
|
21
|
+
// Determine argument count
|
|
22
|
+
if (!varargs) {
|
|
23
|
+
argCount = Math.max(getLength(step), inverse ? getLength(inverse) : 0);
|
|
24
|
+
if (argCount > 0) argCount -= 1;
|
|
25
|
+
if (argCount > 100) throw new RangeError('User-defined functions cannot have more than 100 arguments');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
this[cppdb].aggregate(start, step, inverse, result, name, argCount, safeIntegers, deterministic, directOnly);
|
|
29
|
+
return this;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const getFunctionOption = (options, key, required) => {
|
|
33
|
+
const value = key in options ? options[key] : null;
|
|
34
|
+
if (typeof value === 'function') return value;
|
|
35
|
+
if (value != null) throw new TypeError(`Expected the "${key}" option to be a function`);
|
|
36
|
+
if (required) throw new TypeError(`Missing required option "${key}"`);
|
|
37
|
+
return null;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const getLength = ({ length }) => {
|
|
41
|
+
if (Number.isInteger(length) && length >= 0) return length;
|
|
42
|
+
throw new TypeError('Expected function.length to be a positive integer');
|
|
43
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const { promisify } = require('util');
|
|
5
|
+
const { cppdb } = require('../util');
|
|
6
|
+
const fsAccess = promisify(fs.access);
|
|
7
|
+
|
|
8
|
+
module.exports = async function backup(filename, options) {
|
|
9
|
+
if (options == null) options = {};
|
|
10
|
+
|
|
11
|
+
// Validate arguments
|
|
12
|
+
if (typeof filename !== 'string') throw new TypeError('Expected first argument to be a string');
|
|
13
|
+
if (typeof options !== 'object') throw new TypeError('Expected second argument to be an options object');
|
|
14
|
+
|
|
15
|
+
// Interpret options
|
|
16
|
+
filename = filename.trim();
|
|
17
|
+
const attachedName = 'attached' in options ? options.attached : 'main';
|
|
18
|
+
const handler = 'progress' in options ? options.progress : null;
|
|
19
|
+
|
|
20
|
+
// Validate interpreted options
|
|
21
|
+
if (!filename) throw new TypeError('Backup filename cannot be an empty string');
|
|
22
|
+
if (filename === ':memory:') throw new TypeError('Invalid backup filename ":memory:"');
|
|
23
|
+
if (typeof attachedName !== 'string') throw new TypeError('Expected the "attached" option to be a string');
|
|
24
|
+
if (!attachedName) throw new TypeError('The "attached" option cannot be an empty string');
|
|
25
|
+
if (handler != null && typeof handler !== 'function') throw new TypeError('Expected the "progress" option to be a function');
|
|
26
|
+
|
|
27
|
+
// Make sure the specified directory exists
|
|
28
|
+
await fsAccess(path.dirname(filename)).catch(() => {
|
|
29
|
+
throw new TypeError('Cannot save backup because the directory does not exist');
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const isNewFile = await fsAccess(filename).then(() => false, () => true);
|
|
33
|
+
return runBackup(this[cppdb].backup(this, attachedName, filename, isNewFile), handler || null);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const runBackup = (backup, handler) => {
|
|
37
|
+
let rate = 0;
|
|
38
|
+
let useDefault = true;
|
|
39
|
+
|
|
40
|
+
return new Promise((resolve, reject) => {
|
|
41
|
+
setImmediate(function step() {
|
|
42
|
+
try {
|
|
43
|
+
const progress = backup.transfer(rate);
|
|
44
|
+
if (!progress.remainingPages) {
|
|
45
|
+
backup.close();
|
|
46
|
+
resolve(progress);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (useDefault) {
|
|
50
|
+
useDefault = false;
|
|
51
|
+
rate = 100;
|
|
52
|
+
}
|
|
53
|
+
if (handler) {
|
|
54
|
+
const ret = handler(progress);
|
|
55
|
+
if (ret !== undefined) {
|
|
56
|
+
if (typeof ret === 'number' && ret === ret) rate = Math.max(0, Math.min(0x7fffffff, Math.round(ret)));
|
|
57
|
+
else throw new TypeError('Expected progress callback to return a number or undefined');
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
setImmediate(step);
|
|
61
|
+
} catch (err) {
|
|
62
|
+
backup.close();
|
|
63
|
+
reject(err);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const { cppdb } = require('../util');
|
|
3
|
+
|
|
4
|
+
module.exports = function explain(source) {
|
|
5
|
+
if (typeof source !== 'string') throw new TypeError('Expected first argument to be a string');
|
|
6
|
+
|
|
7
|
+
const stmt = this[cppdb].prepare(`EXPLAIN ${source}`, this, false, true);
|
|
8
|
+
return stmt.all();
|
|
9
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const { getBooleanOption, cppdb } = require('../util');
|
|
3
|
+
|
|
4
|
+
module.exports = function defineFunction(name, options, fn) {
|
|
5
|
+
// Apply defaults
|
|
6
|
+
if (options == null) options = {};
|
|
7
|
+
if (typeof options === 'function') { fn = options; options = {}; }
|
|
8
|
+
|
|
9
|
+
// Validate arguments
|
|
10
|
+
if (typeof name !== 'string') throw new TypeError('Expected first argument to be a string');
|
|
11
|
+
if (typeof fn !== 'function') throw new TypeError('Expected last argument to be a function');
|
|
12
|
+
if (typeof options !== 'object') throw new TypeError('Expected second argument to be an options object');
|
|
13
|
+
if (!name) throw new TypeError('User-defined function name cannot be an empty string');
|
|
14
|
+
|
|
15
|
+
// Interpret options
|
|
16
|
+
const safeIntegers = 'safeIntegers' in options ? +getBooleanOption(options, 'safeIntegers') : 2;
|
|
17
|
+
const deterministic = getBooleanOption(options, 'deterministic');
|
|
18
|
+
const directOnly = getBooleanOption(options, 'directOnly');
|
|
19
|
+
const varargs = getBooleanOption(options, 'varargs');
|
|
20
|
+
let argCount = -1;
|
|
21
|
+
|
|
22
|
+
// Determine argument count
|
|
23
|
+
if (!varargs) {
|
|
24
|
+
argCount = fn.length;
|
|
25
|
+
if (!Number.isInteger(argCount) || argCount < 0) throw new TypeError('Expected function.length to be a positive integer');
|
|
26
|
+
if (argCount > 100) throw new RangeError('User-defined functions cannot have more than 100 arguments');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
this[cppdb].function(fn, name, argCount, safeIntegers, deterministic, directOnly);
|
|
30
|
+
return this;
|
|
31
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const { getBooleanOption, cppdb } = require('../util');
|
|
3
|
+
|
|
4
|
+
module.exports = function pragma(source, options) {
|
|
5
|
+
if (options == null) options = {};
|
|
6
|
+
if (typeof source !== 'string') throw new TypeError('Expected first argument to be a string');
|
|
7
|
+
if (typeof options !== 'object') throw new TypeError('Expected second argument to be an options object');
|
|
8
|
+
const simple = getBooleanOption(options, 'simple');
|
|
9
|
+
|
|
10
|
+
const stmt = this[cppdb].prepare(`PRAGMA ${source}`, this, true, false);
|
|
11
|
+
return simple ? stmt.pluck().get() : stmt.all();
|
|
12
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const { cppdb } = require('../util');
|
|
3
|
+
|
|
4
|
+
module.exports = function serialize(options) {
|
|
5
|
+
if (options == null) options = {};
|
|
6
|
+
|
|
7
|
+
// Validate arguments
|
|
8
|
+
if (typeof options !== 'object') throw new TypeError('Expected first argument to be an options object');
|
|
9
|
+
|
|
10
|
+
// Interpret and validate options
|
|
11
|
+
const attachedName = 'attached' in options ? options.attached : 'main';
|
|
12
|
+
if (typeof attachedName !== 'string') throw new TypeError('Expected the "attached" option to be a string');
|
|
13
|
+
if (!attachedName) throw new TypeError('The "attached" option cannot be an empty string');
|
|
14
|
+
|
|
15
|
+
return this[cppdb].serialize(attachedName);
|
|
16
|
+
};
|