Giter Club home page Giter Club logo

genql's Introduction

genql

Build NPM Version NPM Downloads Github Repo Size LICENSE Contributors Commit

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('$');
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

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

genql's People

Contributors

arshadkazmi42 avatar dependabot[bot] avatar oilyn0s3 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

genql's Issues

fix vulnerability

  • Delete package-lock.json
  • Run npm install
  • Commit the updated package-lock.json
  • Create pull request

deploy latest 2.0

  • Library restructure.
  • Parse functionality to move out to main client modules
  • Breaking change, release v2.0

Add badges for readme using npm-badger

  1. Install npm badger npm install npm-badger -g
  2. Clone this repository git clone https://github.com/arshadkazmi42/genql
  3. Go to root directory cd genql
  4. Run npm badger npm-badger
  5. Commit README.md file
  6. Create Pull Request

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.