Lewis
09/14/2022, 11:32 AMimport prisma from './prisma';
import { getOrCreateUser } from "utils";
import type { Prisma } from '@prisma/client';
export class Stats {
static async update(id: string, stat: Prisma.StatsScalarFieldEnum, amount: number) {
await getOrCreateUser(id);
return await prisma.stats.update({
where: {
user_id: id,
},
data: {
[stat]: {
increment: amount,
}
}
});
}
}
Hey, need a little bit of assistance here! I'm just wondering if this is the correct way of getting my column field names (Prisma.StatsScalarFieldEnum)? I saw this is how some other people do this, is there a better solution or am I being really dumb?Vladi Stevanovic
Lewis
09/16/2022, 1:11 PMVladi Stevanovic
Harshit
09/16/2022, 3:08 PMLewis
09/16/2022, 3:12 PMmodel Stats {
user_id String @id @unique
stats User? @relation(fields: [user_id], references: [id], onDelete: Cascade)
fishCaught Int @default(0)
fishSold Int @default(0)
moneyMade Int @default(0)
moneySpent Int @default(0)
coinflipsWon Int @default(0)
coinflipsLost Int @default(0)
coinflipsMoneyWon Int @default(0)
coinflipsMoneyLost Int @default(0)
}
Lewis
09/19/2022, 12:34 AMLewis
09/19/2022, 4:42 PMAustin
09/20/2022, 7:40 PMScalarFieldEnum
type will hold the columns that contain scalar values, so it excludes any relation fields or list fields, as far as I understand. Iām not sure there is a 100% reliable way to get all the column names for a given model.