pi-para 0.7.8 → 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 +5 -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 +5 -2
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const { cppdb } = require('../util');
|
|
3
|
+
|
|
4
|
+
module.exports = function defineTable(name, factory) {
|
|
5
|
+
// Validate arguments
|
|
6
|
+
if (typeof name !== 'string') throw new TypeError('Expected first argument to be a string');
|
|
7
|
+
if (!name) throw new TypeError('Virtual table module name cannot be an empty string');
|
|
8
|
+
|
|
9
|
+
// Determine whether the module is eponymous-only or not
|
|
10
|
+
let eponymous = false;
|
|
11
|
+
if (typeof factory === 'object' && factory !== null) {
|
|
12
|
+
eponymous = true;
|
|
13
|
+
factory = defer(parseTableDefinition(factory, 'used', name));
|
|
14
|
+
} else {
|
|
15
|
+
if (typeof factory !== 'function') throw new TypeError('Expected second argument to be a function or a table definition object');
|
|
16
|
+
factory = wrapFactory(factory);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
this[cppdb].table(factory, name, eponymous);
|
|
20
|
+
return this;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
function wrapFactory(factory) {
|
|
24
|
+
return function virtualTableFactory(moduleName, databaseName, tableName, ...args) {
|
|
25
|
+
const thisObject = {
|
|
26
|
+
module: moduleName,
|
|
27
|
+
database: databaseName,
|
|
28
|
+
table: tableName,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
// Generate a new table definition by invoking the factory
|
|
32
|
+
const def = apply.call(factory, thisObject, args);
|
|
33
|
+
if (typeof def !== 'object' || def === null) {
|
|
34
|
+
throw new TypeError(`Virtual table module "${moduleName}" did not return a table definition object`);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return parseTableDefinition(def, 'returned', moduleName);
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function parseTableDefinition(def, verb, moduleName) {
|
|
42
|
+
// Validate required properties
|
|
43
|
+
if (!hasOwnProperty.call(def, 'rows')) {
|
|
44
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition without a "rows" property`);
|
|
45
|
+
}
|
|
46
|
+
if (!hasOwnProperty.call(def, 'columns')) {
|
|
47
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition without a "columns" property`);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Validate "rows" property
|
|
51
|
+
const rows = def.rows;
|
|
52
|
+
if (typeof rows !== 'function' || Object.getPrototypeOf(rows) !== GeneratorFunctionPrototype) {
|
|
53
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "rows" property (should be a generator function)`);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Validate "columns" property
|
|
57
|
+
let columns = def.columns;
|
|
58
|
+
if (!Array.isArray(columns) || !isStringArray(columns = [...columns])) {
|
|
59
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "columns" property (should be an array of strings)`);
|
|
60
|
+
}
|
|
61
|
+
if (columns.length !== new Set(columns).size) {
|
|
62
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with duplicate column names`);
|
|
63
|
+
}
|
|
64
|
+
if (!columns.length) {
|
|
65
|
+
throw new RangeError(`Virtual table module "${moduleName}" ${verb} a table definition with zero columns`);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Validate "parameters" property
|
|
69
|
+
let parameters;
|
|
70
|
+
if (hasOwnProperty.call(def, 'parameters')) {
|
|
71
|
+
parameters = def.parameters;
|
|
72
|
+
if (!Array.isArray(parameters) || !isStringArray(parameters = [...parameters])) {
|
|
73
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "parameters" property (should be an array of strings)`);
|
|
74
|
+
}
|
|
75
|
+
} else {
|
|
76
|
+
parameters = inferParameters(rows);
|
|
77
|
+
}
|
|
78
|
+
if (parameters.length !== new Set(parameters).size) {
|
|
79
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with duplicate parameter names`);
|
|
80
|
+
}
|
|
81
|
+
if (parameters.length > 32) {
|
|
82
|
+
throw new RangeError(`Virtual table module "${moduleName}" ${verb} a table definition with more than the maximum number of 32 parameters`);
|
|
83
|
+
}
|
|
84
|
+
for (const parameter of parameters) {
|
|
85
|
+
if (columns.includes(parameter)) {
|
|
86
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with column "${parameter}" which was ambiguously defined as both a column and parameter`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Validate "safeIntegers" option
|
|
91
|
+
let safeIntegers = 2;
|
|
92
|
+
if (hasOwnProperty.call(def, 'safeIntegers')) {
|
|
93
|
+
const bool = def.safeIntegers;
|
|
94
|
+
if (typeof bool !== 'boolean') {
|
|
95
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "safeIntegers" property (should be a boolean)`);
|
|
96
|
+
}
|
|
97
|
+
safeIntegers = +bool;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Validate "directOnly" option
|
|
101
|
+
let directOnly = false;
|
|
102
|
+
if (hasOwnProperty.call(def, 'directOnly')) {
|
|
103
|
+
directOnly = def.directOnly;
|
|
104
|
+
if (typeof directOnly !== 'boolean') {
|
|
105
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "directOnly" property (should be a boolean)`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Generate SQL for the virtual table definition
|
|
110
|
+
const columnDefinitions = [
|
|
111
|
+
...parameters.map(identifier).map(str => `${str} HIDDEN`),
|
|
112
|
+
...columns.map(identifier),
|
|
113
|
+
];
|
|
114
|
+
return [
|
|
115
|
+
`CREATE TABLE x(${columnDefinitions.join(', ')});`,
|
|
116
|
+
wrapGenerator(rows, new Map(columns.map((x, i) => [x, parameters.length + i])), moduleName),
|
|
117
|
+
parameters,
|
|
118
|
+
safeIntegers,
|
|
119
|
+
directOnly,
|
|
120
|
+
];
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function wrapGenerator(generator, columnMap, moduleName) {
|
|
124
|
+
return function* virtualTable(...args) {
|
|
125
|
+
/*
|
|
126
|
+
We must defensively clone any buffers in the arguments, because
|
|
127
|
+
otherwise the generator could mutate one of them, which would cause
|
|
128
|
+
us to return incorrect values for hidden columns, potentially
|
|
129
|
+
corrupting the database.
|
|
130
|
+
*/
|
|
131
|
+
const output = args.map(x => Buffer.isBuffer(x) ? Buffer.from(x) : x);
|
|
132
|
+
for (let i = 0; i < columnMap.size; ++i) {
|
|
133
|
+
output.push(null); // Fill with nulls to prevent gaps in array (v8 optimization)
|
|
134
|
+
}
|
|
135
|
+
for (const row of generator(...args)) {
|
|
136
|
+
if (Array.isArray(row)) {
|
|
137
|
+
extractRowArray(row, output, columnMap.size, moduleName);
|
|
138
|
+
yield output;
|
|
139
|
+
} else if (typeof row === 'object' && row !== null) {
|
|
140
|
+
extractRowObject(row, output, columnMap, moduleName);
|
|
141
|
+
yield output;
|
|
142
|
+
} else {
|
|
143
|
+
throw new TypeError(`Virtual table module "${moduleName}" yielded something that isn't a valid row object`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function extractRowArray(row, output, columnCount, moduleName) {
|
|
150
|
+
if (row.length !== columnCount) {
|
|
151
|
+
throw new TypeError(`Virtual table module "${moduleName}" yielded a row with an incorrect number of columns`);
|
|
152
|
+
}
|
|
153
|
+
const offset = output.length - columnCount;
|
|
154
|
+
for (let i = 0; i < columnCount; ++i) {
|
|
155
|
+
output[i + offset] = row[i];
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function extractRowObject(row, output, columnMap, moduleName) {
|
|
160
|
+
let count = 0;
|
|
161
|
+
for (const key of Object.keys(row)) {
|
|
162
|
+
const index = columnMap.get(key);
|
|
163
|
+
if (index === undefined) {
|
|
164
|
+
throw new TypeError(`Virtual table module "${moduleName}" yielded a row with an undeclared column "${key}"`);
|
|
165
|
+
}
|
|
166
|
+
output[index] = row[key];
|
|
167
|
+
count += 1;
|
|
168
|
+
}
|
|
169
|
+
if (count !== columnMap.size) {
|
|
170
|
+
throw new TypeError(`Virtual table module "${moduleName}" yielded a row with missing columns`);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function inferParameters({ length }) {
|
|
175
|
+
if (!Number.isInteger(length) || length < 0) {
|
|
176
|
+
throw new TypeError('Expected function.length to be a positive integer');
|
|
177
|
+
}
|
|
178
|
+
const params = [];
|
|
179
|
+
for (let i = 0; i < length; ++i) {
|
|
180
|
+
params.push(`$${i + 1}`);
|
|
181
|
+
}
|
|
182
|
+
return params;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const { hasOwnProperty } = Object.prototype;
|
|
186
|
+
const { apply } = Function.prototype;
|
|
187
|
+
const GeneratorFunctionPrototype = Object.getPrototypeOf(function*(){});
|
|
188
|
+
const identifier = str => `"${str.replace(/"/g, '""')}"`;
|
|
189
|
+
const defer = x => () => x;
|
|
190
|
+
const isStringArray = (arr) => {
|
|
191
|
+
for (let i = 0; i < arr.length; ++i) {
|
|
192
|
+
if (typeof arr[i] !== 'string') return false;
|
|
193
|
+
}
|
|
194
|
+
return true;
|
|
195
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const { cppdb } = require('../util');
|
|
3
|
+
const controllers = new WeakMap();
|
|
4
|
+
|
|
5
|
+
module.exports = function transaction(fn) {
|
|
6
|
+
if (typeof fn !== 'function') throw new TypeError('Expected first argument to be a function');
|
|
7
|
+
|
|
8
|
+
const db = this[cppdb];
|
|
9
|
+
const controller = getController(db, this);
|
|
10
|
+
const { apply } = Function.prototype;
|
|
11
|
+
|
|
12
|
+
// Each version of the transaction function has these same properties
|
|
13
|
+
const properties = {
|
|
14
|
+
default: { value: wrapTransaction(apply, fn, db, controller.default) },
|
|
15
|
+
deferred: { value: wrapTransaction(apply, fn, db, controller.deferred) },
|
|
16
|
+
immediate: { value: wrapTransaction(apply, fn, db, controller.immediate) },
|
|
17
|
+
exclusive: { value: wrapTransaction(apply, fn, db, controller.exclusive) },
|
|
18
|
+
database: { value: this, enumerable: true },
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
Object.defineProperties(properties.default.value, properties);
|
|
22
|
+
Object.defineProperties(properties.deferred.value, properties);
|
|
23
|
+
Object.defineProperties(properties.immediate.value, properties);
|
|
24
|
+
Object.defineProperties(properties.exclusive.value, properties);
|
|
25
|
+
|
|
26
|
+
// Return the default version of the transaction function
|
|
27
|
+
return properties.default.value;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// Return the database's cached transaction controller, or create a new one
|
|
31
|
+
const getController = (db, self) => {
|
|
32
|
+
let controller = controllers.get(db);
|
|
33
|
+
if (!controller) {
|
|
34
|
+
const shared = {
|
|
35
|
+
commit: db.prepare('COMMIT', self, false, false),
|
|
36
|
+
rollback: db.prepare('ROLLBACK', self, false, false),
|
|
37
|
+
savepoint: db.prepare('SAVEPOINT `\t_bs3.\t`', self, false, false),
|
|
38
|
+
release: db.prepare('RELEASE `\t_bs3.\t`', self, false, false),
|
|
39
|
+
rollbackTo: db.prepare('ROLLBACK TO `\t_bs3.\t`', self, false, false),
|
|
40
|
+
};
|
|
41
|
+
controllers.set(db, controller = {
|
|
42
|
+
default: Object.assign({ begin: db.prepare('BEGIN', self, false, false) }, shared),
|
|
43
|
+
deferred: Object.assign({ begin: db.prepare('BEGIN DEFERRED', self, false, false) }, shared),
|
|
44
|
+
immediate: Object.assign({ begin: db.prepare('BEGIN IMMEDIATE', self, false, false) }, shared),
|
|
45
|
+
exclusive: Object.assign({ begin: db.prepare('BEGIN EXCLUSIVE', self, false, false) }, shared),
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return controller;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// Return a new transaction function by wrapping the given function
|
|
52
|
+
const wrapTransaction = (apply, fn, db, { begin, commit, rollback, savepoint, release, rollbackTo }) => function sqliteTransaction() {
|
|
53
|
+
let before, after, undo;
|
|
54
|
+
if (db.inTransaction) {
|
|
55
|
+
before = savepoint;
|
|
56
|
+
after = release;
|
|
57
|
+
undo = rollbackTo;
|
|
58
|
+
} else {
|
|
59
|
+
before = begin;
|
|
60
|
+
after = commit;
|
|
61
|
+
undo = rollback;
|
|
62
|
+
}
|
|
63
|
+
before.run();
|
|
64
|
+
try {
|
|
65
|
+
const result = apply.call(fn, this, arguments);
|
|
66
|
+
if (result && typeof result.then === 'function') {
|
|
67
|
+
throw new TypeError('Transaction function cannot return a promise');
|
|
68
|
+
}
|
|
69
|
+
after.run();
|
|
70
|
+
return result;
|
|
71
|
+
} catch (ex) {
|
|
72
|
+
if (db.inTransaction) {
|
|
73
|
+
undo.run();
|
|
74
|
+
if (undo !== rollback) after.run();
|
|
75
|
+
}
|
|
76
|
+
throw ex;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const { cppdb } = require('../util');
|
|
3
|
+
|
|
4
|
+
exports.prepare = function prepare(sql) {
|
|
5
|
+
return this[cppdb].prepare(sql, this, false, false);
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
exports.exec = function exec(sql) {
|
|
9
|
+
this[cppdb].exec(sql);
|
|
10
|
+
return this;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
exports.close = function close() {
|
|
14
|
+
this[cppdb].close();
|
|
15
|
+
return this;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
exports.loadExtension = function loadExtension(...args) {
|
|
19
|
+
this[cppdb].loadExtension(...args);
|
|
20
|
+
return this;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
exports.defaultSafeIntegers = function defaultSafeIntegers(...args) {
|
|
24
|
+
this[cppdb].defaultSafeIntegers(...args);
|
|
25
|
+
return this;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
exports.unsafeMode = function unsafeMode(...args) {
|
|
29
|
+
this[cppdb].unsafeMode(...args);
|
|
30
|
+
return this;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
exports.getters = {
|
|
34
|
+
name: {
|
|
35
|
+
get: function name() { return this[cppdb].name; },
|
|
36
|
+
enumerable: true,
|
|
37
|
+
},
|
|
38
|
+
open: {
|
|
39
|
+
get: function open() { return this[cppdb].open; },
|
|
40
|
+
enumerable: true,
|
|
41
|
+
},
|
|
42
|
+
inTransaction: {
|
|
43
|
+
get: function inTransaction() { return this[cppdb].inTransaction; },
|
|
44
|
+
enumerable: true,
|
|
45
|
+
},
|
|
46
|
+
readonly: {
|
|
47
|
+
get: function readonly() { return this[cppdb].readonly; },
|
|
48
|
+
enumerable: true,
|
|
49
|
+
},
|
|
50
|
+
memory: {
|
|
51
|
+
get: function memory() { return this[cppdb].memory; },
|
|
52
|
+
enumerable: true,
|
|
53
|
+
},
|
|
54
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
class SqliteError extends Error {
|
|
4
|
+
constructor(message, code) {
|
|
5
|
+
if (typeof code !== 'string') {
|
|
6
|
+
throw new TypeError('Expected second argument to be a string');
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
super('' + message);
|
|
10
|
+
this.code = code;
|
|
11
|
+
|
|
12
|
+
if (typeof Error.captureStackTrace === 'function') {
|
|
13
|
+
Error.captureStackTrace(this, SqliteError);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
Object.defineProperty(SqliteError.prototype, 'name', {
|
|
19
|
+
value: 'SqliteError',
|
|
20
|
+
writable: true,
|
|
21
|
+
enumerable: false,
|
|
22
|
+
configurable: true,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
module.exports = SqliteError;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
exports.getBooleanOption = (options, key) => {
|
|
4
|
+
let value = false;
|
|
5
|
+
if (key in options && typeof (value = options[key]) !== 'boolean') {
|
|
6
|
+
throw new TypeError(`Expected the "${key}" option to be a boolean`);
|
|
7
|
+
}
|
|
8
|
+
return value;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
exports.cppdb = Symbol();
|
|
12
|
+
exports.inspect = Symbol.for('nodejs.util.inspect.custom');
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "better-sqlite3",
|
|
3
|
+
"version": "13.0.3",
|
|
4
|
+
"description": "The fastest and simplest library for SQLite in Node.js.",
|
|
5
|
+
"homepage": "http://github.com/WiseLibs/better-sqlite3",
|
|
6
|
+
"author": "Joshua Wise <joshuathomaswise@gmail.com>",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git://github.com/WiseLibs/better-sqlite3.git"
|
|
10
|
+
},
|
|
11
|
+
"main": "lib/index.js",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": "./lib/index.js",
|
|
14
|
+
"./linux-x64": "./lib/linux-x64.js",
|
|
15
|
+
"./linux-arm64": "./lib/linux-arm64.js",
|
|
16
|
+
"./linuxmusl-x64": "./lib/linuxmusl-x64.js",
|
|
17
|
+
"./linuxmusl-arm64": "./lib/linuxmusl-arm64.js",
|
|
18
|
+
"./darwin-x64": "./lib/darwin-x64.js",
|
|
19
|
+
"./darwin-arm64": "./lib/darwin-arm64.js",
|
|
20
|
+
"./win32-x64": "./lib/win32-x64.js",
|
|
21
|
+
"./win32-arm64": "./lib/win32-arm64.js",
|
|
22
|
+
"./package.json": "./package.json"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"binding.gyp",
|
|
26
|
+
"src/**/*.[ch]pp",
|
|
27
|
+
"lib/**",
|
|
28
|
+
"deps/**",
|
|
29
|
+
"prebuilds/**"
|
|
30
|
+
],
|
|
31
|
+
"gypfile": false,
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=22"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"node-addon-api": "^8.0.0"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"chai": "^4.3.8",
|
|
40
|
+
"cli-color": "^2.0.3",
|
|
41
|
+
"fs-extra": "^11.1.1",
|
|
42
|
+
"mocha": "^11.7.5",
|
|
43
|
+
"node-gyp": "^10.3.1",
|
|
44
|
+
"nodemark": "^0.3.0",
|
|
45
|
+
"sqlite": "^5.0.1",
|
|
46
|
+
"sqlite3": "^5.1.6"
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build-release": "node-gyp clean && node-gyp rebuild --release --force_build=1",
|
|
50
|
+
"build-debug": "node-gyp clean && node-gyp rebuild --debug --force_build=1",
|
|
51
|
+
"test": "mocha --exit --slow=75 --timeout=5000",
|
|
52
|
+
"benchmark": "node benchmark",
|
|
53
|
+
"download": "bash ./deps/download.sh",
|
|
54
|
+
"clean": "rm -rf node_modules build prebuilds"
|
|
55
|
+
},
|
|
56
|
+
"license": "MIT",
|
|
57
|
+
"keywords": [
|
|
58
|
+
"sql",
|
|
59
|
+
"sqlite",
|
|
60
|
+
"sqlite3",
|
|
61
|
+
"transactions",
|
|
62
|
+
"user-defined functions",
|
|
63
|
+
"aggregate functions",
|
|
64
|
+
"window functions",
|
|
65
|
+
"database"
|
|
66
|
+
]
|
|
67
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
struct Addon {
|
|
2
|
+
explicit Addon(Napi::Env env) :
|
|
3
|
+
privileged_info(NULL),
|
|
4
|
+
next_id(0),
|
|
5
|
+
cs(env) {}
|
|
6
|
+
|
|
7
|
+
static void Cleanup(Addon* addon) {
|
|
8
|
+
for (Database* db : addon->dbs) db->CloseHandles();
|
|
9
|
+
addon->dbs.clear();
|
|
10
|
+
delete addon;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
inline sqlite3_uint64 NextId() {
|
|
14
|
+
return next_id++;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
static void ConfigureURI() {
|
|
18
|
+
static std::once_flag init_flag;
|
|
19
|
+
std::call_once(init_flag, [](){
|
|
20
|
+
const char* env = getenv("SQLITE_USE_URI");
|
|
21
|
+
if (env != NULL) {
|
|
22
|
+
if (strcmp(env, "1") == 0) {
|
|
23
|
+
int status = sqlite3_config(SQLITE_CONFIG_URI, 1);
|
|
24
|
+
assert(status == SQLITE_OK); ((void)status);
|
|
25
|
+
} else if (strcmp(env, "0") == 0) {
|
|
26
|
+
int status = sqlite3_config(SQLITE_CONFIG_URI, 0);
|
|
27
|
+
assert(status == SQLITE_OK); ((void)status);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
static NODE_METHOD(JS_initialize) {
|
|
34
|
+
REQUIRE_ARGUMENT_FUNCTION(first, Napi::Function SqliteError);
|
|
35
|
+
REQUIRE_ARGUMENT_FUNCTION(second, Napi::Function ArrayFactory);
|
|
36
|
+
REQUIRE_ARGUMENT_FUNCTION(third, Napi::Function ArrayAppender);
|
|
37
|
+
REQUIRE_ARGUMENT_FUNCTION(fourth, Napi::Function RowFactory);
|
|
38
|
+
REQUIRE_ARGUMENT_FUNCTION(fifth, Napi::Function RecordFactory);
|
|
39
|
+
OnlyAddon->SqliteError = Napi::Persistent(SqliteError);
|
|
40
|
+
OnlyAddon->ArrayFactory = Napi::Persistent(ArrayFactory);
|
|
41
|
+
OnlyAddon->ArrayAppender = Napi::Persistent(ArrayAppender);
|
|
42
|
+
OnlyAddon->RowFactory = Napi::Persistent(RowFactory);
|
|
43
|
+
OnlyAddon->RecordFactory = Napi::Persistent(RecordFactory);
|
|
44
|
+
return info.Env().Undefined();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
Napi::FunctionReference Statement;
|
|
48
|
+
Napi::FunctionReference StatementIterator;
|
|
49
|
+
Napi::FunctionReference Backup;
|
|
50
|
+
Napi::FunctionReference SqliteError;
|
|
51
|
+
Napi::FunctionReference ArrayFactory;
|
|
52
|
+
Napi::FunctionReference ArrayAppender;
|
|
53
|
+
Napi::FunctionReference RowFactory;
|
|
54
|
+
Napi::FunctionReference RecordFactory;
|
|
55
|
+
NODE_ARGUMENTS_POINTER privileged_info;
|
|
56
|
+
sqlite3_uint64 next_id;
|
|
57
|
+
CS cs;
|
|
58
|
+
std::set<Database*, Database::CompareDatabase> dbs;
|
|
59
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
#include <cassert>
|
|
2
|
+
#include <climits>
|
|
3
|
+
#include <cmath>
|
|
4
|
+
#include <cstdio>
|
|
5
|
+
#include <cstring>
|
|
6
|
+
#include <string>
|
|
7
|
+
#include <vector>
|
|
8
|
+
#include <set>
|
|
9
|
+
#include <random>
|
|
10
|
+
#include <unordered_map>
|
|
11
|
+
#include <algorithm>
|
|
12
|
+
#include <mutex>
|
|
13
|
+
#include <sqlite3.h>
|
|
14
|
+
#include <napi.h>
|
|
15
|
+
|
|
16
|
+
struct Addon;
|
|
17
|
+
class Database;
|
|
18
|
+
class Statement;
|
|
19
|
+
class StatementIterator;
|
|
20
|
+
class Backup;
|
|
21
|
+
|
|
22
|
+
#include "util/macros.cpp"
|
|
23
|
+
#include "util/helpers.cpp"
|
|
24
|
+
#include "util/constants.cpp"
|
|
25
|
+
#include "util/bind-map.cpp"
|
|
26
|
+
#include "util/data-converter.cpp"
|
|
27
|
+
|
|
28
|
+
#include "util/row-builder.hpp"
|
|
29
|
+
#include "objects/backup.hpp"
|
|
30
|
+
#include "objects/statement.hpp"
|
|
31
|
+
#include "objects/database.hpp"
|
|
32
|
+
#include "addon.cpp"
|
|
33
|
+
#include "objects/statement-iterator.hpp"
|
|
34
|
+
|
|
35
|
+
#include "util/data.cpp"
|
|
36
|
+
#include "util/row-builder.cpp"
|
|
37
|
+
#include "util/query-macros.cpp"
|
|
38
|
+
#include "util/custom-function.cpp"
|
|
39
|
+
#include "util/custom-aggregate.cpp"
|
|
40
|
+
#include "util/custom-table.cpp"
|
|
41
|
+
#include "util/binder.cpp"
|
|
42
|
+
|
|
43
|
+
#include "objects/backup.cpp"
|
|
44
|
+
#include "objects/statement.cpp"
|
|
45
|
+
#include "objects/database.cpp"
|
|
46
|
+
#include "objects/statement-iterator.cpp"
|
|
47
|
+
|
|
48
|
+
Napi::Object InitAll(Napi::Env env, Napi::Object exports) {
|
|
49
|
+
Napi::HandleScope scope(env);
|
|
50
|
+
Addon::ConfigureURI();
|
|
51
|
+
|
|
52
|
+
// Initialize addon instance. The addon is bound to each native-backed class
|
|
53
|
+
// as callback data (rather than per-environment instance data) so that
|
|
54
|
+
// multiple copies of the addon can be loaded into a single environment.
|
|
55
|
+
Addon* addon = new Addon(env);
|
|
56
|
+
env.AddCleanupHook(Addon::Cleanup, addon);
|
|
57
|
+
|
|
58
|
+
// Create and export native-backed classes and functions.
|
|
59
|
+
exports.Set("Database", Database::Init(env, addon));
|
|
60
|
+
exports.Set("Statement", Statement::Init(env, addon));
|
|
61
|
+
exports.Set("StatementIterator", StatementIterator::Init(env, addon));
|
|
62
|
+
exports.Set("Backup", Backup::Init(env, addon));
|
|
63
|
+
exports.Set("initialize", Napi::Function::New(env, Addon::JS_initialize, "initialize", addon));
|
|
64
|
+
|
|
65
|
+
// Store addon instance data.
|
|
66
|
+
addon->Statement = Napi::Persistent(exports.Get("Statement").As<Napi::Function>());
|
|
67
|
+
addon->StatementIterator = Napi::Persistent(exports.Get("StatementIterator").As<Napi::Function>());
|
|
68
|
+
addon->Backup = Napi::Persistent(exports.Get("Backup").As<Napi::Function>());
|
|
69
|
+
|
|
70
|
+
return exports;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
NODE_API_MODULE(better_sqlite3, InitAll)
|