Replies: 3 comments 3 replies
-
|
+1 to this discussion. I have the same issue. |
Beta Was this translation helpful? Give feedback.
-
|
hey guys, I actually figured out a work around this issue. let query = 'testing'
query = '%' + query + '%'
ilike(table.column, query)the actual code I used is as follows (havent tested the above code) export async function findDesertFigure(val: string) {
val = "%" + val + "%";
console.log(val);
try {
const res = await db
.select()
.from(df)
.where(
sql`concat_ws(' ', ${df.title}, ${df.firstName}, ${df.lastName}, ${df.epithet}) ilike ${val}`,
);
console.log(res);
return res;
} catch (error) {
console.log(error);
}
} |
Beta Was this translation helpful? Give feedback.
-
|
For postgres: I would argue, that in an const queryCondition = ilike(table.columnToSearch, `%${query}%`);... One would also have to "manually" escape For example: const escapedSearch = search.replace(/[%_]/g, "\\$&");
const queryCondition = ilike(column, `%${escapedSearch}%`); |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I've read through the docs and it's unclear to me exactly when and how content is escaped in Drizzle. We have a basic search endpoint that accepts a query, on the back-end we build the condition like this:
(NOTE: I'm aware this is not the most efficient way to do searches, I'm not asking about that).
From my understanding from the docs, I think this works like this:
queryis"test"%${query}%becomes%test%"%test%"is passed as a value toilike(...)%(and maybe that's fine).Is this the safest way to build a string like that contains some database internal parts AND user input?
I've tried doing this with the
sqloperator too, but I get errors. If I do:I get a database syntax error at "%" -- okay. I see that. So then I quote it:
I then get an error "could not determine the type of parameter $1," again... okay that makes some sense I guess. So I try:
But that returns the same error as without a type. So I guess using
sqlis not the solution.Beta Was this translation helpful? Give feedback.
All reactions