Socket
Socket
Sign inDemoInstall

npm-json2sql

Package Overview
Dependencies
74
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    npm-json2sql

This package can be used for building SQL from JSON


Version published
Maintainers
1
Install size
3.50 MB
Created

Readme

Source

Purpose

This package can be use to build a mysql query from json.

Usage:


var json2sql=require('npm-json2sql');
myjson = {     
    "filters": { //you can add multiple column for filtering
        "transaction_number": { //transaction_number is the column name
            "value": "56",
            "matchMode": "contains" //can be equal== '=' and contains== 'LIKE'
        },
        "supplier_id": {
            "value": "2",
            "matchMode": "equal" 
        },
        "supplier_name": {
            "value": "jack",
            "matchMode": "contains" 
        }
    },
    //**Sorting and Pagination are optional features**
    "first": 0, // Page Number
    "rows": 10, // Num of Rows per page
    "sortField": "total_amount", //Order by Field 
    "sortOrder": 1 //0==ASC and 1==DESC
};
console.log(json2sql.json2sql(myjson,"transactions"));

Output:

Select * from transactions WHERE transaction_number LIKE '%56%' AND supplier_id = '2' AND supplier_name LIKE '%jack%' ORDER BY total_amount ASC limit 10 OFFSET 0

Keywords

FAQs

Last updated on 08 Aug 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc