# @samhuk/data-query

> Data query package with SQL and URL conversions

Latest version **1.2.3** (published 2022-10-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install @samhuk/data-query
pnpm add @samhuk/data-query
yarn add @samhuk/data-query
bun add @samhuk/data-query
```

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.3 |
| Published | 2022-10-15 |
| First published | 2022-06-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 50.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Maintainers | samhuk |

## Links

- npm: https://www.npmjs.com/package/@samhuk/data-query
- Repository: https://github.com/samhuk/data-query
- Homepage: https://github.com/samhuk/data-query#readme
- Issues: https://github.com/samhuk/data-query/issues
- npm.io page: https://npm.io/package/@samhuk/data-query

## Dependencies (1)

- [@samhuk/data-filter](https://npm.io/package/@samhuk/data-filter.md) ^1.1.1

## Recent versions

- 1.2.3 (latest) — 2022-10-15
- 1.2.2 — 2022-10-15
- 1.2.1 — 2022-10-05
- 1.2.0 — 2022-10-05
- 1.1.8 — 2022-08-21
- 1.1.7 — 2022-08-20
- 1.1.6 — 2022-08-03
- 1.1.5 — 2022-08-01
- 1.1.4 — 2022-08-01
- 1.1.3 — 2022-07-29
- 1.1.2 — 2022-07-23
- 1.1.1 — 2022-07-23
- 1.1.0 — 2022-07-23
- 1.0.3 — 2022-07-21
- 1.0.2 — 2022-06-26
- … 2 more at https://npm.io/package/@samhuk/data-query/versions

## README

# data-query

A package for creating data queries with paging, sorting, and filtering, with URL and SQL conversion.

## Usage

`npm i @samhuk/data-query`

```typescript
import { createDataQuery } from '@samhuk/data-query'
import { Operator, DataFilterLogic } from '@samhuk/data-filter/types'

const dq = createDataQuery({
  page: 5,
  pageSize: 10,
  sorting: [{ field: 'user_id', dir: 'asc' }],
  filter: {
    field: 'date_deleted',
    op: '!=',
    val: null,
  }
})

// Convert to/from SQL and URL params
const sql = dq.toSql()
const urlParams = dq.toUrlParams()
const urlParamsString = dq.toUrlParamsString()
const dq1FromUrlParams = createDataQuery().fromUrlParams(urlParams)

// Update parts of the data query
dq1FromUrlParams.updatePage(6).updatePageSize(11)
```

See the JSDocs for more information on the available options and other capabilities.

## Development

`npm i`

`npm start` - Start a hot reloading tsc build.

`npm run check` - Run linting, unit tests, and tsc build.

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