Skip to content

Commit

Permalink
Merge pull request #626 from sanjaiyan-dev/master
Browse files Browse the repository at this point in the history
  • Loading branch information
soedirgo authored Nov 15, 2023
2 parents b40aec2 + cf37455 commit 173235a
Showing 1 changed file with 46 additions and 36 deletions.
82 changes: 46 additions & 36 deletions src/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,36 +37,46 @@ if (EXPORT_DOCS) {
...DEFAULT_POOL_CONFIG,
connectionString: PG_CONNECTION,
})
const { data: schemas, error: schemasError } = await pgMeta.schemas.list()
const { data: tables, error: tablesError } = await pgMeta.tables.list({
includedSchemas:
GENERATE_TYPES_INCLUDED_SCHEMAS.length > 0 ? GENERATE_TYPES_INCLUDED_SCHEMAS : undefined,
includeColumns: false,
})
const { data: views, error: viewsError } = await pgMeta.views.list({
includedSchemas:
GENERATE_TYPES_INCLUDED_SCHEMAS.length > 0 ? GENERATE_TYPES_INCLUDED_SCHEMAS : undefined,
includeColumns: false,
})
const { data: materializedViews, error: materializedViewsError } =
await pgMeta.materializedViews.list({
const [
{ data: schemas, error: schemasError },
{ data: tables, error: tablesError },
{ data: views, error: viewsError },
{ data: materializedViews, error: materializedViewsError },
{ data: columns, error: columnsError },
{ data: relationships, error: relationshipsError },
{ data: functions, error: functionsError },
{ data: types, error: typesError },
] = await Promise.all([
pgMeta.schemas.list(),
pgMeta.tables.list({
includedSchemas:
GENERATE_TYPES_INCLUDED_SCHEMAS.length > 0 ? GENERATE_TYPES_INCLUDED_SCHEMAS : undefined,
includeColumns: false,
})
const { data: columns, error: columnsError } = await pgMeta.columns.list({
includedSchemas:
GENERATE_TYPES_INCLUDED_SCHEMAS.length > 0 ? GENERATE_TYPES_INCLUDED_SCHEMAS : undefined,
})
const { data: relationships, error: relationshipsError } = await pgMeta.relationships.list()
const { data: functions, error: functionsError } = await pgMeta.functions.list({
includedSchemas:
GENERATE_TYPES_INCLUDED_SCHEMAS.length > 0 ? GENERATE_TYPES_INCLUDED_SCHEMAS : undefined,
})
const { data: types, error: typesError } = await pgMeta.types.list({
includeArrayTypes: true,
includeSystemSchemas: true,
})
}),
pgMeta.views.list({
includedSchemas:
GENERATE_TYPES_INCLUDED_SCHEMAS.length > 0 ? GENERATE_TYPES_INCLUDED_SCHEMAS : undefined,
includeColumns: false,
}),
pgMeta.materializedViews.list({
includedSchemas:
GENERATE_TYPES_INCLUDED_SCHEMAS.length > 0 ? GENERATE_TYPES_INCLUDED_SCHEMAS : undefined,
includeColumns: false,
}),
pgMeta.columns.list({
includedSchemas:
GENERATE_TYPES_INCLUDED_SCHEMAS.length > 0 ? GENERATE_TYPES_INCLUDED_SCHEMAS : undefined,
}),
pgMeta.relationships.list(),
pgMeta.functions.list({
includedSchemas:
GENERATE_TYPES_INCLUDED_SCHEMAS.length > 0 ? GENERATE_TYPES_INCLUDED_SCHEMAS : undefined,
}),
pgMeta.types.list({
includeArrayTypes: true,
includeSystemSchemas: true,
}),
])
await pgMeta.end()

if (schemasError) {
Expand Down Expand Up @@ -96,21 +106,21 @@ if (EXPORT_DOCS) {

console.log(
applyTypescriptTemplate({
schemas: schemas.filter(
schemas: schemas!.filter(
({ name }) =>
GENERATE_TYPES_INCLUDED_SCHEMAS.length === 0 ||
GENERATE_TYPES_INCLUDED_SCHEMAS.includes(name)
),
tables,
views,
materializedViews,
columns,
relationships,
functions: functions.filter(
tables: tables!,
views: views!,
materializedViews: materializedViews!,
columns: columns!,
relationships: relationships!,
functions: functions!.filter(
({ return_type }) => !['trigger', 'event_trigger'].includes(return_type)
),
types: types.filter(({ name }) => name[0] !== '_'),
arrayTypes: types.filter(({ name }) => name[0] === '_'),
types: types!.filter(({ name }) => name[0] !== '_'),
arrayTypes: types!.filter(({ name }) => name[0] === '_'),
detectOneToOneRelationships: GENERATE_TYPES_DETECT_ONE_TO_ONE_RELATIONSHIPS,
})
)
Expand Down

0 comments on commit 173235a

Please sign in to comment.