schema-typegen
Advanced tools
Comparing version 2.7.0 to 2.8.0
@@ -6,9 +6,9 @@ 'use strict' | ||
const typeMapping = { | ||
string: ['bpchar', 'char', 'varchar', 'text', 'uuid', 'bytea', 'inet', 'time', 'timetz', 'interval', 'name'], | ||
number: ['int2', 'int4', 'float4', 'float8', 'numeric', 'money', 'oid'], | ||
string: ['bpchar', 'char', 'varchar', 'text', 'numeric', 'uuid', 'bytea', 'inet', 'time', 'timetz', 'interval', 'name'], | ||
number: ['int2', 'int4', 'float4', 'float8', 'money', 'oid'], | ||
boolean: ['bool'], | ||
bigint: [], | ||
Date: ['timestamp', 'timestamptz'], | ||
'Array<string>': ['_bpchar', '_char', '_varchar', '_text', '_uuid', '_bytea', '_inet', '_time', '_timetz', '_interval', '_name'], | ||
'Array<number>': ['_int2', '_int4', '_float4', '_float8', '_numeric', '_money', '_oid'], | ||
'Array<string>': ['_bpchar', '_char', '_varchar', '_text', '_numeric', '_uuid', '_bytea', '_inet', '_time', '_timetz', '_interval', '_name'], | ||
'Array<number>': ['_int2', '_int4', '_float4', '_float8', '_money', '_oid'], | ||
'Array<boolean>': ['_bool'], | ||
@@ -36,2 +36,28 @@ 'Array<Date>': ['_timestamp', '_timestamptz'], | ||
async function getMaterializedViewDefinitions (sql, schema) { | ||
return sql` | ||
WITH materialized_views AS ( | ||
SELECT matviewname | ||
FROM pg_matviews | ||
WHERE schemaname = ${schema} | ||
) | ||
SELECT pc.relname AS name, | ||
jsonb_agg( | ||
DISTINCT jsonb_build_object( | ||
'name', pa.attname, | ||
'type', pt.typname, | ||
'isNullable', NOT pa.attnotnull | ||
)) AS columns | ||
FROM pg_attribute pa | ||
INNER JOIN pg_class pc ON pa.attrelid = pc.oid | ||
INNER JOIN pg_namespace pn ON pc.relnamespace = pn.oid | ||
INNER JOIN pg_type pt ON pa.atttypid = pt.oid | ||
INNER JOIN materialized_views mv ON pc.relname = mv.matviewname | ||
WHERE pa.attnum > 0 | ||
AND NOT pa.attisdropped | ||
AND pn.nspname = ${schema} | ||
GROUP BY pc.relname; | ||
` | ||
} | ||
function getEnumDefinitions (sql, schema) { | ||
@@ -73,4 +99,9 @@ return sql` | ||
try { | ||
const [tables, enums] = await Promise.all([getTableDefinitions(sql, schema), getEnumDefinitions(sql, schema)]) | ||
return { tables, enums, typeMapping } | ||
const [tables, enums, mViews] = await Promise.all([ | ||
getTableDefinitions(sql, schema), | ||
getEnumDefinitions(sql, schema), | ||
getMaterializedViewDefinitions(sql, schema) | ||
]) | ||
return { tables: [...tables, ...mViews], enums, typeMapping } | ||
} catch (e) { | ||
@@ -77,0 +108,0 @@ console.error(e.toString()) |
{ | ||
"name": "schema-typegen", | ||
"version": "2.7.0", | ||
"version": "2.8.0", | ||
"description": "Generate TypeScript type definitions from database schema", | ||
@@ -5,0 +5,0 @@ "main": "index.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
16395
300