Skip to content

Commit

Permalink
Fix node-postgres ESM imports
Browse files Browse the repository at this point in the history
  • Loading branch information
dankochetov committed Aug 23, 2023
1 parent 603bbc2 commit 0f1c5b4
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 17 deletions.
4 changes: 3 additions & 1 deletion drizzle-orm/type-tests/kysely/index.ts
Original file line number Diff line number Diff line change
@@ -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(),
Expand Down
4 changes: 3 additions & 1 deletion drizzle-orm/type-tests/pg/db.ts
Original file line number Diff line number Diff line change
@@ -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());
6 changes: 4 additions & 2 deletions integration-tests/tests/neon-http.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down Expand Up @@ -118,7 +120,7 @@ interface Context {
docker: Docker;
pgContainer: Docker.Container;
db: NeonHttpDatabase;
ddlRunner: Client;
ddlRunner: pg.Client;
client: NeonQueryFunction<false, true>;
}

Expand Down
6 changes: 4 additions & 2 deletions integration-tests/tests/pg-schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down Expand Up @@ -59,7 +61,7 @@ interface Context {
docker: Docker;
pgContainer: Docker.Container;
db: NodePgDatabase;
client: Client;
client: pg.Client;
}

const test = anyTest as TestFn<Context>;
Expand Down
6 changes: 4 additions & 2 deletions integration-tests/tests/pg.custom.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -70,7 +72,7 @@ interface Context {
docker: Docker;
pgContainer: Docker.Container;
db: NodePgDatabase;
client: Client;
client: pg.Client;
}

const test = anyTest as TestFn<Context>;
Expand Down
6 changes: 4 additions & 2 deletions integration-tests/tests/pg.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down Expand Up @@ -120,7 +122,7 @@ interface Context {
docker: Docker;
pgContainer: Docker.Container;
db: NodePgDatabase;
client: Client;
client: pg.Client;
}

const test = anyTest as TestFn<Context>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/*
Expand All @@ -17,7 +19,7 @@ const ENABLE_LOGGING = false;

let pgContainer: Docker.Container;
let db: NodePgDatabase<typeof schema>;
let client: Client;
let client: pg.Client;

async function createDockerDB(): Promise<string> {
const docker = new Docker();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/*
Expand All @@ -17,7 +19,7 @@ const ENABLE_LOGGING = false;

let pgContainer: Docker.Container;
let db: NodePgDatabase<typeof schema>;
let client: Client;
let client: pg.Client;

async function createDockerDB(): Promise<string> {
const docker = new Docker();
Expand Down
8 changes: 5 additions & 3 deletions integration-tests/tests/relational/pg.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,14 +24,14 @@ declare module 'vitest' {
docker: Docker;
pgContainer: Docker.Container;
pgDb: NodePgDatabase<typeof schema>;
pgClient: Client;
pgClient: pg.Client;
}
}

let globalDocker: Docker;
let pgContainer: Docker.Container;
let db: NodePgDatabase<typeof schema>;
let client: Client;
let client: pg.Client;

async function createDockerDB(): Promise<string> {
const docker = (globalDocker = new Docker());
Expand Down

0 comments on commit 0f1c5b4

Please sign in to comment.