Add function to table in schema.ts

I come from a background using the Eloquent ORM in Laravel where you can add methods to the models so you can do something like user.isAdmin() (example with js syntax). Is it possible in Drizzle to add a function to the table so after I've queried a row I can do something similar like
const user = (await db.select()
.from(users)
.where(
eq(users.username, request.nextUrl.searchParams.get("viewer")!),
))[0];

if(user.isAdmin())
{
console.log("is Admin")
}
const user = (await db.select()
.from(users)
.where(
eq(users.username, request.nextUrl.searchParams.get("viewer")!),
))[0];

if(user.isAdmin())
{
console.log("is Admin")
}
or would i have to define helpers like
const isUserAdmin(user: User) {
return true;
}
const isUserAdmin(user: User) {
return true;
}
worth to note that in this example I would have a user_admins table with a one-to-one reference to a User not a is_admin column on the users table
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server