-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathmyDbModule.ts
More file actions
25 lines (22 loc) · 860 Bytes
/
myDbModule.ts
File metadata and controls
25 lines (22 loc) · 860 Bytes
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 {
await baseClient.$applyPendingMigrations();
console.log("db initialized!");
} 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"
);
}
}