Skip to content

Commit

Permalink
Update CHANGELOG
Browse files Browse the repository at this point in the history
  • Loading branch information
ingalls committed Mar 4, 2024
1 parent b0e7324 commit b10bb5e
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 232 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
164 changes: 0 additions & 164 deletions lib/pgtypes.ts

This file was deleted.

67 changes: 0 additions & 67 deletions lib/pool.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -13,15 +10,6 @@ import {

export type PostgresJsDatabase<TSchema extends Record<string, unknown> = Record<string, never>> = PgDatabase<PostgresJsQueryResultHKT, TSchema>;

export type DbStructure = {
tables: {
[k: string]: object;
};
views: {
[k: string]: object;
};
}

/**
* @class
* @param connstr Postgres Connection String
Expand All @@ -30,7 +18,6 @@ export type DbStructure = {
export default class Pool<TSchema extends Record<string, unknown> = Record<string, never>> extends PgDatabase<PostgresJsQueryResultHKT, TSchema> {
connstr: string;
schema: TSchema;
pgschema?: DbStructure;

constructor(connstr: string, config: {
schema: TSchema
Expand Down Expand Up @@ -75,15 +62,10 @@ export default class Pool<TSchema extends Record<string, unknown> = Record<strin
* @param [opts] Options Object
* @param [opts.retry=5] Number of times to retry an initial connection
* @param [opts.schema]
* @param [opts.jsonschema] JSON Schema Options
* @param [opts.jsonschema.dir] JSON Schema Directory
*/
static async connect<TSchema extends Record<string, unknown> = Record<string, never>>(connstr: string, schema: TSchema, opts: {
retry?: number;
migrationsFolder?: string;
jsonschema?: {
dir: string | URL;
};
ssl?: {
rejectUnauthorized?: boolean;
};
Expand Down Expand Up @@ -119,57 +101,8 @@ export default class Pool<TSchema extends Record<string, unknown> = Record<strin
await migrate(pool, { migrationsFolder: opts.migrationsFolder });
}

if (opts.jsonschema && opts.jsonschema.dir) await pool.genJSONSchemas({
ssl: opts.ssl,
dir: opts.jsonschema.dir
});

return pool;
}

/**
* Parse the current database state into JSON Schemas per table
* Called automatically at the start of a postgres connection
*
* @param {Object} opts See Pool.connect() documentation on `opts.schemas`
*/
async genJSONSchemas(opts: {
dir: string | URL;
ssl?: {
rejectUnauthorized?: boolean;
};
}) {
const res = {
tables: {},
views: {}
};

const url = new URL(this.connstr);
if (opts.ssl && opts.ssl.rejectUnauthorized == false) {
url.searchParams.set('sslmode', 'no-verify')
}


const db = await pgStructure(String(url));
const types = new PGTypes();

for (const type of ['views', 'tables']) {
for (const parsed of db.get('public')[type]) {
res[type][parsed.name] = types.container(parsed);
for (const col of parsed.columns) {
res[type][parsed.name].properties[col.name] = types.column(col);
}

res[type][parsed.name].required = Object.keys(res[type][parsed.name].properties);
}
}

this.pgschema = res;

if (opts.dir) await Schemas.write(res, opts.dir);

return res;
}
}

function sleep(ms) {
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"@openaddresses/batch-error": "^2.1.2",
"@turf/bbox": "^6.5.0",
"mkdirp": "^3.0.0",
"pg-structure": "^7.15.0",
"postgres": "^3.4.3",
"wkx": "^0.5.0"
}
Expand Down

0 comments on commit b10bb5e

Please sign in to comment.