Help with raw query

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}`
);
1 Reply
Andrii Sherman
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}`)
Want results from more Discord servers?
Add your server