@platformatic/sql-mapper 3.63.0 → 3.65.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/lib/entity.js +10 -0
- package/lib/queries/pg.js +18 -11
- package/package.json +3 -3
package/lib/entity.js
CHANGED
|
@@ -604,6 +604,16 @@ export function buildEntity (
|
|
|
604
604
|
schemaList?.length > 0 ? schemaList.includes(constraint.foreign_table_schema) : true
|
|
605
605
|
/* istanbul ignore if */
|
|
606
606
|
if (constraint.constraint_type === 'FOREIGN KEY' && isForeignKeySchemaInConfig) {
|
|
607
|
+
/* istanbul ignore next */
|
|
608
|
+
if (!constraint.foreign_table_name) {
|
|
609
|
+
// The referenced side of the foreign key could not be resolved by the introspection
|
|
610
|
+
// query. Ignore the relation rather than failing the whole boot.
|
|
611
|
+
log.warn(
|
|
612
|
+
{ constraint },
|
|
613
|
+
`Could not resolve the table referenced by the foreign key "${constraint.constraint_name}" on "${constraint.table_name}.${constraint.column_name}". The relation will be ignored.`
|
|
614
|
+
)
|
|
615
|
+
continue
|
|
616
|
+
}
|
|
607
617
|
field.foreignKey = true
|
|
608
618
|
const foreignEntityName = singularize(
|
|
609
619
|
camelcase(
|
package/lib/queries/pg.js
CHANGED
|
@@ -80,8 +80,8 @@ export async function listColumns (db, sql, table, schema) {
|
|
|
80
80
|
|
|
81
81
|
export async function listConstraints (db, sql, table, schema) {
|
|
82
82
|
const query = sql`
|
|
83
|
-
SELECT constraints.*, usage.*,
|
|
84
|
-
|
|
83
|
+
SELECT constraints.*, usage.*, foreign_table.relname AS foreign_table_name,
|
|
84
|
+
foreign_column.attname AS foreign_column_name, foreign_namespace.nspname AS foreign_table_schema
|
|
85
85
|
FROM information_schema.table_constraints constraints
|
|
86
86
|
JOIN information_schema.key_column_usage usage
|
|
87
87
|
ON constraints.constraint_catalog = usage.constraint_catalog
|
|
@@ -89,15 +89,22 @@ export async function listConstraints (db, sql, table, schema) {
|
|
|
89
89
|
AND constraints.constraint_name = usage.constraint_name
|
|
90
90
|
AND constraints.table_schema = usage.table_schema
|
|
91
91
|
AND constraints.table_name = usage.table_name
|
|
92
|
-
LEFT JOIN
|
|
93
|
-
ON
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
AND
|
|
100
|
-
AND
|
|
92
|
+
LEFT JOIN pg_catalog.pg_namespace local_namespace
|
|
93
|
+
ON local_namespace.nspname = constraints.table_schema
|
|
94
|
+
LEFT JOIN pg_catalog.pg_class local_table
|
|
95
|
+
ON local_table.relname = constraints.table_name
|
|
96
|
+
AND local_table.relnamespace = local_namespace.oid
|
|
97
|
+
LEFT JOIN pg_catalog.pg_constraint foreign_constraint
|
|
98
|
+
ON foreign_constraint.conrelid = local_table.oid
|
|
99
|
+
AND foreign_constraint.conname = constraints.constraint_name
|
|
100
|
+
AND foreign_constraint.contype = 'f'
|
|
101
|
+
LEFT JOIN pg_catalog.pg_class foreign_table
|
|
102
|
+
ON foreign_table.oid = foreign_constraint.confrelid
|
|
103
|
+
LEFT JOIN pg_catalog.pg_namespace foreign_namespace
|
|
104
|
+
ON foreign_namespace.oid = foreign_table.relnamespace
|
|
105
|
+
LEFT JOIN pg_catalog.pg_attribute foreign_column
|
|
106
|
+
ON foreign_column.attrelid = foreign_constraint.confrelid
|
|
107
|
+
AND foreign_column.attnum = foreign_constraint.confkey[usage.ordinal_position]
|
|
101
108
|
WHERE constraints.table_name = ${table}
|
|
102
109
|
AND constraints.table_schema = ${schema}
|
|
103
110
|
ORDER BY usage.constraint_name, usage.ordinal_position
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platformatic/sql-mapper",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.65.0",
|
|
4
4
|
"description": "A data mapper utility for SQL databases",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"camelcase": "^6.3.0",
|
|
36
36
|
"fastify-plugin": "^6.0.0",
|
|
37
37
|
"inflected": "^2.1.0",
|
|
38
|
-
"@platformatic/
|
|
39
|
-
"@platformatic/
|
|
38
|
+
"@platformatic/foundation": "3.65.0",
|
|
39
|
+
"@platformatic/telemetry": "3.65.0"
|
|
40
40
|
},
|
|
41
41
|
"engines": {
|
|
42
42
|
"node": ">=22.19.0"
|