-
Notifications
You must be signed in to change notification settings - Fork 0
/
myDbModule.ts
25 lines (22 loc) · 855 Bytes
/
myDbModule.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { PrismaClient } from "@prisma/client/react-native";
import { reactiveHooksExtension } from "@prisma/react-native";
export const baseClient = new PrismaClient({
log: [
// {emit: "stdout", level: "query"},
{ emit: "stdout", level: "info" },
{ emit: "stdout", level: "warn" },
{ emit: "stdout", level: "error" },
],
});
export const extendedClient = baseClient.$extends(reactiveHooksExtension());
export async function initializeDb() {
try {
baseClient.$applyPendingMigrations();
console.log("migrations applied");
} catch (e) {
console.error(`failed to apply migrations: ${e}`);
throw new Error(
"Applying migrations failed, your app is now in an inconsistent state. We cannot guarantee safety, it is now your responsibility to reset the database or tell the user to re-install the app"
);
}
}