How can I extend queries with additional fields

I have the following model:

export const titleEnum = pgEnum("title", ["Mr.", "Mrs.", "Ms.", "Miss.", "Dr."]);

export const Client = pgTable("client", {
    id: uuid("id").primaryKey().defaultRandom(),
    title: titleEnum("title"),
    firstName: text("first_name"),
    lastName: text("last_name"),
    companyName: text("company_name")
})


Depending on the information available, I would like to expose a "name" field that contains one of the following values (in order of priority):

Title Firstname Lastname
Firstname Lastname
Title Firstname
FirstName
Title Lastname
Lastname
Company Name
Null

How can I do this?
Was this page helpful?