# bare-queryable

> Query on array.

Latest version **1.6.0** (published 2022-05-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install bare-queryable
pnpm add bare-queryable
yarn add bare-queryable
bun add bare-queryable
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.6.0 |
| Published | 2022-05-19 |
| First published | 2021-10-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 24 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Mahdi Aslami Khavari |
| Maintainers | mahdyaslami |
| Keywords | query, array |

## Links

- npm: https://www.npmjs.com/package/bare-queryable
- Repository: https://github.com/mahdyaslami/bare-queryable
- Homepage: https://github.com/mahdyaslami/bare-queryable#readme
- Issues: https://github.com/mahdyaslami/bare-queryable/issues
- npm.io page: https://npm.io/package/bare-queryable

## Alternatives

- [gamedig](https://npm.io/package/gamedig.md) — 29.3K weekly downloads
- [join-monster](https://npm.io/package/join-monster.md) — 12.8K weekly downloads
- [masked](https://npm.io/package/masked.md) — 5.5K weekly downloads
- [@comunica/actor-query-process-explain-logical](https://npm.io/package/@comunica/actor-query-process-explain-logical.md) — 4.7K weekly downloads
- [@veracity/vui](https://npm.io/package/@veracity/vui.md) — 4.6K weekly downloads

## Recent versions

- 1.6.0 (latest) — 2022-05-19
- 1.5.3 — 2021-10-30
- 1.5.0 — 2021-10-20
- 1.4.0 — 2021-10-16
- 1.3.1 — 2021-10-11
- 1.3.0 — 2021-10-11
- 1.1.0 — 2021-10-10
- 1.0.2 — 2021-10-10
- 1.0.1 — 2021-10-10
- 1.0.0 — 2021-10-10

## README

Query on array
==============

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.

Introduction
------------

```javascript
import { query } from 'query'

const users = [
  { id: 1, name: 'bare' },
  { id: 1, name: 'bare' },
]

const result = 
  query(users)
    where('name').contain('re')
    .get()
```

APIs
----

### Select

- #### _get()_

Returns query result.

```javascript
query([...]).get()

```

### Limit

```javascript
query([...]).first()

```

- #### _first()_

Returns first item of query result.

- #### _last()_

Returns last item of query result.

- #### _count()_

Returns count of items in query result.

### Where

```javascript
query([...])
  .where('id').equal(1)
  .get()
```

`column` parameter can be nested, for example:

```javascript
query([...])
  .where('prop.id').equal(1)
  .get()
```

- #### _where(column).equal(value)_

Filters the array so that the column value is exactly equal to the desired value. We use the `===` operator for this comparison.

- #### _where(column).notEqual(value)_

Filters the array so that the column value is not equal to the desired value. We use the `!==` operator for this comparison.

- #### _where(column).above(value)_

Filters the array so that the column value is greater than the desired value.

- #### _where(column).aboveOrEqual(value)_

Filters the array so that the column value is greater than or equal to the desired value.

- #### _where(column).below(value)_

Filters the array so that the column value is lower than the desired value.

- #### _where(column).belowOrEqual(value)_

Filters the array so that the column value is lower than or equal to the desired value.

- #### _where(column).contain(value)_

Filters the array so that the column value contains the desired value.

- #### _where(column).in(array)_

Filters the array so that the column value is inside the desired array.

```javascript
query([...])
  .where('id').in([1, 2, 3])
  .get()
```

- #### _andWhere(column)_

Chain conditions with `and` operator. both ways are ok.

```javascript
query([...])
  .where('id').equal(1)
  .andWhere('name').contain('foo')
  .get()

query([...])
  .where('id').equal(1)
  .where('name').contain('foo')
  .get()
```

- #### _orWhere(column)_

Chain conditions with `or` operator.

```javascript
query([...])
  .where('id').equal(1)
  .orWhere('id').above(10)
  .get()
```

- #### _Compare two columns_

If you want to compare two columns you can use the `.col` attribute.

```javascript
query([...])
  .where('name').col.notEqual('family')
  .get()
```

### Order by

Sorts columns ascending or descending.

```javascript
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:

```javascript
query([...])
  .order('prop.id').equal(1)
  .get()
```

- #### _DATE_COMPARATOR_

A callback that can compare two Dates.

- #### _STRING_COMPARATOR_

A callback that can compare two strings.

- #### _NUMBER_COMPARATOR_

A callback that can compare two numbers.

---
_Source: https://npm.io/package/bare-queryable · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
