Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

schema-typegen

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

schema-typegen - npm Package Compare versions

Comparing version 2.7.0 to 2.8.0

43

lib/postgres.js

@@ -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())

2

package.json
{
"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",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc