How to deal with the type of response in sql'' template

How can we deal with the types of sql'' template since the result is accessable from the rows property of result, Unlike the ORM itself.
const { rows } = await db.execute(
sql`SELECT DISTINCT ${vehicleReferences.manufacturer} FROM ${vehicleReferences} WHERE ${vehicleReferences.vehType} = ${category}`
)

// Mapping the result to get only the brands as an Array
const vehTypes = rows.map((row) => row.manufacturer)

res.json({ brands: vehTypes })
const { rows } = await db.execute(
sql`SELECT DISTINCT ${vehicleReferences.manufacturer} FROM ${vehicleReferences} WHERE ${vehicleReferences.vehType} = ${category}`
)

// Mapping the result to get only the brands as an Array
const vehTypes = rows.map((row) => row.manufacturer)

res.json({ brands: vehTypes })
For example rows are not type-safe here and I have to guess row manufacturer
1 Reply
Angelelz
Angelelz11mo ago
depending on your driver, db.execute accepts a generic parameter in which you can describe the shape of your rows
Want results from more Discord servers?
Add your server