将 Json 对象转换为 SQL Table
Convert Json Object To SQL Table
我想动态生成 sql 查询。我找到了这个工具
http://querybuilder.js.org/demo.html
我有以下 JSON 对象:
{
"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"
}
]
}
]
}
现在我想生成 SQL Table 以便正确保存此 JSON 数据。
有什么方法可以生成Table,如果有请给我link或者请帮我创建相同的table
您的 Json 数据需要使用递归解码 SQL function.You 首先需要创建一个自引用 table 像这样:
CREATE TABLE jsonCondition(
ConditionId INT IDENTITY,
ParentCondotionId INT ,
Id NVARCHAR(20),
Field NVARCHAR(20),
Type NVARCHAR(20),
Input NVARCHAR(20),
Operator NVARCHAR(20),
Value NVARCHAR(20)
)
那请参考我的另一个json递归转换为SQL在:
如何使用 Microsoft SQL Server 2016 生成分层 JSON 数据?
我想动态生成 sql 查询。我找到了这个工具
http://querybuilder.js.org/demo.html
我有以下 JSON 对象:
{
"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"
}
]
}
]
}
现在我想生成 SQL Table 以便正确保存此 JSON 数据。 有什么方法可以生成Table,如果有请给我link或者请帮我创建相同的table
您的 Json 数据需要使用递归解码 SQL function.You 首先需要创建一个自引用 table 像这样:
CREATE TABLE jsonCondition(
ConditionId INT IDENTITY,
ParentCondotionId INT ,
Id NVARCHAR(20),
Field NVARCHAR(20),
Type NVARCHAR(20),
Input NVARCHAR(20),
Operator NVARCHAR(20),
Value NVARCHAR(20)
)
那请参考我的另一个json递归转换为SQL在: 如何使用 Microsoft SQL Server 2016 生成分层 JSON 数据?