View to compose two fields?

Hello I have three columns in my auth table today, name, givenName, and familyName. I was looking to get rid of the name one, and have a "view" that creates the name based on the other two. I looked at the docs but I can't really figure it out: https://orm.drizzle.team/docs/views Is it possible?
1 Reply
KirbyTwister
KirbyTwister5mo ago
Pretty sure you can just define it as a computed column like:
db.select({
givenName: Users.givenName,
familyName: Users.familyName,
name: sql<string>`${Users.givenName} || '' || ${Users.familyName}`.as('name')
})
db.select({
givenName: Users.givenName,
familyName: Users.familyName,
name: sql<string>`${Users.givenName} || '' || ${Users.familyName}`.as('name')
})

Did you find this page helpful?