Skip to content

Commit

Permalink
use one global instance of Prisma client (#362)
Browse files Browse the repository at this point in the history
  • Loading branch information
lihebi authored Jul 8, 2023
1 parent 03dc3d3 commit 5ae438a
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 21 deletions.
5 changes: 5 additions & 0 deletions api/src/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { PrismaClient } from "@prisma/client";

let prisma = new PrismaClient();

export default prisma;
7 changes: 1 addition & 6 deletions api/src/resolver_export.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Prisma from "@prisma/client";

import AWS from "aws-sdk";
import { writeFile, readFile, unlink } from "fs/promises";
import prisma from './client'

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

Expand Down Expand Up @@ -37,10 +36,6 @@ async function uploadToS3WithExpiration(filename, content) {
}
}

const { PrismaClient } = Prisma;

const prisma = new PrismaClient();

/**
* Export to a JSON file for the pods' raw data.
*/
Expand Down
5 changes: 1 addition & 4 deletions api/src/resolver_repo.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import Prisma from "@prisma/client";
// nanoid v4 does not work with nodejs. https://github.com/ai/nanoid/issues/365
import { customAlphabet } from "nanoid/async";
import { lowercase, numbers } from "nanoid-dictionary";
import prisma from './client'

const nanoid = customAlphabet(lowercase + numbers, 20);
const { PrismaClient } = Prisma;

const prisma = new PrismaClient();

async function ensureRepoEditAccess({ repoId, userId }) {
let repo = await prisma.repo.findFirst({
Expand Down
6 changes: 0 additions & 6 deletions api/src/resolver_runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ import {
initRoutes as initRoutes_k8s,
} from "./spawner-k8s";

import Prisma from "@prisma/client";

const { PrismaClient } = Prisma;

const prisma = new PrismaClient();

const apollo_client = new ApolloClient({
cache: new InMemoryCache({}),
uri: process.env.PROXY_API_URL,
Expand Down
7 changes: 2 additions & 5 deletions api/src/resolver_user.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Prisma from "@prisma/client";
import bcrypt from "bcryptjs";
import jwt from "jsonwebtoken";
import { OAuth2Client } from "google-auth-library";
Expand All @@ -7,11 +6,9 @@ import { OAuth2Client } from "google-auth-library";
import { customAlphabet } from "nanoid/async";
import { lowercase, numbers } from "nanoid-dictionary";

const nanoid = customAlphabet(lowercase + numbers, 20);

const { PrismaClient } = Prisma;
import prisma from './client'

const prisma = new PrismaClient();
const nanoid = customAlphabet(lowercase + numbers, 20);

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

0 comments on commit 5ae438a

Please sign in to comment.