Skip to content

Commit

Permalink
update postgres adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
pilcrowonpaper committed Dec 20, 2023
1 parent 2c31c72 commit 9d68600
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/adapter-postgresql/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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<T extends {}>(sql: string, args: any[]): Promise<T | null> {
const { rows } = await this.pool.query<T>(sql, args);
const { rows } = await this.client.query<T>(sql, args);
return rows.at(0) ?? null;
}

public async getAll<T extends {}>(sql: string, args: any[]): Promise<T[]> {
const { rows } = await this.pool.query<T>(sql, args);
const { rows } = await this.client.query<T>(sql, args);
return rows;
}

public async execute(sql: string, args: any[]): Promise<void> {
await this.pool.query(sql, args);
await this.client.query(sql, args);
}
}
4 changes: 2 additions & 2 deletions packages/adapter-postgresql/src/index.ts
Original file line number Diff line number Diff line change
@@ -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";
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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"
});
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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"
});
Expand Down

0 comments on commit 9d68600

Please sign in to comment.