Help with raw query

Ppdina5/18/2023
The following query is all raw. Is there a way to make SQL raw only the part of the where clause? (or still better a way to not use raw sql at all)
await dbConn.execute<User>(
sql`select * from ${UserModel} where similarity("name", ${q}) > ${treshold}`
);
await dbConn.execute<User>(
sql`select * from ${UserModel} where similarity("name", ${q}) > ${treshold}`
);
ASAndrii Sherman5/19/2023
Yes, you can
await db.select().from(UserModel).where(sql`similarity("name", ${q}) > ${treshold}`)
await db.select().from(UserModel).where(sql`similarity("name", ${q}) > ${treshold}`)
also if "name" is a column in UserModel you can do this(I would suggest to do this)
await db.select().from(UserModel).where(sql`similarity(${UserModel.name}, ${q}) > ${treshold}`)
await db.select().from(UserModel).where(sql`similarity(${UserModel.name}, ${q}) > ${treshold}`)

Looking for more? Join the community!