NicoFish
NicoFish
Explore posts from servers
PPrisma
Created by NicoFish on 10/9/2024 in #help-and-questions
Extending client not typesafe
I'm working in a NestJS project and need to extend the prisma client to replace all Date with string. I have this code:
import { Injectable, OnModuleInit } from '@nestjs/common';
import { PrismaClient } from '~/types/prisma-schema';

export type WithSerializedDates<T> = T extends Date
? string
: T extends Array<infer R>
? Array<WithSerializedDates<R>>
: T extends object
? { [K in keyof T]: WithSerializedDates<T[K]> }
: T;

export const withoutDates = <T>(model: T): WithSerializedDates<T> =>
JSON.parse(JSON.stringify(model)) as WithSerializedDates<T>;

@Injectable()
export class PrismaService extends PrismaClient implements OnModuleInit {
async onModuleInit(): Promise<void> {
await this.$extends({
query: {
$allModels: {
$allOperations: async ({ query, args }) => {
return withoutDates(await query(args));
},
},
},
}).$connect();
}
}
import { Injectable, OnModuleInit } from '@nestjs/common';
import { PrismaClient } from '~/types/prisma-schema';

export type WithSerializedDates<T> = T extends Date
? string
: T extends Array<infer R>
? Array<WithSerializedDates<R>>
: T extends object
? { [K in keyof T]: WithSerializedDates<T[K]> }
: T;

export const withoutDates = <T>(model: T): WithSerializedDates<T> =>
JSON.parse(JSON.stringify(model)) as WithSerializedDates<T>;

@Injectable()
export class PrismaService extends PrismaClient implements OnModuleInit {
async onModuleInit(): Promise<void> {
await this.$extends({
query: {
$allModels: {
$allOperations: async ({ query, args }) => {
return withoutDates(await query(args));
},
},
},
}).$connect();
}
}
But when using the client, it does not apply the extension types.
7 replies
TtRPC
Created by NicoFish on 4/28/2024 in #❓-help
Change db url in ctx with an API call
I want to have a switch in my frontend to change from dev db to prod db. I'm using prisma. Have 2 prisma instances (one for prod and the other for dev). Is there any way to override the prisma instance in the ctx with an API call?
4 replies
TtRPC
Created by NicoFish on 4/4/2024 in #❓-help
Trouble with Vercel and deployment URL
Hey I've been having a problem with nextjs deploying to vercel. In localhost the calls to the backend are done correctly, but when deployed, the calls are made to https://myvercelurl.vercel.app/deployment_url/api/trpc/.... I don't know why the hell the deployment_url is inserted there. Running in npm, packages: @trpc/client: ^10.45.0 => 10.45.1 @trpc/next: ^10.45.0 => 10.45.1 @trpc/react-query: ^10.45.0 => 10.45.1 @trpc/server: ^10.45.0 => 10.45.1 next: 14.1.0 => 14.1.0 react: ^18 => 18.2.0 typescript: ^5 => 5.3.3 If someone could help me I will really appreciate it
1 replies