Kysely dialect for PostgreSQL using the deno-postgres client.
Attributes
Includes Deno configuration
Repository
Current version released
10 months ago
kysely-deno-postgres-dialect
Kysely dialect for PostgreSQL using the deno-postgres client.
🚀 Getting started
import {
KyselyDenoPostgresDialect,
setup,
} from "https://deno.land/x/kysely_deno_postgres_dialect/mod.ts";
setup(() => {
const dialect = new KyselyDenoPostgresDialect({
pool: new Pool(
{
database: "postgres",
hostname: "localhost",
password: "postgres",
port: 5432,
user: "postgres",
},
10,
true,
),
});
return new Kysely<Database>({
dialect,
});
});
// run queries
🩺 Testing
See detail at ./tests/testing/utils_test.ts
.
Important
To fix leaking resources
error, you should end all connections between
cases.
import {
KyselyDenoPostgresDialect,
PostgresConnection,
setup,
wrapTransaction,
} from "https://deno.land/x/kysely_deno_postgres_dialect/mod.ts";
import { setupTesting } from "https://deno.land/x/kysely_deno_postgres_dialect/testing.ts";
const connections: PostgresConnection[] = [];
setup(() => {
const dialect = new KyselyDenoPostgresDialect({
pool: new Pool(
{
database: "postgres",
hostname: "localhost",
password: "postgres",
port: 5432,
user: "postgres",
},
10,
true,
),
onCreateConnection: (connection: DatabaseConnection) => {
connections.push(connection as PostgresConnection);
},
});
return new Kysely<Database>({
dialect,
});
});
async function endConnections() {
for (const connection of connections) {
await connection.end();
}
}
// test files
const {
beforeAllFn,
beforeEachFn,
afterEachFn,
afterAllFn,
} = setupTesting(stub);
describe("tests", () => {
beforeAll(async () => {
await beforeAllFn();
});
afterAll(async () => {
await afterAllFn();
});
beforeEach(async () => {
await beforeEachFn();
});
afterEach(async () => {
// note: fix Leaking resources error
await endConnections();
await afterEachFn();
});
it("works", async () => {
// snip
});
});