Helper for SQL query generating and formatting
npm i genql
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'
// ]-
_default(field)- Returns default value for the field from model
Params- field (string)
-
_insert(prefix)- Returns all the fields from model, except the
autofields. Uses optionalprefixand appends it to column name Params- prefix (String) {Optional}
- Returns all the fields from model, except the
-
_join(prefix)- Returns all the fields from model, appended with
join_keyas prefix which is defined in model. Uses optionalprefixand appends it to column name Params- prefix (String) {Optional}
- Returns all the fields from model, appended with
-
_findPrivate(prefix)- Returns all the column which have
privateflag defined with it in the model. Uses optinalprefixand appends it to column names Params- prefix (String) {Optional}
- Returns all the column which have
-
_removePrivate(data)- Removes all the values from
dataobject which are marked as private column in model Params- data {JSON}
- Removes all the values from
-
_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
prefixand appends it to column name Params- prefix (String) {Optional}
- Returns all the fields from model and uses alternate column if defined in model. Uses 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
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