mirror of
https://github.com/documenso/documenso.git
synced 2025-11-12 15:53:02 +10:00
feat: add kysely for raw type-safe SQL queries
This commit is contained in:
@ -1,5 +1,8 @@
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import { Kysely, PostgresAdapter, PostgresIntrospector, PostgresQueryCompiler } from 'kysely';
|
||||
import kyselyExtension from 'prisma-extension-kysely';
|
||||
|
||||
import type { DB } from './generated/types.js';
|
||||
import { getDatabaseUrl } from './helper';
|
||||
|
||||
declare global {
|
||||
@ -12,10 +15,24 @@ if (!globalThis.prisma) {
|
||||
globalThis.prisma = new PrismaClient({ datasourceUrl: getDatabaseUrl() });
|
||||
}
|
||||
|
||||
export const prisma =
|
||||
const _prisma =
|
||||
globalThis.prisma ||
|
||||
new PrismaClient({
|
||||
datasourceUrl: getDatabaseUrl(),
|
||||
});
|
||||
|
||||
export const prisma = _prisma.$extends(
|
||||
kyselyExtension({
|
||||
kysely: (driver) =>
|
||||
new Kysely<DB>({
|
||||
dialect: {
|
||||
createAdapter: () => new PostgresAdapter(),
|
||||
createDriver: () => driver,
|
||||
createIntrospector: (db) => new PostgresIntrospector(db),
|
||||
createQueryCompiler: () => new PostgresQueryCompiler(),
|
||||
},
|
||||
}),
|
||||
}),
|
||||
);
|
||||
|
||||
export const getPrismaClient = () => prisma;
|
||||
|
||||
Reference in New Issue
Block a user