Search util for Lux.
IMPORTANT: This util requires Lux 1.2.0+.
$ npm i --save lux-search
Lux-search can be used to substring search a single or multiple columns whereas number columns are searched left to right. The util is meant to be used in the index action or a custom action. It will extend the (knex) query with a whereRaw call.
- query - An instance of knex'es query object or a super call to a Lux'es super.index;
- request - The request object passed into the action in which search is used
- options - Options Array. Can either contain a string or a 2D array for multi-column search. See the example below.
import search from 'lux-search'
index(request, response) {
return search(
super.index(request, response),
request,
[
'firstName',
'address',
'someNumber',
['fullName', ['firstName', 'suffix', 'surName']]
]
);
}
And an accompanying example request:
GET localhost:4000/?search[fullName]=SomeSubstr&search[someNumber]=123
NOTE: characters must of course be properly URL encoded.
The aim is to support database drivers as supported by Lux.
Currently supported database drivers are:
- pg
- sqlite3
NOTE: A case insensitive collation must be used
- mysql
- mysql2
- mariasql
NOTE: A case insensitive collation must be used
Other drivers which are to be supported in the near future are:
- strong-oracle
- oracle
- mssql
$ npm install
$ npm test
This project is licensed under the MIT license. See the LICENSE file for more info.