schema-typegen
Advanced tools
Comparing version 2.5.1 to 2.5.2
@@ -23,12 +23,10 @@ 'use strict' | ||
jsonb_agg( | ||
jsonb_build_object( | ||
DISTINCT jsonb_build_object( | ||
'name', column_name, | ||
'type', udt_name, | ||
'isNullable', is_nullable::boolean | ||
) ORDER BY column_name | ||
) AS columns | ||
)) AS columns | ||
FROM information_schema.columns | ||
WHERE table_schema = ${schema} | ||
GROUP BY table_name | ||
ORDER BY table_name | ||
` | ||
@@ -39,3 +37,3 @@ } | ||
return sql` | ||
SELECT t.typname AS name, jsonb_agg(e.enumlabel ORDER BY e.enumlabel) AS values | ||
SELECT t.typname AS name, jsonb_agg(DISTINCT e.enumlabel) AS values | ||
FROM pg_type t | ||
@@ -46,3 +44,2 @@ INNER JOIN pg_enum e ON t.oid = e.enumtypid | ||
GROUP BY name | ||
ORDER BY name | ||
` | ||
@@ -49,0 +46,0 @@ } |
'use strict' | ||
function sortByField (name) { | ||
return function (a, b) { | ||
return a[name] < b[name] ? -1 : a[name] > b[name] ? 1 : 0 | ||
} | ||
} | ||
function toPascalCase (value) { | ||
@@ -67,2 +73,3 @@ let replaced = value.replace(/((_|-|\s)\w)/g, (token) => token[1].toUpperCase()) | ||
.filter(table => !opts.exclude.includes(table.name)) | ||
.sort(sortByField('name')) | ||
.map(table => { | ||
@@ -75,5 +82,7 @@ let tableType = getTableType(opts, table.name) | ||
table.columns.forEach(tableColumn => { | ||
tableType += ` ${formatName(tableColumn.name)}${tableColumn.isNullable && opts.optionals ? '?' : ''}: ${getColumnType(typeMapping, tableColumn.type, enums)}${tableColumn.isNullable && !opts.optionals ? ' | null' : ''}${semicolon(opts)}\n` | ||
}) | ||
table.columns | ||
.sort(sortByField('name')) | ||
.forEach(tableColumn => { | ||
tableType += ` ${formatName(tableColumn.name)}${tableColumn.isNullable && opts.optionals ? '?' : ''}: ${getColumnType(typeMapping, tableColumn.type, enums)}${tableColumn.isNullable && !opts.optionals ? ' | null' : ''}${semicolon(opts)}\n` | ||
}) | ||
@@ -88,2 +97,3 @@ tableType += `}${semicolon(opts)}\n` | ||
.filter(entry => !opts.exclude.includes(entry.name)) | ||
.sort(sortByField('name')) | ||
.map(entry => { | ||
@@ -96,3 +106,3 @@ let enumType = `export enum ${toPascalCase(entry.name)} {` | ||
entry.values.forEach(value => { | ||
entry.values.sort().forEach(value => { | ||
enumType += ` ${formatEnumName(opts, value)} = '${value}',\n` | ||
@@ -99,0 +109,0 @@ }) |
{ | ||
"name": "schema-typegen", | ||
"version": "2.5.1", | ||
"version": "2.5.2", | ||
"description": "Generate TypeScript type definitions from database schema", | ||
@@ -5,0 +5,0 @@ "main": "schema-typegen.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15317
262