Virgile
Virgile
PPrisma
Created by Virgile on 10/7/2024 in #help-and-questions
Still unable to get Optimize working in my NestJS app.
Hi everyone. I would really like to try Optimize, and have been trying for some time. See similar discussion here https://discord.com/channels/937751382725886062/1270167207204356178/1275034014025121792 But it does not record anything. There is not a single log. No "errors" logs, no "success" logs. I don't know what's going on. Did Optimize initialize successfully ? Did it error ? Again, using NestJS. Here is current non-working code :
import { Inject, Injectable } from "@nestjs/common";
import type { ConfigType } from "@nestjs/config";
import { PrismaClient } from "@prisma/client";
import { withOptimize } from "@prisma/extension-optimize";
import appConfig, { appConfigFeature } from "../config/app.config";

@Injectable()
export class PrismaService extends PrismaClient {
constructor(
@Inject(appConfigFeature.KEY)
private readonly appConfiguration: ConfigType<typeof appConfig>,
) {
super();
this.$extends(withOptimize({
apiKey: this.appConfiguration.PRISMA_OPTIMIZE_KEY,
}))
try {
if (
this.appConfiguration.NODE_ENV === "production" ||
this.appConfiguration.NODE_ENV === "development"
) {
const extendedClient = this.$extends(withOptimize({
apiKey: this.appConfiguration.PRISMA_OPTIMIZE_KEY,
}));
Object.assign(this, extendedClient);
}
this.user.findMany()
} catch (error) {
console.error(error)
}
}
import { Inject, Injectable } from "@nestjs/common";
import type { ConfigType } from "@nestjs/config";
import { PrismaClient } from "@prisma/client";
import { withOptimize } from "@prisma/extension-optimize";
import appConfig, { appConfigFeature } from "../config/app.config";

@Injectable()
export class PrismaService extends PrismaClient {
constructor(
@Inject(appConfigFeature.KEY)
private readonly appConfiguration: ConfigType<typeof appConfig>,
) {
super();
this.$extends(withOptimize({
apiKey: this.appConfiguration.PRISMA_OPTIMIZE_KEY,
}))
try {
if (
this.appConfiguration.NODE_ENV === "production" ||
this.appConfiguration.NODE_ENV === "development"
) {
const extendedClient = this.$extends(withOptimize({
apiKey: this.appConfiguration.PRISMA_OPTIMIZE_KEY,
}));
Object.assign(this, extendedClient);
}
this.user.findMany()
} catch (error) {
console.error(error)
}
}
Is there a method to know which middlewares have been added ? like this.prisma.listActiveMiddlewares() or something ? So that I could troubleshoot, debug, try things to know where the problem comes from ? Like does it come from my implementation or from Prisma, or from the Class ? Cheers.
16 replies
PPrisma
Created by Virgile on 5/17/2024 in #help-and-questions
How to authenticate Prisma Optimize in a VPS ?
Hi everyone. I enabled Prisma Optimize on a project to try it out. On local, I can authenticate using the browser, all works well. On a VPS though, I pushed to prod and my website crashed. How can we authenticate to Prisma on a VPS ? What command could I run before hand to avoid this issue ? I have a production and a preproduction environment, do I need to authenticate for both, or only for one ? Do we need to run this command inside the project, alongside the schema.prisma ? Thanks !
8 replies