Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

knex muliple like query

public async getFilteredItems(searchCriteria): Promise<any[]> {
    const table = 'items';
    const columns = ['itemName', 'itemType', 'category'];
    const qb = (query) => {
      for (const col of columns) {
        query.orWhere(`${table}.${col}`, 'like', `%${searchCriteria[col]}%`);
      }
    }
    return await knex(table).where(qb);
}
 
PREVIOUS NEXT
Tagged: #knex #muliple #query
ADD COMMENT
Topic
Name
8+8 =