Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: gajus/slonik
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v30.1.1
Choose a base ref
...
head repository: gajus/slonik
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v30.1.2
Choose a head ref
  • 1 commit
  • 3 files changed
  • 1 contributor

Commits on Aug 6, 2022

  1. Copy the full SHA
    c880503 View commit details
Showing with 15 additions and 88 deletions.
  1. +12 −6 src/factories/createPool.ts
  2. +3 −7 src/routines/createTypeOverrides.ts
  3. +0 −75 test/slonik/routines/createTypeOverrides.ts
18 changes: 12 additions & 6 deletions src/factories/createPool.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
Client as PgClient,
Pool as PgPool,
} from 'pg';
import {
@@ -57,18 +58,23 @@ export const createPool = async (
throw new Error('Unexpected state.');
}

// This pool is only used to initialize the client.
const setupPool: PgPool = new Pool({
...poolConfiguration,
max: 1,
const setupClient = new PgClient({
database: poolConfiguration.database,
host: poolConfiguration.host,
password: poolConfiguration.password,
port: poolConfiguration.port,
ssl: poolConfiguration.ssl,
user: poolConfiguration.user,
});

await setupClient.connect();

const getTypeParser = await createTypeOverrides(
setupPool,
setupClient,
clientConfiguration.typeParsers,
);

await setupPool.end();
await setupClient.end();

const pool: PgPool = new Pool({
...poolConfiguration,
10 changes: 3 additions & 7 deletions src/routines/createTypeOverrides.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
type Pool as PgPool,
type Client as PgClient,
} from 'pg';
import {
getTypeParser,
@@ -18,23 +18,19 @@ type PostgresType = {
};

export const createTypeOverrides = async (
pool: PgPool,
pool: PgClient,
typeParsers: readonly TypeParser[],
) => {
const typeNames = typeParsers.map((typeParser) => {
return typeParser.name;
});

const connection = await pool.connect();

const postgresTypes: PostgresType[] = (
await connection.query('SELECT oid, typarray, typname FROM pg_type WHERE typname = ANY($1::text[])', [
await pool.query('SELECT oid, typarray, typname FROM pg_type WHERE typname = ANY($1::text[])', [
typeNames,
])
).rows;

connection.release(true);

const parsers = {};

for (const typeParser of typeParsers) {
75 changes: 0 additions & 75 deletions test/slonik/routines/createTypeOverrides.ts

This file was deleted.