Files
sign/packages/prisma/index.ts

35 lines
997 B
TypeScript
Raw Normal View History

2025-01-15 13:46:45 +11:00
/// <reference types="@documenso/prisma/types/types.d.ts" />
2023-06-09 18:21:18 +10:00
import { PrismaClient } from '@prisma/client';
import { Kysely, PostgresAdapter, PostgresIntrospector, PostgresQueryCompiler } from 'kysely';
import kyselyExtension from 'prisma-extension-kysely';
2023-01-07 15:10:26 +01:00
2024-05-29 14:47:33 +10:00
import type { DB } from './generated/types';
2023-09-14 15:00:14 +10:00
import { getDatabaseUrl } from './helper';
2024-05-29 22:25:23 +10:00
import { remember } from './utils/remember';
2023-09-14 15:00:14 +10:00
2024-05-29 14:47:33 +10:00
export const prisma = remember(
'prisma',
() =>
new PrismaClient({
datasourceUrl: getDatabaseUrl(),
}),
);
2024-05-29 14:47:33 +10:00
export const kyselyPrisma = remember('kyselyPrisma', () =>
prisma.$extends(
kyselyExtension({
kysely: (driver) =>
new Kysely<DB>({
dialect: {
createAdapter: () => new PostgresAdapter(),
createDriver: () => driver,
createIntrospector: (db) => new PostgresIntrospector(db),
createQueryCompiler: () => new PostgresQueryCompiler(),
},
}),
}),
),
);
2024-05-29 20:03:51 +10:00
export { sql } from 'kysely';