@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.
Files changed (2) hide show
  1. package/package.json +7 -7
  2. 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.28",
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.23",
32
- "@travetto/context": "^8.0.0-alpha.21",
33
- "@travetto/model": "^8.0.0-alpha.24",
34
- "@travetto/model-query": "^8.0.0-alpha.26",
35
- "@travetto/model-sql": "^8.0.0-alpha.28",
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.29"
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
  }