@travetto/model-mysql 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 +3 -3
  2. package/src/dialect.ts +25 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/model-mysql",
3
- "version": "8.0.0-alpha.28",
3
+ "version": "8.0.0-alpha.29",
4
4
  "type": "module",
5
5
  "description": "MySQL backing for the travetto model module, with real-time modeling support for SQL schemas.",
6
6
  "keywords": [
@@ -31,8 +31,8 @@
31
31
  "@travetto/config": "^8.0.0-alpha.23",
32
32
  "@travetto/context": "^8.0.0-alpha.21",
33
33
  "@travetto/model": "^8.0.0-alpha.24",
34
- "@travetto/model-query": "^8.0.0-alpha.25",
35
- "@travetto/model-sql": "^8.0.0-alpha.27",
34
+ "@travetto/model-query": "^8.0.0-alpha.26",
35
+ "@travetto/model-sql": "^8.0.0-alpha.28",
36
36
  "mysql2": "^3.23.1"
37
37
  },
38
38
  "peerDependencies": {
package/src/dialect.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { AbstractANSI99Dialect, type JSONSqlPathMode, type ResolvedPathContext, type TableContext } from '@travetto/model-sql';
2
2
  import { type Class, castTo, JSONUtil } from '@travetto/runtime';
3
- import type { SchemaFieldConfig } from '@travetto/schema';
3
+ import { type SchemaFieldConfig, SchemaRegistryIndex } from '@travetto/schema';
4
4
 
5
5
  export class MysqlDialect extends AbstractANSI99Dialect {
6
6
  override returningSupport = false;
@@ -64,13 +64,36 @@ export class MysqlDialect extends AbstractANSI99Dialect {
64
64
  }
65
65
  }
66
66
 
67
+ #formatSubPath(context: ResolvedPathContext): string {
68
+ if (!context.subPath || context.subPath.length === 0) {
69
+ return '';
70
+ }
71
+ let currentClass: Class | undefined = context.arrayField?.type;
72
+ const parts: string[] = [];
73
+ for (let index = 0; index < context.subPath.length; index++) {
74
+ const segment = context.subPath[index];
75
+ if (currentClass) {
76
+ const classConfig = SchemaRegistryIndex.getOptional(currentClass)?.get();
77
+ const fieldConfig = classConfig?.fields[segment];
78
+ if (fieldConfig) {
79
+ parts.push(fieldConfig.array ? `${segment}[*]` : segment);
80
+ currentClass = fieldConfig.type;
81
+ continue;
82
+ }
83
+ }
84
+ parts.push(segment);
85
+ }
86
+ return parts.join('.');
87
+ }
88
+
67
89
  #getArraySqlPath(context: ResolvedPathContext): string {
68
90
  if (!context.arrayPath || context.arrayPath.length === 0 || !context.subPath || context.subPath.length === 0) {
69
91
  return context.sqlPath;
70
92
  }
71
93
  const columnName = this.escapeIdentifier(context.arrayPath[0]);
72
94
  const arrayPathPart = context.arrayPath.length > 1 ? context.arrayPath.slice(1).join('.') : '';
73
- const jsonPathExpr = arrayPathPart ? `$.${arrayPathPart}[*].${context.subPath.join('.')}` : `$[*].${context.subPath.join('.')}`;
95
+ const formattedSubPath = this.#formatSubPath(context);
96
+ const jsonPathExpr = arrayPathPart ? `$.${arrayPathPart}[*].${formattedSubPath}` : `$[*].${formattedSubPath}`;
74
97
  return `JSON_EXTRACT(${columnName}, '${jsonPathExpr}')`;
75
98
  }
76
99