diff --git a/packages/adapter-postgresql/package.json b/packages/adapter-postgresql/package.json index 76f216d04..4ccb58ccc 100644 --- a/packages/adapter-postgresql/package.json +++ b/packages/adapter-postgresql/package.json @@ -1,6 +1,6 @@ { "name": "@lucia-auth/adapter-postgresql", - "version": "3.0.0-beta.6", + "version": "3.0.0-beta.7", "description": "PostgreSQL adapter for Lucia", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/packages/adapter-postgresql/src/drivers/pg.ts b/packages/adapter-postgresql/src/drivers/node-postgres.ts similarity index 55% rename from packages/adapter-postgresql/src/drivers/pg.ts rename to packages/adapter-postgresql/src/drivers/node-postgres.ts index 672e49592..f1b8de626 100644 --- a/packages/adapter-postgresql/src/drivers/pg.ts +++ b/packages/adapter-postgresql/src/drivers/node-postgres.ts @@ -1,31 +1,31 @@ import { PostgreSQLAdapter } from "../base.js"; import type { Controller, TableNames } from "../base.js"; -import type { Pool } from "pg"; +import type { Pool, Client } from "pg"; export class NodePostgresAdapter extends PostgreSQLAdapter { - constructor(pool: Pool, tableNames: TableNames) { - super(new NodePostgresController(pool), tableNames); + constructor(client: Client | Pool, tableNames: TableNames) { + super(new NodePostgresController(client), tableNames); } } class NodePostgresController implements Controller { - private pool: Pool; - constructor(pool: Pool) { - this.pool = pool; + private client: Client | Pool; + constructor(client: Client | Pool) { + this.client = client; } public async get(sql: string, args: any[]): Promise { - const { rows } = await this.pool.query(sql, args); + const { rows } = await this.client.query(sql, args); return rows.at(0) ?? null; } public async getAll(sql: string, args: any[]): Promise { - const { rows } = await this.pool.query(sql, args); + const { rows } = await this.client.query(sql, args); return rows; } public async execute(sql: string, args: any[]): Promise { - await this.pool.query(sql, args); + await this.client.query(sql, args); } } diff --git a/packages/adapter-postgresql/src/drivers/postgres.ts b/packages/adapter-postgresql/src/drivers/postgresjs.ts similarity index 100% rename from packages/adapter-postgresql/src/drivers/postgres.ts rename to packages/adapter-postgresql/src/drivers/postgresjs.ts diff --git a/packages/adapter-postgresql/src/index.ts b/packages/adapter-postgresql/src/index.ts index 8bf9bb14b..b25031db8 100644 --- a/packages/adapter-postgresql/src/index.ts +++ b/packages/adapter-postgresql/src/index.ts @@ -1,2 +1,2 @@ -export { NodePostgresAdapter } from "./drivers/pg.js"; -export { PostgresJsAdapter } from "./drivers/postgres.js"; +export { NodePostgresAdapter } from "./drivers/node-postgres.js"; +export { PostgresJsAdapter } from "./drivers/postgresjs.js"; diff --git a/packages/adapter-postgresql/tests/pg.ts b/packages/adapter-postgresql/tests/node-postgres.ts similarity index 90% rename from packages/adapter-postgresql/tests/pg.ts rename to packages/adapter-postgresql/tests/node-postgres.ts index 3130b7e5e..17c6f9914 100644 --- a/packages/adapter-postgresql/tests/pg.ts +++ b/packages/adapter-postgresql/tests/node-postgres.ts @@ -1,5 +1,5 @@ import { testAdapter, databaseUser } from "@lucia-auth/adapter-test"; -import { PgAdapter } from "../src/drivers/pg.js"; +import { NodePostgresAdapter } from "../src/drivers/node-postgres.js"; import dotenv from "dotenv"; import { resolve } from "path"; import pg from "pg"; @@ -34,7 +34,7 @@ await pool.query(`INSERT INTO public.user (id, username) VALUES ($1, $2)`, [ databaseUser.attributes.username ]); -const adapter = new PgAdapter(pool, { +const adapter = new NodePostgresAdapter(pool, { user: "public.user", session: "public.session" }); diff --git a/packages/adapter-postgresql/tests/postgres.ts b/packages/adapter-postgresql/tests/postgresjs.ts similarity index 90% rename from packages/adapter-postgresql/tests/postgres.ts rename to packages/adapter-postgresql/tests/postgresjs.ts index 5064e29d0..0b5e17d62 100644 --- a/packages/adapter-postgresql/tests/postgres.ts +++ b/packages/adapter-postgresql/tests/postgresjs.ts @@ -1,5 +1,5 @@ import { testAdapter, databaseUser } from "@lucia-auth/adapter-test"; -import { PostgresAdapter } from "../src/drivers/postgres.js"; +import { PostgresJsAdapter } from "../src/drivers/postgresjs.js"; import dotenv from "dotenv"; import { resolve } from "path"; import postgres from "postgres"; @@ -27,7 +27,7 @@ await sql`CREATE TABLE public.session ( await sql`INSERT INTO public.user (id, username) VALUES (${databaseUser.id}, ${databaseUser.attributes.username})`; -const adapter = new PostgresAdapter(sql, { +const adapter = new PostgresJsAdapter(sql, { user: "public.user", session: "public.session" });