Rewrite the data access layer onto Prisma Client
This commit is contained in:
+10
-10
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect, afterAll } from 'vitest';
|
||||
import { getPool, closePool, buildDatabaseUrl } from '../src/db.js';
|
||||
import { getPrismaClient, closePrismaClient, buildDatabaseUrl } from '../src/db.js';
|
||||
import { loadConfig } from '../src/config.js';
|
||||
|
||||
describe('buildDatabaseUrl', () => {
|
||||
@@ -20,25 +20,25 @@ describe('buildDatabaseUrl', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('getPool', () => {
|
||||
describe('getPrismaClient', () => {
|
||||
afterAll(async () => {
|
||||
await closePool();
|
||||
await closePrismaClient();
|
||||
});
|
||||
|
||||
it('returns a working pool that can run a query', async () => {
|
||||
it('returns a working client that can run a query', async () => {
|
||||
const config = loadConfig();
|
||||
const pool = getPool(config);
|
||||
const prisma = getPrismaClient(config);
|
||||
|
||||
const rows = await pool.query('SELECT 1 AS value');
|
||||
const rows = await prisma.$queryRaw`SELECT 1 AS value`;
|
||||
|
||||
expect(Number(rows[0].value)).toBe(1);
|
||||
});
|
||||
|
||||
it('returns the same pool instance on repeated calls', () => {
|
||||
it('returns the same client instance on repeated calls', () => {
|
||||
const config = loadConfig();
|
||||
const poolA = getPool(config);
|
||||
const poolB = getPool(config);
|
||||
const clientA = getPrismaClient(config);
|
||||
const clientB = getPrismaClient(config);
|
||||
|
||||
expect(poolA).toBe(poolB);
|
||||
expect(clientA).toBe(clientB);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user