Skip to content

Commit 5ae438a

Browse files
authored
use one global instance of Prisma client (#362)
1 parent 03dc3d3 commit 5ae438a

File tree

5 files changed

+9
-21
lines changed

5 files changed

+9
-21
lines changed

api/src/client.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { PrismaClient } from "@prisma/client";
2+
3+
let prisma = new PrismaClient();
4+
5+
export default prisma;

api/src/resolver_export.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import Prisma from "@prisma/client";
2-
31
import AWS from "aws-sdk";
42
import { writeFile, readFile, unlink } from "fs/promises";
3+
import prisma from './client'
54

65
console.log("REGION", process.env.EXPORT_AWS_S3_REGION);
76

@@ -37,10 +36,6 @@ async function uploadToS3WithExpiration(filename, content) {
3736
}
3837
}
3938

40-
const { PrismaClient } = Prisma;
41-
42-
const prisma = new PrismaClient();
43-
4439
/**
4540
* Export to a JSON file for the pods' raw data.
4641
*/

api/src/resolver_repo.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
import Prisma from "@prisma/client";
21
// nanoid v4 does not work with nodejs. https://github.com/ai/nanoid/issues/365
32
import { customAlphabet } from "nanoid/async";
43
import { lowercase, numbers } from "nanoid-dictionary";
4+
import prisma from './client'
55

66
const nanoid = customAlphabet(lowercase + numbers, 20);
7-
const { PrismaClient } = Prisma;
8-
9-
const prisma = new PrismaClient();
107

118
async function ensureRepoEditAccess({ repoId, userId }) {
129
let repo = await prisma.repo.findFirst({

api/src/resolver_runtime.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@ import {
1616
initRoutes as initRoutes_k8s,
1717
} from "./spawner-k8s";
1818

19-
import Prisma from "@prisma/client";
20-
21-
const { PrismaClient } = Prisma;
22-
23-
const prisma = new PrismaClient();
24-
2519
const apollo_client = new ApolloClient({
2620
cache: new InMemoryCache({}),
2721
uri: process.env.PROXY_API_URL,

api/src/resolver_user.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import Prisma from "@prisma/client";
21
import bcrypt from "bcryptjs";
32
import jwt from "jsonwebtoken";
43
import { OAuth2Client } from "google-auth-library";
@@ -7,11 +6,9 @@ import { OAuth2Client } from "google-auth-library";
76
import { customAlphabet } from "nanoid/async";
87
import { lowercase, numbers } from "nanoid-dictionary";
98

10-
const nanoid = customAlphabet(lowercase + numbers, 20);
11-
12-
const { PrismaClient } = Prisma;
9+
import prisma from './client'
1310

14-
const prisma = new PrismaClient();
11+
const nanoid = customAlphabet(lowercase + numbers, 20);
1512

1613
async function me(_, __, { userId }) {
1714
if (!userId) throw Error("Unauthenticated");

0 commit comments

Comments
 (0)