feat: add kysely for raw type-safe SQL queries
This commit is contained in:
1508
package-lock.json
generated
1508
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,8 @@
|
|||||||
import { PrismaClient } from '@prisma/client';
|
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';
|
import { getDatabaseUrl } from './helper';
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
@@ -12,10 +15,24 @@ if (!globalThis.prisma) {
|
|||||||
globalThis.prisma = new PrismaClient({ datasourceUrl: getDatabaseUrl() });
|
globalThis.prisma = new PrismaClient({ datasourceUrl: getDatabaseUrl() });
|
||||||
}
|
}
|
||||||
|
|
||||||
export const prisma =
|
const _prisma =
|
||||||
globalThis.prisma ||
|
globalThis.prisma ||
|
||||||
new PrismaClient({
|
new PrismaClient({
|
||||||
datasourceUrl: getDatabaseUrl(),
|
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;
|
export const getPrismaClient = () => prisma;
|
||||||
|
|||||||
@@ -20,12 +20,15 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@prisma/client": "5.4.2",
|
"@prisma/client": "5.4.2",
|
||||||
|
"kysely": "^0.27.3",
|
||||||
"prisma": "5.4.2",
|
"prisma": "5.4.2",
|
||||||
|
"prisma-extension-kysely": "^2.1.0",
|
||||||
"ts-pattern": "^5.0.6"
|
"ts-pattern": "^5.0.6"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"dotenv": "^16.3.1",
|
"dotenv": "^16.3.1",
|
||||||
"dotenv-cli": "^7.3.0",
|
"dotenv-cli": "^7.3.0",
|
||||||
|
"prisma-kysely": "^1.8.0",
|
||||||
"ts-node": "^10.9.1",
|
"ts-node": "^10.9.1",
|
||||||
"typescript": "5.2.2"
|
"typescript": "5.2.2"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
generator client {
|
generator kysely {
|
||||||
provider = "prisma-client-js"
|
provider = "prisma-kysely"
|
||||||
}
|
}
|
||||||
|
|
||||||
datasource db {
|
datasource db {
|
||||||
|
|||||||
Reference in New Issue
Block a user