From b10bb5edd1447471db6413a31195ef5c3e2c439d Mon Sep 17 00:00:00 2001 From: ingalls Date: Mon, 4 Mar 2024 12:23:00 -0700 Subject: [PATCH] Update CHANGELOG --- CHANGELOG.md | 4 ++ lib/pgtypes.ts | 164 ------------------------------------------------- lib/pool.ts | 67 -------------------- package.json | 1 - 4 files changed, 4 insertions(+), 232 deletions(-) delete mode 100644 lib/pgtypes.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index c2e4388..59456f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ ## Version History +### v16.0.0 + +- :tada: Remove JSON Schema output now that we use drizzle-typebox + ### v15.13.0 - :tada: Add Order Enum diff --git a/lib/pgtypes.ts b/lib/pgtypes.ts deleted file mode 100644 index 1040fbd..0000000 --- a/lib/pgtypes.ts +++ /dev/null @@ -1,164 +0,0 @@ -/** - * @class - */ -export default class PGTypes extends Map { - constructor() { - super(); - - const types = [{ - pgtypes: [ - 'geometry' - ], - schema: { - type: 'object' - } - },{ - pgtypes: [ - 'bit', - 'bit varying', - 'varbit', - 'character', - 'character varying', - 'text' - ], - schema: { - type: 'string' - } - },{ - pgtypes: [ - 'uuid' - ], - schema: { - type: 'string', - format: 'uuid' - } - }, { - pgtypes: [ - 'date' - ], - schema: { - type: 'string', - format: 'date' - } - }, { - pgtypes: [ - 'time with time zone', - 'time without time zone' - ], - schema: { - type: 'string', - format: 'time' - } - }, { - pgtypes: [ - 'timestamp with time zone', - 'timestamp without time zone', - 'timestamp' - ], - schema: { - type: 'string', - format: 'date-time' - } - }, { - pgtypes: [ - 'boolean' - ], - schema: { - type: 'boolean' - } - }, { - pgtypes: [ - 'bigint', - 'decimal', - 'double precision', - 'float8', - 'int', - 'integer', - 'numeric', - 'real', - 'smallint' - ], - schema: { - type: 'number' - } - }, { - pgtypes: [ - 'json', - 'jsonb' - ], - schema: { - type: 'object' - } - }, { - pgtypes: [ - 'interval' - ], - schema: { - type: 'number' - } - }]; - - for (const cls of types) { - for (const type of cls.pgtypes) { - this.set(type, cls.schema); - } - } - } - - /** - * Process a table/view an output high level JSON Schema properties representing it - * - * @param {Object} parsed PGStructure Container Object (Table/View) - * - * @returns {Object} - */ - container(parsed) { - const res = { - type: 'object', - _primaryKey: null, - additionalProperties: false, - properties: {} - }; - - if (parsed.constraints) { - for (const constr of parsed.constraints) { - if (constr.index && constr.index.isPrimaryKey) { - res._primaryKey = constr.index.columnsAndExpressions[0].name; - } - } - } - - return res; - } - - /** - * Process a single column of a table/view and output a JSON Schema representing it - * - * @param {Object} col PGStructure Object for the column - * - * @returns {Object} JSON Schema - */ - column(col) { - const parsed = this.get(col.type.name); - if (!parsed) return {}; - let schema = JSON.parse(JSON.stringify(parsed)); - - if (!col.notNull) schema.type = [schema.type, 'null']; - if (col.length) schema.maxLength = col.length; - - schema.description = col.comment || ''; - - if (col.arrayDimension > 0) { - schema = { - type: 'array', - items: schema - }; - - schema.$comment = `${col.type.internalName || col.type.shortName}[]`; - } else { - schema.$comment = col.type.internalName || col.type.shortName; - } - - return schema; - } -} diff --git a/lib/pool.ts b/lib/pool.ts index 4a0f4f1..765035e 100644 --- a/lib/pool.ts +++ b/lib/pool.ts @@ -1,6 +1,3 @@ -import { pgStructure } from 'pg-structure/dist/main.js'; -import PGTypes from './pgtypes.js'; -import Schemas from './schema.js'; import postgres from 'postgres'; import { sql } from 'drizzle-orm'; import { PgDatabase, PgDialect } from 'drizzle-orm/pg-core'; @@ -13,15 +10,6 @@ import { export type PostgresJsDatabase = Record> = PgDatabase; -export type DbStructure = { - tables: { - [k: string]: object; - }; - views: { - [k: string]: object; - }; -} - /** * @class * @param connstr Postgres Connection String @@ -30,7 +18,6 @@ export type DbStructure = { export default class Pool = Record> extends PgDatabase { connstr: string; schema: TSchema; - pgschema?: DbStructure; constructor(connstr: string, config: { schema: TSchema @@ -75,15 +62,10 @@ export default class Pool = Record = Record>(connstr: string, schema: TSchema, opts: { retry?: number; migrationsFolder?: string; - jsonschema?: { - dir: string | URL; - }; ssl?: { rejectUnauthorized?: boolean; }; @@ -119,57 +101,8 @@ export default class Pool = Record