genql
Helper for SQL query generating and formatting
Install
npm i genql
Usage
const GenQL = require('genql');
const model = require('./data/model.json');
const $ = new GenQL(model);
const fields = $._select();
const fieldPrefix = $._select('
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
Contributing
Interested in contributing to this project?
You can log any issues or suggestion related to this library here
Read our contributing guide on getting started with contributing to the codebase
Contributors
Thank you to all the contributors who have helped us in making this project better
);
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
__INLINE_CODE_0__
- Returns default value for the field from model
- __INLINE_CODE_1__
- field (string)
__INLINE_CODE_2__
- Returns all the fields from model, except the __INLINE_CODE_3__ fields. Uses optional __INLINE_CODE_4__ and appends it to column name
- __INLINE_CODE_5__
- prefix (String) {Optional}
__INLINE_CODE_6__
- Returns all the fields from model, appended with __INLINE_CODE_7__ as prefix which is defined in model. Uses optional __INLINE_CODE_8__ and appends it to column name
- __INLINE_CODE_9__
- prefix (String) {Optional}
__INLINE_CODE_10__
- Returns all the column which have __INLINE_CODE_11__ flag defined with it in the model. Uses optinal __INLINE_CODE_12__ and appends it to column names
- __INLINE_CODE_13__
- prefix (String) {Optional}
__INLINE_CODE_14__
- Removes all the values from __INLINE_CODE_15__ object which are marked as private column in model
- __INLINE_CODE_16__
- data {JSON}
__INLINE_CODE_17__
- Returns list of values from data object for all the columns from model which are not marked as private
- __INLINE_CODE_18__
- data (JSON)
__INLINE_CODE_19__
- Returns all the fields from model and uses alternate column if defined in model. Uses optional __INLINE_CODE_20__ and appends it to column name
- __INLINE_CODE_21__
- prefix (String) {Optional}
__INLINE_CODE_22__
- Returns list of values from data for the input fields
- __INLINE_CODE_23__
- fields (Array)
- data (JSON)
Note: Sample model definition is available in data/model.json
Contributing
Interested in contributing to this project? You can log any issues or suggestion related to this library here
Read our contributing guide on getting started with contributing to the codebase
Contributors
Thank you to all the contributors who have helped us in making this project better