Filter (Where)

I want to make where is optional like is user add searchParams then it will search otherwise select all data from db.
In the down I just shared my code,, please help me to fix that as soon as possible, please

  const [lengths, profiles] = await Promise.all([
    db.select({ count: sql<number>`count(*)` }).from(users),
    db
      .select()
      .from(users)
      .where(
        or(
          ilike(users.name, `%${searchParams}%`),
          ilike(users.location, `%${searchParams}%`)
        )
      )
      .limit(itemPerPage)
      .offset(offset),
  ]);
  const count = lengths[0].count;
Was this page helpful?