Helper for sql query generation and formatting
MIT License
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)
Params
_insert(prefix)
auto
fields. Uses optional prefix
and appends it to column nameParams
_join(prefix)
join_key
as prefix which is defined in model. Uses optional prefix
and appends it to column nameParams
_findPrivate(prefix)
private
flag defined with it in the model. Uses optinal prefix
and appends it to column namesParams
_removePrivate(data)
data
object which are marked as private column in modelParams
_values(data)
Params
_select(prefix)
prefix
and appends it to column nameParams
_update(fields, data)
Params
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