@travetto/model-postgres 8.0.0-alpha.28 → 8.0.0-alpha.29
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/package.json +7 -7
- package/src/dialect.ts +25 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/model-postgres",
|
|
3
|
-
"version": "8.0.0-alpha.
|
|
3
|
+
"version": "8.0.0-alpha.29",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "PostgreSQL backing for the travetto model module, with real-time modeling support for SQL schemas.",
|
|
6
6
|
"keywords": [
|
|
@@ -28,16 +28,16 @@
|
|
|
28
28
|
"directory": "module/model-postgres"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@travetto/config": "^8.0.0-alpha.
|
|
32
|
-
"@travetto/context": "^8.0.0-alpha.
|
|
33
|
-
"@travetto/model": "^8.0.0-alpha.
|
|
34
|
-
"@travetto/model-query": "^8.0.0-alpha.
|
|
35
|
-
"@travetto/model-sql": "^8.0.0-alpha.
|
|
31
|
+
"@travetto/config": "^8.0.0-alpha.24",
|
|
32
|
+
"@travetto/context": "^8.0.0-alpha.22",
|
|
33
|
+
"@travetto/model": "^8.0.0-alpha.25",
|
|
34
|
+
"@travetto/model-query": "^8.0.0-alpha.27",
|
|
35
|
+
"@travetto/model-sql": "^8.0.0-alpha.29",
|
|
36
36
|
"@types/pg": "^8.20.0",
|
|
37
37
|
"pg": "^8.22.0"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
|
-
"@travetto/cli": "^8.0.0-alpha.
|
|
40
|
+
"@travetto/cli": "^8.0.0-alpha.30"
|
|
41
41
|
},
|
|
42
42
|
"peerDependenciesMeta": {
|
|
43
43
|
"@travetto/cli": {
|
package/src/dialect.ts
CHANGED
|
@@ -185,6 +185,31 @@ export class PostgresDialect extends AbstractANSI99Dialect {
|
|
|
185
185
|
return { sql: `(${target.jsonbPath} IS NOT NULL AND ${target.jsonbPath} <> '[]'::jsonb)` };
|
|
186
186
|
}
|
|
187
187
|
|
|
188
|
+
compileArrayRegex(context: ResolvedPathContext, identifier: string, value: RegExp | string): { sql: string; formatted: unknown } {
|
|
189
|
+
const target = this.#getPostgresArrayTarget(context);
|
|
190
|
+
const regex = value instanceof RegExp ? value : new RegExp(String(value));
|
|
191
|
+
const caseInsensitive = regex.flags.includes('i');
|
|
192
|
+
const regexOp = this.getRegexOperator(caseInsensitive);
|
|
193
|
+
const regexSource = this.formatRegex(regex.source, caseInsensitive);
|
|
194
|
+
|
|
195
|
+
if (target.isNative) {
|
|
196
|
+
return {
|
|
197
|
+
sql: `EXISTS (SELECT 1 FROM unnest(${target.sqlPath}) AS elem WHERE elem ${regexOp} ${identifier})`,
|
|
198
|
+
formatted: regexSource
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const subAccessor =
|
|
203
|
+
context.subPath && context.subPath.length > 0
|
|
204
|
+
? `->${context.subPath.map(segment => `'${this.escapeLiteral(segment)}'`).join('->')}`
|
|
205
|
+
: '';
|
|
206
|
+
|
|
207
|
+
return {
|
|
208
|
+
sql: `EXISTS (SELECT 1 FROM jsonb_array_elements_text((${target.jsonbPath})${subAccessor}) AS elem WHERE elem ${regexOp} ${identifier})`,
|
|
209
|
+
formatted: regexSource
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
|
|
188
213
|
getRegexOperator(caseInsensitive: boolean): string {
|
|
189
214
|
return caseInsensitive ? '~*' : '~';
|
|
190
215
|
}
|