diff --git a/packages/pg-meta/src/pg-meta-columns.ts b/packages/pg-meta/src/pg-meta-columns.ts index f995ec9ce5e..682bb6e48e3 100644 --- a/packages/pg-meta/src/pg-meta-columns.ts +++ b/packages/pg-meta/src/pg-meta-columns.ts @@ -1,8 +1,8 @@ +import { z } from 'zod' import { DEFAULT_SYSTEM_SCHEMAS } from './constants' import { filterByList, filterByValue } from './helpers' import { ident, literal } from './pg-format' import { COLUMNS_SQL } from './sql/columns' -import { z } from 'zod' const pgColumnZod = z.object({ id: z.string(), diff --git a/packages/pg-meta/src/pg-meta-foreign-tables.ts b/packages/pg-meta/src/pg-meta-foreign-tables.ts index 1f048a5aef7..eda0a73b6ef 100644 --- a/packages/pg-meta/src/pg-meta-foreign-tables.ts +++ b/packages/pg-meta/src/pg-meta-foreign-tables.ts @@ -1,10 +1,10 @@ -import { literal, ident } from './pg-format' import { z } from 'zod' import { DEFAULT_SYSTEM_SCHEMAS } from './constants' -import { filterByList, coalesceRowsToArray } from './helpers' -import { FOREIGN_TABLES_SQL } from './sql/foreign-tables' -import { COLUMNS_SQL } from './sql/columns' +import { coalesceRowsToArray, filterByList } from './helpers' +import { ident, literal } from './pg-format' import { pgColumnArrayZod } from './pg-meta-columns' +import { COLUMNS_SQL } from './sql/columns' +import { FOREIGN_TABLES_SQL } from './sql/foreign-tables' export const pgForeignTableZod = z.object({ id: z.number(), diff --git a/packages/pg-meta/src/pg-meta-materialized-views.ts b/packages/pg-meta/src/pg-meta-materialized-views.ts index d585ac351b5..84a7cd0e772 100644 --- a/packages/pg-meta/src/pg-meta-materialized-views.ts +++ b/packages/pg-meta/src/pg-meta-materialized-views.ts @@ -1,10 +1,10 @@ -import { literal, ident } from './pg-format' import { z } from 'zod' import { DEFAULT_SYSTEM_SCHEMAS } from './constants' -import { filterByList, coalesceRowsToArray } from './helpers' -import { MATERIALIZED_VIEWS_SQL } from './sql/materialized-views' -import { COLUMNS_SQL } from './sql/columns' +import { coalesceRowsToArray, filterByList } from './helpers' +import { ident, literal } from './pg-format' import { pgColumnArrayZod } from './pg-meta-columns' +import { COLUMNS_SQL } from './sql/columns' +import { MATERIALIZED_VIEWS_SQL } from './sql/materialized-views' export const pgMaterializedViewZod = z.object({ id: z.number(), @@ -86,7 +86,7 @@ export function retrieve(identifier: MaterializedViewIdentifier): { sql: string zod: typeof pgMaterializedViewOptionalZod } { - let whereClause = getIdentifierWhereClause(identifier) + const whereClause = getIdentifierWhereClause(identifier) const sql = `${generateEnrichedMaterializedViewsSql({ includeColumns: true })} where ${whereClause};` return { diff --git a/packages/pg-meta/src/pg-meta-tables.ts b/packages/pg-meta/src/pg-meta-tables.ts index 8f22e8f4e9e..e52ba541a83 100644 --- a/packages/pg-meta/src/pg-meta-tables.ts +++ b/packages/pg-meta/src/pg-meta-tables.ts @@ -1,10 +1,10 @@ import { z } from 'zod' -import { coalesceRowsToArray, filterByList, filterByValue } from './helpers' -import { TABLES_SQL } from './sql/tables' -import { COLUMNS_SQL } from './sql/columns' import { DEFAULT_SYSTEM_SCHEMAS } from './constants' +import { coalesceRowsToArray, filterByList, filterByValue } from './helpers' import { ident, literal } from './pg-format' import { pgColumnArrayZod } from './pg-meta-columns' +import { COLUMNS_SQL } from './sql/columns' +import { TABLES_SQL } from './sql/tables' const pgTablePrimaryKeyZod = z.object({ table_id: z.number(), @@ -129,7 +129,9 @@ type TableCreateParams = { comment?: string } -function create({ name, schema = 'public', comment }: TableCreateParams): { sql: string } { +function create({ name, schema = 'public', comment }: TableCreateParams): { + sql: string +} { const tableSql = `CREATE TABLE ${ident(schema)}.${ident(name)} ();` const commentSql = comment === undefined diff --git a/packages/pg-meta/src/pg-meta-views.ts b/packages/pg-meta/src/pg-meta-views.ts index 78122d01188..64665659cf4 100644 --- a/packages/pg-meta/src/pg-meta-views.ts +++ b/packages/pg-meta/src/pg-meta-views.ts @@ -1,10 +1,10 @@ -import { literal, ident } from './pg-format' import { z } from 'zod' import { DEFAULT_SYSTEM_SCHEMAS } from './constants' -import { filterByList, coalesceRowsToArray } from './helpers' -import { VIEWS_SQL } from './sql/views' -import { COLUMNS_SQL } from './sql/columns' +import { coalesceRowsToArray, filterByList } from './helpers' +import { ident, literal } from './pg-format' import { pgColumnArrayZod } from './pg-meta-columns' +import { COLUMNS_SQL } from './sql/columns' +import { VIEWS_SQL } from './sql/views' export const pgViewZod = z.object({ id: z.number(), @@ -84,7 +84,7 @@ export function retrieve(identifier: ViewIdentifier): { sql: string zod: typeof pgViewOptionalZod } { - let whereClause = getIdentifierWhereClause(identifier) + const whereClause = getIdentifierWhereClause(identifier) const sql = `${generateEnrichedViewsSql({ includeColumns: true })} where ${whereClause};` return { diff --git a/packages/pg-meta/test/tables.test.ts b/packages/pg-meta/test/tables.test.ts index d6a0d25a01c..1f646cee9ba 100644 --- a/packages/pg-meta/test/tables.test.ts +++ b/packages/pg-meta/test/tables.test.ts @@ -585,6 +585,26 @@ withTestDatabase('retrieve table by id', async ({ executeQuery }) => { { "bytes": Any, "columns": [ + { + "check": null, + "comment": null, + "data_type": "integer", + "default_value": "nextval('memes_id_seq'::regclass)", + "enums": [], + "format": "int4", + "id": "16510.1", + "identity_generation": null, + "is_generated": false, + "is_identity": false, + "is_nullable": false, + "is_unique": false, + "is_updatable": true, + "name": "id", + "ordinal_position": 1, + "schema": "public", + "table": "memes", + "table_id": 16510, + }, { "check": null, "comment": null, @@ -665,26 +685,6 @@ withTestDatabase('retrieve table by id', async ({ executeQuery }) => { "table": "memes", "table_id": 16510, }, - { - "check": null, - "comment": null, - "data_type": "integer", - "default_value": "nextval('memes_id_seq'::regclass)", - "enums": [], - "format": "int4", - "id": "16510.1", - "identity_generation": null, - "is_generated": false, - "is_identity": false, - "is_nullable": false, - "is_unique": false, - "is_updatable": true, - "name": "id", - "ordinal_position": 1, - "schema": "public", - "table": "memes", - "table_id": 16510, - }, { "check": null, "comment": null, @@ -761,6 +761,26 @@ withTestDatabase('retrieve table by name and schema', async ({ executeQuery }) = { "bytes": Any, "columns": [ + { + "check": null, + "comment": null, + "data_type": "integer", + "default_value": "nextval('memes_id_seq'::regclass)", + "enums": [], + "format": "int4", + "id": "16510.1", + "identity_generation": null, + "is_generated": false, + "is_identity": false, + "is_nullable": false, + "is_unique": false, + "is_updatable": true, + "name": "id", + "ordinal_position": 1, + "schema": "public", + "table": "memes", + "table_id": 16510, + }, { "check": null, "comment": null, @@ -841,26 +861,6 @@ withTestDatabase('retrieve table by name and schema', async ({ executeQuery }) = "table": "memes", "table_id": 16510, }, - { - "check": null, - "comment": null, - "data_type": "integer", - "default_value": "nextval('memes_id_seq'::regclass)", - "enums": [], - "format": "int4", - "id": "16510.1", - "identity_generation": null, - "is_generated": false, - "is_identity": false, - "is_nullable": false, - "is_unique": false, - "is_updatable": true, - "name": "id", - "ordinal_position": 1, - "schema": "public", - "table": "memes", - "table_id": 16510, - }, { "check": null, "comment": null, @@ -921,7 +921,7 @@ withTestDatabase('retrieve table by name and schema', async ({ executeQuery }) = ) }) -withTestDatabase('retrieve error if missing identifiers', async ({}) => { +withTestDatabase('retrieve error if missing identifiers', async () => { await expect(async () => { //@ts-expect-error use with missing params await pgMeta.tables.retrieve({ name: 'memes' }) @@ -985,7 +985,7 @@ withTestDatabase('remove throws error for non-existent table', async ({ executeQ ) }) -withTestDatabase('remove throws error with missing identifiers', async ({}) => { +withTestDatabase('remove throws error with missing identifiers', async () => { await expect(async () => { //@ts-expect-error use with missing params await pgMeta.tables.remove({ name: 'some_table' })