npm-json2sql

1.0.9 • Public • Published

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

Package Sidebar

Install

npm i npm-json2sql

Weekly Downloads

4

Version

1.0.9

License

ISC

Unpacked Size

10.1 kB

Total Files

6

Last publish

Collaborators

  • sameeriqbal