Skip to content

Commit 1f0ac3e

Browse files
committed
thread through pool
1 parent 1245e09 commit 1f0ac3e

1 file changed

Lines changed: 5 additions & 29 deletions

File tree

drizzle-kit/src/api.ts

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -84,24 +84,15 @@ export const introspectPgDB = async (
8484
};
8585

8686
export const preparePgDB = async (
87-
credentials: DrizzlePostgresCredentials,
87+
pool: import('pg').Pool | import('pg').PoolClient,
8888
): Promise<
8989
DrizzlePgDB
9090
> => {
91-
console.log(`Using 'pg' driver for database querying`);
9291
const { default: pg } = await import('pg');
92+
9393
const { drizzle } = await import('drizzle-orm/node-postgres');
9494
const { migrate } = await import('drizzle-orm/node-postgres/migrator');
9595

96-
const ssl = 'ssl' in credentials
97-
? credentials.ssl === 'prefer'
98-
|| credentials.ssl === 'require'
99-
|| credentials.ssl === 'allow'
100-
? { rejectUnauthorized: false }
101-
: credentials.ssl === 'verify-full'
102-
? {}
103-
: credentials.ssl
104-
: {};
10596

10697
// Override pg default date parsers
10798
const types: { getTypeParser: typeof pg.types.getTypeParser } = {
@@ -124,17 +115,13 @@ export const preparePgDB = async (
124115
},
125116
};
126117

127-
const client = 'url' in credentials
128-
? new pg.Pool({ connectionString: credentials.url, max: 1 })
129-
: new pg.Pool({ ...credentials, ssl, max: 1 });
130-
131-
const db = drizzle(client);
118+
const db = drizzle(pool);
132119
const migrateFn = async (config: MigrationConfig) => {
133120
return migrate(db, config);
134121
};
135122

136123
const query = async (sql: string, params?: any[]) => {
137-
const result = await client.query({
124+
const result = await pool.query({
138125
text: sql,
139126
values: params ?? [],
140127
types,
@@ -143,7 +130,7 @@ export const preparePgDB = async (
143130
};
144131

145132
const proxy: Proxy = async (params: ProxyParams) => {
146-
const result = await client.query({
133+
const result = await pool.query({
147134
text: params.sql,
148135
values: params.params,
149136
...(params.mode === 'array' && { rowMode: 'array' }),
@@ -155,17 +142,6 @@ export const preparePgDB = async (
155142
return { query, proxy, migrate: migrateFn };
156143
};
157144

158-
export const getPgClientPool = async (
159-
targetCredentials: DrizzlePostgresCredentials,
160-
) => {
161-
const { default: pg } = await import('pg');
162-
const pool = 'url' in targetCredentials
163-
? new pg.Pool({ connectionString: targetCredentials.url, max: 1 })
164-
: new pg.Pool({ ...targetCredentials, ssl: undefined, max: 1 });
165-
166-
return pool;
167-
};
168-
169145
export type { SelectResolverInput, SelectResolverOutput } from './cli/commands/pgPushUtils';
170146
export { applyPgSnapshotsDiff } from './snapshotsDiffer';
171147
export type {

0 commit comments

Comments
 (0)