@gjsify/sqlite 0.3.13 → 0.3.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/esm/constants.js +49 -93
- package/lib/esm/data-model-reader.js +69 -73
- package/lib/esm/database-sync.js +374 -395
- package/lib/esm/errors.js +63 -69
- package/lib/esm/index.js +4 -7
- package/lib/esm/param-binding.js +103 -105
- package/lib/esm/statement-sync.js +291 -283
- package/package.json +6 -6
package/lib/esm/errors.js
CHANGED
|
@@ -1,70 +1,64 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
class InvalidStateError extends Error {
|
|
13
|
-
code = "ERR_INVALID_STATE";
|
|
14
|
-
constructor(message) {
|
|
15
|
-
super(message);
|
|
16
|
-
this.name = "InvalidStateError";
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
class InvalidArgTypeError extends TypeError {
|
|
20
|
-
code = "ERR_INVALID_ARG_TYPE";
|
|
21
|
-
constructor(message) {
|
|
22
|
-
super(message);
|
|
23
|
-
this.name = "InvalidArgTypeError";
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
class InvalidArgValueError extends Error {
|
|
27
|
-
code = "ERR_INVALID_ARG_VALUE";
|
|
28
|
-
constructor(message) {
|
|
29
|
-
super(message);
|
|
30
|
-
this.name = "InvalidArgValueError";
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
class OutOfRangeError extends RangeError {
|
|
34
|
-
code = "ERR_OUT_OF_RANGE";
|
|
35
|
-
constructor(message) {
|
|
36
|
-
super(message);
|
|
37
|
-
this.name = "OutOfRangeError";
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
class ConstructCallRequiredError extends TypeError {
|
|
41
|
-
code = "ERR_CONSTRUCT_CALL_REQUIRED";
|
|
42
|
-
constructor(name) {
|
|
43
|
-
super(`Cannot call constructor without \`new\`: ${name}`);
|
|
44
|
-
this.name = "ConstructCallRequiredError";
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
class InvalidUrlSchemeError extends TypeError {
|
|
48
|
-
code = "ERR_INVALID_URL_SCHEME";
|
|
49
|
-
constructor(message = "The URL must be of scheme file:") {
|
|
50
|
-
super(message);
|
|
51
|
-
this.name = "InvalidUrlSchemeError";
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
class IllegalConstructorError extends TypeError {
|
|
55
|
-
code = "ERR_ILLEGAL_CONSTRUCTOR";
|
|
56
|
-
constructor() {
|
|
57
|
-
super("Illegal constructor");
|
|
58
|
-
this.name = "IllegalConstructorError";
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
export {
|
|
62
|
-
ConstructCallRequiredError,
|
|
63
|
-
IllegalConstructorError,
|
|
64
|
-
InvalidArgTypeError,
|
|
65
|
-
InvalidArgValueError,
|
|
66
|
-
InvalidStateError,
|
|
67
|
-
InvalidUrlSchemeError,
|
|
68
|
-
OutOfRangeError,
|
|
69
|
-
SqliteError
|
|
1
|
+
//#region src/errors.ts
|
|
2
|
+
var SqliteError = class extends Error {
|
|
3
|
+
code = "ERR_SQLITE_ERROR";
|
|
4
|
+
errcode;
|
|
5
|
+
errstr;
|
|
6
|
+
constructor(message, errcode = 0, errstr = "") {
|
|
7
|
+
super(message);
|
|
8
|
+
this.name = "SqliteError";
|
|
9
|
+
this.errcode = errcode;
|
|
10
|
+
this.errstr = errstr || message;
|
|
11
|
+
}
|
|
70
12
|
};
|
|
13
|
+
var InvalidStateError = class extends Error {
|
|
14
|
+
code = "ERR_INVALID_STATE";
|
|
15
|
+
constructor(message) {
|
|
16
|
+
super(message);
|
|
17
|
+
this.name = "InvalidStateError";
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
var InvalidArgTypeError = class extends TypeError {
|
|
21
|
+
code = "ERR_INVALID_ARG_TYPE";
|
|
22
|
+
constructor(message) {
|
|
23
|
+
super(message);
|
|
24
|
+
this.name = "InvalidArgTypeError";
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
var InvalidArgValueError = class extends Error {
|
|
28
|
+
code = "ERR_INVALID_ARG_VALUE";
|
|
29
|
+
constructor(message) {
|
|
30
|
+
super(message);
|
|
31
|
+
this.name = "InvalidArgValueError";
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
var OutOfRangeError = class extends RangeError {
|
|
35
|
+
code = "ERR_OUT_OF_RANGE";
|
|
36
|
+
constructor(message) {
|
|
37
|
+
super(message);
|
|
38
|
+
this.name = "OutOfRangeError";
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
var ConstructCallRequiredError = class extends TypeError {
|
|
42
|
+
code = "ERR_CONSTRUCT_CALL_REQUIRED";
|
|
43
|
+
constructor(name) {
|
|
44
|
+
super(`Cannot call constructor without \`new\`: ${name}`);
|
|
45
|
+
this.name = "ConstructCallRequiredError";
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var InvalidUrlSchemeError = class extends TypeError {
|
|
49
|
+
code = "ERR_INVALID_URL_SCHEME";
|
|
50
|
+
constructor(message = "The URL must be of scheme file:") {
|
|
51
|
+
super(message);
|
|
52
|
+
this.name = "InvalidUrlSchemeError";
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
var IllegalConstructorError = class extends TypeError {
|
|
56
|
+
code = "ERR_ILLEGAL_CONSTRUCTOR";
|
|
57
|
+
constructor() {
|
|
58
|
+
super("Illegal constructor");
|
|
59
|
+
this.name = "IllegalConstructorError";
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
//#endregion
|
|
64
|
+
export { ConstructCallRequiredError, IllegalConstructorError, InvalidArgTypeError, InvalidArgValueError, InvalidStateError, InvalidUrlSchemeError, OutOfRangeError, SqliteError };
|
package/lib/esm/index.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import { DatabaseSync } from "./database-sync.js";
|
|
2
|
-
import { StatementSync } from "./statement-sync.js";
|
|
3
1
|
import { constants } from "./constants.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
};
|
|
2
|
+
import { StatementSync } from "./statement-sync.js";
|
|
3
|
+
import { DatabaseSync } from "./database-sync.js";
|
|
4
|
+
|
|
5
|
+
export { DatabaseSync, StatementSync, constants };
|
package/lib/esm/param-binding.js
CHANGED
|
@@ -1,114 +1,112 @@
|
|
|
1
1
|
import { InvalidArgTypeError, InvalidArgValueError, InvalidStateError, SqliteError } from "./errors.js";
|
|
2
|
+
|
|
3
|
+
//#region src/param-binding.ts
|
|
2
4
|
const MAX_INT64 = 9223372036854775807n;
|
|
3
5
|
const MIN_INT64 = -9223372036854775808n;
|
|
4
6
|
function validateBindValue(value, paramIndex) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
`Provided value cannot be bound to SQLite parameter ${paramIndex}.`
|
|
12
|
-
);
|
|
7
|
+
if (value === null || value === undefined) return;
|
|
8
|
+
const t = typeof value;
|
|
9
|
+
if (t === "number" || t === "bigint" || t === "string" || t === "boolean") return;
|
|
10
|
+
if (value instanceof Uint8Array || value instanceof ArrayBuffer) return;
|
|
11
|
+
if (ArrayBuffer.isView(value)) return;
|
|
12
|
+
throw new InvalidArgTypeError(`Provided value cannot be bound to SQLite parameter ${paramIndex}.`);
|
|
13
13
|
}
|
|
14
14
|
function setHolderValue(holder, value) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
holder.set_value(value);
|
|
15
|
+
if (value === null || value === undefined) {
|
|
16
|
+
holder.set_value(null);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (typeof value === "number") {
|
|
20
|
+
holder.set_value(value);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (typeof value === "bigint") {
|
|
24
|
+
if (value > MAX_INT64 || value < MIN_INT64) {
|
|
25
|
+
throw new InvalidArgValueError(`BigInt value is too large to bind.`);
|
|
26
|
+
}
|
|
27
|
+
holder.set_value(Number(value));
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (typeof value === "string") {
|
|
31
|
+
holder.set_value(value);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (typeof value === "boolean") {
|
|
35
|
+
holder.set_value(value ? 1 : 0);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (value instanceof Uint8Array || ArrayBuffer.isView(value)) {
|
|
39
|
+
const bytes = value instanceof Uint8Array ? value : new Uint8Array(value.buffer);
|
|
40
|
+
holder.set_value(bytes);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
holder.set_value(value);
|
|
46
44
|
}
|
|
47
45
|
function bindParameters(paramSet, anonymousArgs, namedArgs, ctx) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
46
|
+
if (!paramSet) {
|
|
47
|
+
if (anonymousArgs.length > 0) {
|
|
48
|
+
throw new SqliteError("column index out of range", 25, "column index out of range");
|
|
49
|
+
}
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const holders = paramSet.get_holders();
|
|
53
|
+
if (namedArgs) {
|
|
54
|
+
const usedKeys = new Set();
|
|
55
|
+
for (const holder of holders) {
|
|
56
|
+
const id = holder.get_id();
|
|
57
|
+
let value = undefined;
|
|
58
|
+
let found = false;
|
|
59
|
+
if (id in namedArgs) {
|
|
60
|
+
value = namedArgs[id];
|
|
61
|
+
usedKeys.add(id);
|
|
62
|
+
found = true;
|
|
63
|
+
}
|
|
64
|
+
if (!found && ctx.allowBareNamedParameters) {
|
|
65
|
+
const bareName = id.replace(/^[\$:@]/, "");
|
|
66
|
+
if (bareName in namedArgs) {
|
|
67
|
+
value = namedArgs[bareName];
|
|
68
|
+
usedKeys.add(bareName);
|
|
69
|
+
found = true;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (!found && !ctx.allowBareNamedParameters) {
|
|
73
|
+
const bareName = id.replace(/^[\$:@]/, "");
|
|
74
|
+
if (bareName in namedArgs) {
|
|
75
|
+
throw new InvalidStateError(`Unknown named parameter '${bareName}'`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (found) {
|
|
79
|
+
const paramIdx = holders.indexOf(holder) + 1;
|
|
80
|
+
validateBindValue(value, paramIdx);
|
|
81
|
+
setHolderValue(holder, value);
|
|
82
|
+
} else {
|
|
83
|
+
setHolderValue(holder, null);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (!ctx.allowUnknownNamedParameters) {
|
|
87
|
+
for (const key of Object.keys(namedArgs)) {
|
|
88
|
+
if (!usedKeys.has(key)) {
|
|
89
|
+
const matchesHolder = holders.some((h) => {
|
|
90
|
+
const id = h.get_id();
|
|
91
|
+
return id === key || id.replace(/^[\$:@]/, "") === key;
|
|
92
|
+
});
|
|
93
|
+
if (!matchesHolder) {
|
|
94
|
+
throw new InvalidStateError(`Unknown named parameter '${key}'`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
} else {
|
|
100
|
+
if (anonymousArgs.length > holders.length) {
|
|
101
|
+
throw new SqliteError("column index out of range", 25, "column index out of range");
|
|
102
|
+
}
|
|
103
|
+
for (let i = 0; i < holders.length; i++) {
|
|
104
|
+
const value = i < anonymousArgs.length ? anonymousArgs[i] : undefined;
|
|
105
|
+
validateBindValue(value, i + 1);
|
|
106
|
+
setHolderValue(holders[i], value ?? null);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
111
109
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
};
|
|
110
|
+
|
|
111
|
+
//#endregion
|
|
112
|
+
export { bindParameters };
|