@travetto/model-postgres 8.0.0-alpha.29 → 8.0.0-alpha.30

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 +2 -2
  2. package/src/dialect.ts +12 -18
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/model-postgres",
3
- "version": "8.0.0-alpha.29",
3
+ "version": "8.0.0-alpha.30",
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": [
@@ -32,7 +32,7 @@
32
32
  "@travetto/context": "^8.0.0-alpha.22",
33
33
  "@travetto/model": "^8.0.0-alpha.25",
34
34
  "@travetto/model-query": "^8.0.0-alpha.27",
35
- "@travetto/model-sql": "^8.0.0-alpha.29",
35
+ "@travetto/model-sql": "^8.0.0-alpha.30",
36
36
  "@types/pg": "^8.20.0",
37
37
  "pg": "^8.22.0"
38
38
  },
package/src/dialect.ts CHANGED
@@ -74,29 +74,23 @@ export class PostgresDialect extends AbstractANSI99Dialect {
74
74
  return `$${index}`;
75
75
  }
76
76
 
77
+ override getUpsertSQL(
78
+ context: TableContext,
79
+ columns: string[],
80
+ placeholders: string[],
81
+ conflictTarget: string[],
82
+ updates: string[]
83
+ ): string {
84
+ return `INSERT INTO ${this.escapeIdentifier(context.tableName)} (${columns.join(', ')}) VALUES (${placeholders.join(', ')}) ON CONFLICT (${conflictTarget.join(', ')}) DO UPDATE SET ${updates.join(', ')} RETURNING *;`;
85
+ }
86
+
77
87
  #buildContainmentPayload(value: unknown, context: ResolvedPathContext): unknown {
78
88
  if (!context.subPath || context.subPath.length === 0) {
79
89
  return Array.isArray(value) ? value : [value];
80
90
  }
81
91
 
82
- const isArraySegment = new Array<boolean>(context.subPath.length).fill(false);
83
- let currentClass: Class | undefined = context.arrayField?.type;
84
- for (let index = 0; index < context.subPath.length; index++) {
85
- if (!currentClass) {
86
- break;
87
- }
88
- const segment = context.subPath[index];
89
- const classConfig = SchemaRegistryIndex.getOptional(currentClass)?.get();
90
- const fieldConfig = classConfig?.fields[segment];
91
- if (fieldConfig) {
92
- if (fieldConfig.array) {
93
- isArraySegment[index] = true;
94
- }
95
- currentClass = fieldConfig.type;
96
- } else {
97
- break;
98
- }
99
- }
92
+ const subPathMetadata = this.getSchemaSubPathMetadata(context.arrayField?.type, context.subPath);
93
+ const isArraySegment = subPathMetadata.map(item => item.isArray);
100
94
 
101
95
  const buildPayloadForValue = (item: unknown): unknown => {
102
96
  let itemPayload: unknown = item;