I want to generate sql query dynamically. I found this tool
http://querybuilder.js.org/demo.html
And i have the following JSON object:
{
"condition": "AND",
"rules": [
{
"id": "name",
"field": "name",
"type": "string",
"input": "text",
"operator": "equal",
"value": "zura"
},
{
"condition": "OR",
"rules": [
{
"id": "category",
"field": "category",
"type": "integer",
"input": "select",
"operator": "equal",
"value": "1"
},
{
"id": "price",
"field": "price",
"type": "double",
"input": "number",
"operator": "equal",
"value": "123"
}
]
},
{
"id": "in_stock",
"field": "in_stock",
"type": "integer",
"input": "radio",
"operator": "equal",
"value": "1"
},
{
"condition": "AND",
"rules": [
{
"id": "category",
"field": "category",
"type": "integer",
"input": "select",
"operator": "equal",
"value": "2"
},
{
"id": "in_stock",
"field": "in_stock",
"type": "integer",
"input": "radio",
"operator": "equal",
"value": "0"
}
]
}
]
}
Now i want to generate SQL Table in order to save this JSON data properly. Is there any way to generate Table, if yes please give me link or please help me to create same table
VARCHAR,TEXT, etc (w3schools.com/sql/sql_datatypes_general.asp). You could use theCREATE TABLEstatement (w3schools.com/sql/sql_create_table.asp), but based on your JSON values, I don't think you'd be creating a valid SQL table. For example, from your data:rules["type"] = string,stringis not a valid SQL datatype, whereasVARCHAR(200)is. If you were to dynamically generate your table based on an object, I'd presume you'd need the right datatypes, at the very least, as key values.CREATE TABLE(see link in my last comment). When you create the table, you have to define its structure, which requires defining a data type. IE, the SQL table has to know what type of data to expect (numbers, text, etc). As far as I know, you can't create an SQL table without setting data types for the properties you are trying to capture. It's a requirement when the table is created. A lot of people use MySQL Workbench to draft up their vision and the program spits out the SQL table for them.