From 0f1c5b4c6ea3c7084ea89a9dedc2870125836fce Mon Sep 17 00:00:00 2001 From: Dan Kochetov Date: Thu, 24 Aug 2023 01:40:51 +0300 Subject: [PATCH] Fix node-postgres ESM imports --- drizzle-orm/type-tests/kysely/index.ts | 4 +++- drizzle-orm/type-tests/pg/db.ts | 4 +++- integration-tests/tests/neon-http.test.ts | 6 ++++-- integration-tests/tests/pg-schema.test.ts | 6 ++++-- integration-tests/tests/pg.custom.test.ts | 6 ++++-- integration-tests/tests/pg.test.ts | 6 ++++-- .../issues-schemas/duplicates/pg/pg.duplicates.test.ts | 6 ++++-- .../relational/issues-schemas/wrong-mapping/pg.test.ts | 6 ++++-- integration-tests/tests/relational/pg.test.ts | 8 +++++--- 9 files changed, 35 insertions(+), 17 deletions(-) diff --git a/drizzle-orm/type-tests/kysely/index.ts b/drizzle-orm/type-tests/kysely/index.ts index ecb49810f..c6a56f572 100644 --- a/drizzle-orm/type-tests/kysely/index.ts +++ b/drizzle-orm/type-tests/kysely/index.ts @@ -1,11 +1,13 @@ import { Kysely, PostgresDialect } from 'kysely'; -import { Pool } from 'pg'; +import pg from 'pg'; import { type Equal, Expect } from 'type-tests/utils.ts'; import type { Kyselify } from '~/kysely/index.ts'; import { char, mysqlTable, timestamp as mysqlTimestamp, varchar as mysqlVarchar } from '~/mysql-core/index.ts'; import { integer, pgEnum, pgTable, serial, text, timestamp, varchar } from '~/pg-core/index.ts'; import type { PromiseOf } from '~/utils.ts'; +const { Pool } = pg; + const test = pgTable('test', { id: serial('id').primaryKey(), name: text('name').notNull(), diff --git a/drizzle-orm/type-tests/pg/db.ts b/drizzle-orm/type-tests/pg/db.ts index c9a0dd05e..8cdd30116 100644 --- a/drizzle-orm/type-tests/pg/db.ts +++ b/drizzle-orm/type-tests/pg/db.ts @@ -1,4 +1,6 @@ -import { Client } from 'pg'; +import pg from 'pg'; import { drizzle } from '~/node-postgres/index.ts'; +const { Client } = pg; + export const db = drizzle(new Client()); diff --git a/integration-tests/tests/neon-http.test.ts b/integration-tests/tests/neon-http.test.ts index acaa5b0f7..c5a7eb70e 100644 --- a/integration-tests/tests/neon-http.test.ts +++ b/integration-tests/tests/neon-http.test.ts @@ -46,10 +46,12 @@ import { varchar, } from 'drizzle-orm/pg-core'; import getPort from 'get-port'; -import { Client } from 'pg'; +import pg from 'pg'; import { v4 as uuid } from 'uuid'; import { type Equal, Expect } from './utils.ts'; +const { Client } = pg; + const ENABLE_LOGGING = false; const usersTable = pgTable('users', { @@ -118,7 +120,7 @@ interface Context { docker: Docker; pgContainer: Docker.Container; db: NeonHttpDatabase; - ddlRunner: Client; + ddlRunner: pg.Client; client: NeonQueryFunction; } diff --git a/integration-tests/tests/pg-schema.test.ts b/integration-tests/tests/pg-schema.test.ts index 3e8dd27e3..f2c116805 100644 --- a/integration-tests/tests/pg-schema.test.ts +++ b/integration-tests/tests/pg-schema.test.ts @@ -22,9 +22,11 @@ import { timestamp, } from 'drizzle-orm/pg-core'; import getPort from 'get-port'; -import { Client } from 'pg'; +import pg from 'pg'; import { v4 as uuid } from 'uuid'; +const { Client } = pg; + const mySchema = pgSchema('mySchema'); const usersTable = mySchema.table('users', { @@ -59,7 +61,7 @@ interface Context { docker: Docker; pgContainer: Docker.Container; db: NodePgDatabase; - client: Client; + client: pg.Client; } const test = anyTest as TestFn; diff --git a/integration-tests/tests/pg.custom.test.ts b/integration-tests/tests/pg.custom.test.ts index 8e1751816..2010d92bf 100644 --- a/integration-tests/tests/pg.custom.test.ts +++ b/integration-tests/tests/pg.custom.test.ts @@ -9,9 +9,11 @@ import { drizzle } from 'drizzle-orm/node-postgres'; import { migrate } from 'drizzle-orm/node-postgres/migrator'; import { alias, customType, pgTable, pgTableCreator, serial, text } from 'drizzle-orm/pg-core'; import getPort from 'get-port'; -import { Client } from 'pg'; +import pg from 'pg'; import { v4 as uuid } from 'uuid'; +const { Client } = pg; + const customSerial = customType<{ data: number; notNull: true; default: true }>({ dataType() { return 'serial'; @@ -70,7 +72,7 @@ interface Context { docker: Docker; pgContainer: Docker.Container; db: NodePgDatabase; - client: Client; + client: pg.Client; } const test = anyTest as TestFn; diff --git a/integration-tests/tests/pg.test.ts b/integration-tests/tests/pg.test.ts index e26da3bfb..f9a50b563 100644 --- a/integration-tests/tests/pg.test.ts +++ b/integration-tests/tests/pg.test.ts @@ -48,10 +48,12 @@ import { varchar, } from 'drizzle-orm/pg-core'; import getPort from 'get-port'; -import { Client } from 'pg'; +import pg from 'pg'; import { v4 as uuid } from 'uuid'; import { type Equal, Expect } from './utils.ts'; +const { Client } = pg; + const ENABLE_LOGGING = false; const usersTable = pgTable('users', { @@ -120,7 +122,7 @@ interface Context { docker: Docker; pgContainer: Docker.Container; db: NodePgDatabase; - client: Client; + client: pg.Client; } const test = anyTest as TestFn; diff --git a/integration-tests/tests/relational/issues-schemas/duplicates/pg/pg.duplicates.test.ts b/integration-tests/tests/relational/issues-schemas/duplicates/pg/pg.duplicates.test.ts index a28e00c8d..17a057de7 100644 --- a/integration-tests/tests/relational/issues-schemas/duplicates/pg/pg.duplicates.test.ts +++ b/integration-tests/tests/relational/issues-schemas/duplicates/pg/pg.duplicates.test.ts @@ -3,11 +3,13 @@ import Docker from 'dockerode'; import { sql } from 'drizzle-orm'; import { drizzle, type NodePgDatabase } from 'drizzle-orm/node-postgres'; import getPort from 'get-port'; -import { Client } from 'pg'; +import pg from 'pg'; import { v4 as uuid } from 'uuid'; import { afterAll, beforeAll, beforeEach, expect, expectTypeOf, test } from 'vitest'; import * as schema from './pg.duplicates.ts'; +const { Client } = pg; + const ENABLE_LOGGING = false; /* @@ -17,7 +19,7 @@ const ENABLE_LOGGING = false; let pgContainer: Docker.Container; let db: NodePgDatabase; -let client: Client; +let client: pg.Client; async function createDockerDB(): Promise { const docker = new Docker(); diff --git a/integration-tests/tests/relational/issues-schemas/wrong-mapping/pg.test.ts b/integration-tests/tests/relational/issues-schemas/wrong-mapping/pg.test.ts index 35e2b388f..ea81c82fb 100644 --- a/integration-tests/tests/relational/issues-schemas/wrong-mapping/pg.test.ts +++ b/integration-tests/tests/relational/issues-schemas/wrong-mapping/pg.test.ts @@ -3,11 +3,13 @@ import Docker from 'dockerode'; import { desc, sql } from 'drizzle-orm'; import { drizzle, type NodePgDatabase } from 'drizzle-orm/node-postgres'; import getPort from 'get-port'; -import { Client } from 'pg'; +import pg from 'pg'; import { v4 as uuid } from 'uuid'; import { afterAll, beforeAll, beforeEach, expectTypeOf, test } from 'vitest'; import * as schema from './pg.schema.ts'; +const { Client } = pg; + const ENABLE_LOGGING = false; /* @@ -17,7 +19,7 @@ const ENABLE_LOGGING = false; let pgContainer: Docker.Container; let db: NodePgDatabase; -let client: Client; +let client: pg.Client; async function createDockerDB(): Promise { const docker = new Docker(); diff --git a/integration-tests/tests/relational/pg.test.ts b/integration-tests/tests/relational/pg.test.ts index ceca76036..02f7fcbec 100644 --- a/integration-tests/tests/relational/pg.test.ts +++ b/integration-tests/tests/relational/pg.test.ts @@ -3,11 +3,13 @@ import Docker from 'dockerode'; import { desc, DrizzleError, eq, gt, gte, or, placeholder, sql, TransactionRollbackError } from 'drizzle-orm'; import { drizzle, type NodePgDatabase } from 'drizzle-orm/node-postgres'; import getPort from 'get-port'; -import { Client } from 'pg'; +import pg from 'pg'; import { v4 as uuid } from 'uuid'; import { afterAll, beforeAll, beforeEach, expect, expectTypeOf, test } from 'vitest'; import * as schema from './pg.schema.ts'; +const { Client } = pg; + const { usersTable, postsTable, commentsTable, usersToGroupsTable, groupsTable } = schema; const ENABLE_LOGGING = false; @@ -22,14 +24,14 @@ declare module 'vitest' { docker: Docker; pgContainer: Docker.Container; pgDb: NodePgDatabase; - pgClient: Client; + pgClient: pg.Client; } } let globalDocker: Docker; let pgContainer: Docker.Container; let db: NodePgDatabase; -let client: Client; +let client: pg.Client; async function createDockerDB(): Promise { const docker = (globalDocker = new Docker());