Column name alias

Is there a way to create column name alias in SELECT queries ? like (name as petName).
3 Replies
aitorcas
aitorcas15mo ago
Is my first time answering here so don't fully trust me. I was able to rename a select column with the sql as() function. For example:
db.
select({
username: sql`${users.name}`.as("user_name")
})
.from(users)
db.
select({
username: sql`${users.name}`.as("user_name")
})
.from(users)
But when doing that the type of username isn't inferred, so you can add the type you want using <>.
sql<string>`${users.name}`.as("user_name")
sql<string>`${users.name}`.as("user_name")
Angelelz
Angelelz15mo ago
^ This
peli
peliOP15mo ago
@aitorcas oy cool buddy thanks for the reply, I was hoping there is something built-in, like we have on select({ user: true }) maybe select({ user: 'username' }), you know what I mean but this is also fine for me, as I'm quite a fan of query builders (see you kysely)
Want results from more Discord servers?
Add your server