From 6a0caf8be5f843cb63ae3911e041850bd90e2f64 Mon Sep 17 00:00:00 2001 From: ingalls Date: Fri, 30 Aug 2024 08:34:34 -0600 Subject: [PATCH 1/5] Stricter TS Config --- tsconfig.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tsconfig.json b/tsconfig.json index 0a28b28..109654d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,11 +4,11 @@ }, "compilerOptions": { "strict": true, + "strictNullChecks": true, + "esModuleInterop": true, "skipLibCheck": true, "module": "es2022", "target": "es2022", - "esModuleInterop": true, - "noImplicitAny": false, "moduleResolution": "node", "sourceMap": true, "outDir": "dist", @@ -19,6 +19,7 @@ ] } }, + "exclude": [], "include": [ "generic.ts", "lib/*.ts" From 4a9f9fb573bfb9f4db0e7c976e44806ba27a0fda Mon Sep 17 00:00:00 2001 From: ingalls Date: Fri, 30 Aug 2024 08:35:55 -0600 Subject: [PATCH 2/5] Fix pool boolean check --- lib/pool.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/pool.ts b/lib/pool.ts index ba4f318..0652e46 100644 --- a/lib/pool.ts +++ b/lib/pool.ts @@ -72,7 +72,7 @@ export default class Pool = Record> { if (!opts.retry) opts.retry = 5; - let pool; + let pool: Pool | undefined = undefined; let retry = opts.retry; do { try { @@ -83,7 +83,7 @@ export default class Pool = Record = Record Date: Fri, 30 Aug 2024 08:38:52 -0600 Subject: [PATCH 3/5] Fix now select --- lib/pool.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/pool.ts b/lib/pool.ts index 0652e46..2126813 100644 --- a/lib/pool.ts +++ b/lib/pool.ts @@ -80,7 +80,10 @@ export default class Pool = Record Date: Fri, 30 Aug 2024 08:46:08 -0600 Subject: [PATCH 4/5] Use config to set schema --- lib/pool.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/pool.ts b/lib/pool.ts index 2126813..165a680 100644 --- a/lib/pool.ts +++ b/lib/pool.ts @@ -2,13 +2,16 @@ import postgres from 'postgres'; import { sql } from 'drizzle-orm'; import { PgDatabase, PgDialect } from 'drizzle-orm/pg-core'; import { migrate } from 'drizzle-orm/postgres-js/migrator' -import { PostgresJsSession, PostgresJsQueryResultHKT } from 'drizzle-orm/postgres-js'; +import { PostgresJsSession } from 'drizzle-orm/postgres-js' +import type {PostgresJsQueryResultHKT } from 'drizzle-orm/postgres-js'; import { - createTableRelationsHelpers, - extractTablesRelationalConfig + createTableRelationsHelpers, + extractTablesRelationalConfig +} from "drizzle-orm/relations"; +import type { + RelationalSchemaConfig, + TablesRelationalConfig } from "drizzle-orm/relations"; - -export type PostgresJsDatabase = Record> = PgDatabase; /** * @class @@ -29,7 +32,7 @@ export default class Pool = Record | undefined; if (config.schema) { const tablesConfig = extractTablesRelationalConfig( config.schema, @@ -47,7 +50,7 @@ export default class Pool = Record Date: Fri, 30 Aug 2024 09:05:21 -0600 Subject: [PATCH 5/5] Add from test --- lib/pool.ts | 9 +++++++-- package-lock.json | 22 ++++++++++++++++++++++ package.json | 1 + test/generic.test.ts | 17 ++++++++++++++++- 4 files changed, 46 insertions(+), 3 deletions(-) diff --git a/lib/pool.ts b/lib/pool.ts index 165a680..7b350d2 100644 --- a/lib/pool.ts +++ b/lib/pool.ts @@ -3,12 +3,13 @@ import { sql } from 'drizzle-orm'; import { PgDatabase, PgDialect } from 'drizzle-orm/pg-core'; import { migrate } from 'drizzle-orm/postgres-js/migrator' import { PostgresJsSession } from 'drizzle-orm/postgres-js' -import type {PostgresJsQueryResultHKT } from 'drizzle-orm/postgres-js'; +import type { PostgresJsQueryResultHKT } from 'drizzle-orm/postgres-js'; import { createTableRelationsHelpers, extractTablesRelationalConfig } from "drizzle-orm/relations"; import type { + ExtractTablesWithRelations, RelationalSchemaConfig, TablesRelationalConfig } from "drizzle-orm/relations"; @@ -47,7 +48,11 @@ export default class Pool = Record> + ); this.connstr = connstr; this.schema = config.schema; diff --git a/package-lock.json b/package-lock.json index e57b2d3..cc39f01 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,6 +18,7 @@ "devDependencies": { "@types/express": "^4.17.21", "@types/geojson": "^7946.0.13", + "@types/tape": "^5.6.4", "eslint": "^9.0.0", "tape": "^5.4.0", "typedoc": "^0.26.0", @@ -1229,6 +1230,27 @@ "@types/send": "*" } }, + "node_modules/@types/tape": { + "version": "5.6.4", + "resolved": "https://registry.npmjs.org/@types/tape/-/tape-5.6.4.tgz", + "integrity": "sha512-EmL4fJpZyByNCkupLLcJhneqcnT+rQUG5fWKNCsZyBK1x7nUuDTwwEerc4biEMZgvSK2+FXr775aLeXhKXK4Yw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/node": "*", + "@types/through": "*" + } + }, + "node_modules/@types/through": { + "version": "0.0.33", + "resolved": "https://registry.npmjs.org/@types/through/-/through-0.0.33.tgz", + "integrity": "sha512-HsJ+z3QuETzP3cswwtzt2vEIiHBk/dCcHGhbmG5X3ecnwFD/lPrMpliGXxSCg03L9AhrdwA4Oz/qfspkDW+xGQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/unist": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/@types/unist/-/unist-3.0.3.tgz", diff --git a/package.json b/package.json index 032feef..b78b9ab 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "devDependencies": { "@types/express": "^4.17.21", "@types/geojson": "^7946.0.13", + "@types/tape": "^5.6.4", "eslint": "^9.0.0", "tape": "^5.4.0", "typedoc": "^0.26.0", diff --git a/test/generic.test.ts b/test/generic.test.ts index 1cfbba9..3acada4 100644 --- a/test/generic.test.ts +++ b/test/generic.test.ts @@ -5,7 +5,7 @@ import * as pgschema from './schema.base.js'; const connstr = init(); -test('Generic Generate', async () => { +test('Generic Generate', async (t) => { const pool = await Pool.connect(connstr, pgschema); const ProfileModel = new Modeler(pool, pgschema.Profile); @@ -15,6 +15,7 @@ test('Generic Generate', async () => { }); pool.end(); + t.end(); }); test('Generic From - 404', async (t) => { @@ -34,4 +35,18 @@ test('Generic From - 404', async (t) => { } pool.end(); + t.end(); +}); + +test('Generic From', async (t) => { + const pool = await Pool.connect(connstr, pgschema); + + const ProfileModel = new Modeler(pool, pgschema.Profile); + + const user = await ProfileModel.from('test-user'); + + t.equals(user.username, 'test-user') + + pool.end(); + t.end(); });