trilean-sql 1.0.1 → 1.2.0
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/README.md +65 -24
- package/dist/compile.cjs +30 -17
- package/dist/compile.d.cts +2 -1
- package/dist/compile.d.ts +2 -1
- package/dist/compile.js +30 -17
- package/dist/errors.cjs +20 -2
- package/dist/errors.d.cts +15 -3
- package/dist/errors.d.ts +15 -3
- package/dist/errors.js +20 -3
- package/dist/guard.cjs +49 -21
- package/dist/guard.d.cts +4 -0
- package/dist/guard.d.ts +4 -0
- package/dist/guard.js +49 -21
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/options.cjs +27 -0
- package/dist/options.d.cts +38 -6
- package/dist/options.d.ts +38 -6
- package/dist/options.js +26 -1
- package/package.json +4 -1
package/dist/options.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { UnknownDialectError } from "./errors.js";
|
|
1
2
|
//#region src/options.ts
|
|
2
3
|
/** The PostgreSQL type each declared value kind is cast to. `timestamptz` rather than `timestamp`: trilean's `instant` is an ISO-8601 string that may carry an offset, and parsing one as a naive `timestamp` would silently discard it. */
|
|
3
4
|
const POSTGRES_TYPE_NAME = {
|
|
@@ -6,5 +7,29 @@ const POSTGRES_TYPE_NAME = {
|
|
|
6
7
|
boolean: "boolean",
|
|
7
8
|
timestamp: "timestamptz"
|
|
8
9
|
};
|
|
10
|
+
const DIALECT_CONFIG = {
|
|
11
|
+
postgres: {
|
|
12
|
+
matches: "~",
|
|
13
|
+
notMatches: "!~",
|
|
14
|
+
placeholder: (index, castTo) => `$${String(index)}::${POSTGRES_TYPE_NAME[castTo]}`,
|
|
15
|
+
emptyMemberOfNullSuffix: "::boolean"
|
|
16
|
+
},
|
|
17
|
+
sqlite: {
|
|
18
|
+
matches: "REGEXP",
|
|
19
|
+
notMatches: "NOT REGEXP",
|
|
20
|
+
placeholder: () => "?",
|
|
21
|
+
emptyMemberOfNullSuffix: ""
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Refuses a dialect this version does not implement, before anything indexes a per-dialect table with it.
|
|
26
|
+
*
|
|
27
|
+
* Both entry points check their own argument, because both are reachable with a name the type describes but cannot enforce -- a dialect is exactly the sort of value that arrives as a configuration string asserted into the union at the boundary. Left unchecked, that name is not caught anywhere: the compiler reads an operator off `undefined` and throws a `TypeError` naming an internal field, and the guard, whose tables are only consulted for a node it actually objects to, answers "pushable" for a tree the compiler then fails on -- the one thing `findUnpushableNodeKind` exists to decide, decided wrongly.
|
|
28
|
+
*
|
|
29
|
+
* `DIALECT_CONFIG` is the list, rather than a second constant, so implementing a dialect cannot leave this behind.
|
|
30
|
+
*/
|
|
31
|
+
function assertImplementedDialect(dialect) {
|
|
32
|
+
if (!Object.hasOwn(DIALECT_CONFIG, dialect)) throw new UnknownDialectError(dialect, Object.keys(DIALECT_CONFIG));
|
|
33
|
+
}
|
|
9
34
|
//#endregion
|
|
10
|
-
export { POSTGRES_TYPE_NAME };
|
|
35
|
+
export { DIALECT_CONFIG, POSTGRES_TYPE_NAME, assertImplementedDialect };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "trilean-sql",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Compiles a trilean predicate tree into a parameterised SQL WHERE fragment, pushing three-valued logic down onto the database's own NULL propagation instead of evaluating it in process.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -70,6 +70,7 @@
|
|
|
70
70
|
"keywords": [
|
|
71
71
|
"sql",
|
|
72
72
|
"postgres",
|
|
73
|
+
"sqlite",
|
|
73
74
|
"predicate",
|
|
74
75
|
"three-valued-logic",
|
|
75
76
|
"query-builder",
|
|
@@ -82,9 +83,11 @@
|
|
|
82
83
|
"@electric-sql/pglite": "^0.5.8",
|
|
83
84
|
"@exadev/eslint-config": "^2.10.2",
|
|
84
85
|
"@testcontainers/postgresql": "^12.1.0",
|
|
86
|
+
"@types/better-sqlite3": "^9.6.0",
|
|
85
87
|
"@types/node": "^26.4.0",
|
|
86
88
|
"@types/pg": "^8.15.6",
|
|
87
89
|
"@vitest/coverage-v8": "^4.1.11",
|
|
90
|
+
"better-sqlite3": "^12.11.1",
|
|
88
91
|
"eslint": "^10.9.1",
|
|
89
92
|
"eslint-config-prettier": "^10.1.8",
|
|
90
93
|
"eslint-plugin-prettier": "^5.5.6",
|