# genql

> Helper for generating and formatting SQL queries

Latest version **2.0.1** (published 2021-08-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install genql
pnpm add genql
yarn add genql
bun add genql
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2021-08-15 |
| First published | 2019-08-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Arshad Kazmi |
| Maintainers | arshadkazmi42 |
| Keywords | sql, query, sql query, query format, query generate, mysql, sqlite, query helper |

## Links

- npm: https://www.npmjs.com/package/genql
- Repository: https://github.com/arshadkazmi42/genql
- Homepage: https://github.com/arshadkazmi42/genql#readme
- Issues: https://github.com/arshadkazmi42/genql/issues
- npm.io page: https://npm.io/package/genql

## Dependencies (1)

- [lodash](https://npm.io/package/lodash.md) ^4.17.15

## 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

- 2.0.1 (latest) — 2021-08-15
- 2.0.0 — 2019-09-05
- 1.0.4 — 2019-08-11
- 1.0.3 — 2019-08-11
- 1.0.2 — 2019-08-04
- 1.0.1 — 2019-08-04
- 1.0.0 — 2019-08-04

## README

# genql

[![Build](https://github.com/arshadkazmi42/genql/actions/workflows/nodejs.yml/badge.svg)](https://github.com/arshadkazmi42/genql/actions/workflows/nodejs.yml)
[![NPM Version](https://img.shields.io/npm/v/genql.svg)](https://www.npmjs.com/package/genql)
[![NPM Downloads](https://img.shields.io/npm/dt/genql.svg)](https://www.npmjs.com/package/genql)
[![Github Repo Size](https://img.shields.io/github/repo-size/arshadkazmi42/genql.svg)](https://github.com/arshadkazmi42/genql)
[![LICENSE](https://img.shields.io/npm/l/genql.svg)](https://github.com/arshadkazmi42/genql/blob/master/LICENSE)
[![Contributors](https://img.shields.io/github/contributors/arshadkazmi42/genql.svg)](https://github.com/arshadkazmi42/genql/graphs/contributors)
[![Commit](https://img.shields.io/github/last-commit/arshadkazmi42/genql.svg)](https://github.com/arshadkazmi42/genql/commits/master)



Helper for SQL query generating and formatting

## Install

```
npm i genql
```

## Usage

```javascript

const GenQL = require('genql');
const model = require('./data/model.json');

const $ = new GenQL(model);
const fields = $._select();
const fieldPrefix = $._select('$');
console.log(fields);
console.log(fieldPrefix);

// OUTPUT -> {{fields}}
// [
//  'id',
//  'name',
//  'email',
//  'COALESCE(NULLIF(class, ''), cls)',
//  'status'
// ]

// OUTPUT -> {{fieldPrefix}}
// [
//  '$.id',
//  '$.name',
//  '$.email',
//  'COALESCE(NULLIF($.class, ''), cls)',
//  '$.status'
// ]

```

## API

- **`_default(field)`**
  - Returns default value for the field from model
  - ***`Params`***
    - field (string)

- **`_insert(prefix)`**
  - Returns all the fields from model, except the `auto` fields. Uses optional `prefix` and appends it to column name
  - ***`Params`***
    - prefix (String) {Optional}

- **`_join(prefix)`**
  - Returns all the fields from model, appended with `join_key` as prefix which is defined in model. Uses optional `prefix`  and appends it to column name
  - ***`Params`***
    - prefix (String) {Optional}

- **`_findPrivate(prefix)`**
  - Returns all the column which have `private` flag defined with it in the model. Uses optinal `prefix` and appends it to column names
  - ***`Params`***
    - prefix (String) {Optional}

- **`_removePrivate(data)`**
  - Removes all the values from `data` object which are marked as private column in model
  - ***`Params`***
    - data {JSON}

- **`_values(data)`**
  - Returns list of values from data object for all the columns from model which are not marked as private
  - ***`Params`***
    - data (JSON)

- **`_select(prefix)`**
  - Returns all the fields from model and uses alternate column if defined in model. Uses optional `prefix` and appends it to column name
  - ***`Params`***
    - prefix (String) {Optional}

- **`_update(fields, data)`**
  - Returns list of values from data for the input fields
  - ***`Params`***
    - fields (Array)
    - data (JSON)

> Note: Sample model definition is available in [data/model.json](data/model.json)


## Contributing

Interested in contributing to this project?
You can log any issues or suggestion related to this library [here](https://github.com/arshadkazmi42/genql/issues/new)

Read our contributing [guide](CONTRIBUTING.md) on getting started with contributing to the codebase

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