bare-queryable help you to query on an array of objects as SQL way.
In the usual way, you need to create a callback method for javascript array helpers like filter() and etc, But here you only do what you need.
import { query } from 'query'
const users = [
{ id: 1, name: 'bare' },
{ id: 1, name: 'bare' },
]
const result =
query(users)
where('name').contain('re')
.get()
Returns query result.
query([...]).get()
query([...]).first()
Returns first item of query result.
Returns last item of query result.
Returns count of items in query result.
query([...])
.where('id').equal(1)
.get()
column
parameter can be nested, for example:
query([...])
.where('prop.id').equal(1)
.get()
Filters the array so that the column value is exactly equal to the desired value. We use the ===
operator for this comparison.
Filters the array so that the column value is not equal to the desired value. We use the !==
operator for this comparison.
Filters the array so that the column value is greater than the desired value.
Filters the array so that the column value is greater than or equal to the desired value.
Filters the array so that the column value is lower than the desired value.
Filters the array so that the column value is lower than or equal to the desired value.
Filters the array so that the column value contains the desired value.
Filters the array so that the column value is inside the desired array.
query([...])
.where('id').in([1, 2, 3])
.get()
Chain conditions with and
operator. both ways are ok.
query([...])
.where('id').equal(1)
.andWhere('name').contain('foo')
.get()
query([...])
.where('id').equal(1)
.where('name').contain('foo')
.get()
Chain conditions with or
operator.
query([...])
.where('id').equal(1)
.orWhere('id').above(10)
.get()
If you want to compare two columns you can use the .col
attribute.
query([...])
.where('name').col.notEqual('family')
.get()
Sorts columns ascending or descending.
import { NUMBER_COMPARATOR, STRING_COMPARATOR, DATE_COMPARATOR } from 'bare-queryable'
query([...])
.orderBy('id', NUMBER_COMPARATOR).asc()
.orderBy('name', STRING_COMPARATOR).desc()
.orderBy('born_at', DATE_COMPARATOR).desc()
.get()
column
parameter can be nested, for example:
query([...])
.order('prop.id').equal(1)
.get()
A callback that can compare two Dates.
A callback that can compare two strings.
A callback that can compare two numbers.