Adonis Search
This is repo is a AdonisJs provider for simplicity work with search in adonis-lucid
Install
npm i --save adonis-search
Registering provider
The provider is registered inside start/app.js
file under providers
array.
const providers = 'adonis-query/providers/QueryProvider'
That's all! Now you can use the mail provider as follows.
Sample
Request url is GET
/users?search=mark&page=2&order=-email
const Route = const Query = const User = Route
Usage
Default values
You can change defaults by send second argument in Query constructor
cosnt query = request limit: 50
Search
Note 1. Search not fire where clause if search variable is empty.
Note 2. All search columns and values will be translated to lowercase.
For basic usage you need add columns where you make search
const query = request order: 'id' const users = await User
If you need search in INT
columns, you need set first argument as object with columns types:
const query = request order: 'id' const users = await User
Paginate
You can get parsed values from uri as page
and limit
. Variables are optional.
Route
Order by
For use order by you need set default value order
by column for query
const query = request order: 'id' const order = queryconst users = await User
Reverse sort are supported by set first symbol -
before name column. Sample uri as /users?order=-email
It's native support for AngularJS applications.