```import prisma from './prisma'; import { getOrCr...
# orm-help
l
Copy code
import 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?
āœ… 1
v
šŸ‘‹ Hello @Lewis, I've flagged this question for our team and they are consulting on the best approach re: column names. In the meantime can you tell us a little more about your app and the technical stack? (e.g. is it a production application? what is the programming language, automation tooling, hosting, and cloud providers you use?, etc.).
l
Hey @Vladi Stevanovic, It's early development atm, just trying to sharpen my TS skills and get something to boost my portfolio! Is there any word on my field name query?
v
Thank you for the extra context, Lewis! @Harshit @Austin and @Raphael Etim FYI
h
Hey Lewis, can you please share the model here so that we may try this out?
l
Sure, lmk if you need anything else!
Copy code
model 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)
}
@Harshit Have you had a chance to look?
I just need to know if my method is the best type-safe way of getting my column names
a
The
ScalarFieldEnum
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.