@platformatic/sql-mapper 0.12.1 → 0.13.1

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 CHANGED
@@ -330,7 +330,7 @@ function createMapper (defaultDb, sql, log, table, fields, primaryKeys, relation
330
330
  }
331
331
  }
332
332
 
333
- async function buildEntity (db, sql, log, table, queries, autoTimestamp, schema, useSchemaInName, ignore, limitConfig) {
333
+ async function buildEntity (db, sql, log, table, queries, autoTimestamp, schema, useSchemaInName, ignore, limitConfig, schemaList) {
334
334
  // Compute the columns
335
335
  const columns = (await queries.listColumns(db, sql, table, schema)).filter((c) => !ignore[c.column_name])
336
336
  const fields = columns.reduce((acc, column) => {
@@ -409,15 +409,14 @@ async function buildEntity (db, sql, log, table, queries, autoTimestamp, schema,
409
409
  field.primaryKey = true
410
410
  }
411
411
 
412
- if (constraint.constraint_type === 'FOREIGN KEY') {
412
+ // we need to ignore for coverage here because cannot be covered with sqlite (no schema support)
413
+ // istanbul ignore next
414
+ const isForeignKeySchemaInConfig = schemaList?.length > 0 ? schemaList.includes(constraint.foreign_table_schema) : true
415
+ /* istanbul ignore if */
416
+ if (constraint.constraint_type === 'FOREIGN KEY' && isForeignKeySchemaInConfig) {
413
417
  field.foreignKey = true
414
-
415
- // we need to ignore for coverage here becasue cannot be covered with sqlite (no schema support)
416
- // istanbul ignore next
417
418
  const foreignEntityName = singularize(camelcase(useSchemaInName ? camelcase(`${constraint.foreign_table_schema} ${constraint.foreign_table_name}`) : constraint.foreign_table_name))
418
- // istanbul ignore next
419
419
  const entityName = singularize(camelcase(useSchemaInName ? camelcase(`${constraint.table_schema} ${constraint.table_name}`) : constraint.table_name))
420
- // istanbul ignore next
421
420
  const loweredTableWithSchemaName = lowerCaseFirst(useSchemaInName ? camelcase(`${constraint.table_schema} ${camelcase(constraint.table_name)}`) : camelcase(constraint.table_name))
422
421
  constraint.loweredTableWithSchemaName = loweredTableWithSchemaName
423
422
  constraint.foreignEntityName = foreignEntityName
package/mapper.js CHANGED
@@ -122,7 +122,7 @@ async function connect ({ connectionString, log, onDatabaseLoad, poolSize = 10,
122
122
  if (ignore[table] === true) {
123
123
  continue
124
124
  }
125
- const entity = await buildEntity(db, sql, log, table, queries, autoTimestamp, schema, useSchema, ignore[table] || {}, limit)
125
+ const entity = await buildEntity(db, sql, log, table, queries, autoTimestamp, schema, useSchema, ignore[table] || {}, limit, schemaList)
126
126
  // Check for primary key of all entities
127
127
  if (entity.primaryKeys.size === 0) {
128
128
  log.warn({ table }, 'Cannot find any primary keys for table')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/sql-mapper",
3
- "version": "0.12.1",
3
+ "version": "0.13.1",
4
4
  "description": "A data mapper utility for SQL databases",
5
5
  "main": "mapper.js",
6
6
  "repository": {