Using a filter
You can use a filter for sorting data, search for specific data and update data!
The filter class is an extender of the client. So you can make a filter by doing this.
Constructor
In the constructor, you can give up the limit and the divide for each filter. More explanation for this can you find at the limit section and the divide section. Here are some examples.
Setting the limit
If you are using where
for example, you can say to the MySQL database: I only want 10 results.
You can set this in the constructor or in the filter.setLimit
function. An example to set the limit to 10.
If you want unlimited results, you can do that by giving up the value
0
ornull
.
Setting the divide option
In a filter you can set filters, like name = "Paul"
and mail includes ".nl"
. Those two filters has to be divided. And there comes the divide option.
This you can use:
and
, so you say that the name has to be Paul
AND the mail has to include .nl
.
or
, then the name has to be Paul
OR the mail has to include .nl
.
Here is a example to set the divide (and
and or
are fully written here).
Adding a filter
Now the main purpose for a filter: the filter itself. To add a filter, use the filter.add
function. Here are some examples for filters.
Warning! - If you are using
less
,greater
orbetween
the column and keyword has to be a number! - If you are usingbetween
, the keyword has to be a array of TWO numbers!
Editing a filter
You can edit a filter with the filter.chance
function. If you want to chance a filter, you have to get the ID of the filter. Each filter that you add has a ID, starting by one and counting up. So if you want to chance the second filter that you added, the ID is two.
But, you can also save the filter object in a variable, like all the examples of adding a filter. Then the ID is <VARIABLE>.id
. Here are some examples.
Using the filter
If you have made your filter, you can use it for different functions. The only thing you have to do is giving the filter class up in to the object. Better-MySQL will do the rest!
Self writing a object (advanced)
If you want to write the object itself instead of using the filter, you can do that. If you have a filter, log the filter.handle
function in the console, like this. Click on Output
for the output.
Here you can see the object that will be translated directly to SQL and then requested. If you want, you can make this object for yourself. Just remember:
The limit has to be a number.
The divide has to be in capital letters,
AND
orOR
.The filters is a array with objects in it.
A filter object has to includes
column
,keyword
andtype
.The column has to be a string: This column has to exists in the table!
The keyword has to be a string or array: This can be what you want!
WARNING: Only if the type is
between
the keyword can be a array with two numbers, otherwise it has to be a string or number!The type has to be a string:
equals
,includes
,starts
,ends
,less
,greater
orbetween
.
I don't recommencement to use a object, but if you really want, you can.
Last updated
Was this helpful?