作者: 一了 <1liao3@funlang.org> 日期: 2019-08-08
在 json 根目录下建立 OrmInit 节点, 保存 O/R Mapping Schema 初始化信息
{
"init-connectionString": "数据库连接串",
"init-options": {
//...
},
"OrmInit": {
//...
}
}
{
"init-connectionString": "数据库连接串",
"init-options": {
//...
},
"OrmInit": {
//...
},
// 用于取回自增字段 autoId 的语句, 返回必须命名为 autoId
"OrmSelectAutoId": "SELECT SCOPE_IDENTITY() as autoId"
}
{
"method": "OrmGet",
"args": {
"ObjectName1": {
// key-value list, may be empty (means get all)
}, //...
"ObjectNameX": {
// key-value list, may be empty (means get all)
}
}
}
{
"method": "OrmSave",
"args": {
"ObjectName1": [
{
// key-value list
},
// ...
], //...
"ObjectNameX": [
// Object list
]
}
}
{
"method": "OrmUpdate",
"args": {
"ObjectName1": {
"Set": {
// key-value list
},
"Where": {
// key-value list
}
}, //...
"ObjectNameX": {
// Set and Where list
}
}
}
{
"method": "OrmDelete",
"args": {
"ObjectName1": {
// key-value list
}, //...
"ObjectNameX": {
// key-value list
}
}
}
ORM 支持 NOT, AND, OR, IS [NOT] NULL, [NOT] LIKE, [NOT] BETWEEN AND, [NOT] IN, 比较运算符等, 如下:
[
Order: [
CustomerID : 'VINET',
$OR : [
CustomerID : ">= VI'NET",
EmployeeID : 'NOT NULL',
ShipAddress: 'not like a%',
Freight : 'not between 0 AND 1',
OrderDate : "between '1996-7-4' AND '2096-7-4'",
$NOT : [
CustomerID : "<> VI'NET",
Freight : 'not in (0, 1)',
$AND : [
Freight : '<> 1 + 2',
EmployeeID : 'NULL',
CustomerID : "not in ('VINET')"
]
]
]
, $Set_quantifier: 'DISTINCT TOP 10 '
, $Order: [EmployeeID:1, Freight:-1]
],
Customer: [CustomerID: 'VINET'],
Region: []
]
{
"Order": {
"CustomerID": "VINET",
"$OR": {
"CustomerID": ">= VI'NET",
"EmployeeID": "NOT NULL",
"ShipAddress": "not like a%",
"Freight": "not between 0 AND 1",
"OrderDate": "between '1996-7-4' AND '2096-7-4'",
"$NOT": {
"CustomerID": "<> VI'NET",
"Freight": "not in (0, 1)",
"$AND": {
"Freight": "<> 1 + 2",
"EmployeeID": "NULL",
"CustomerID": "not in ('VINET')"
}
}
},
"$Set_quantifier": "DISTINCT TOP 10 ",
"$Order": {
"EmployeeID": 1,
"Freight": -1
}
},
"Customer": {
"CustomerID": "VINET"
},
"Region": [
]
}
SELECT DISTINCT TOP 10 *
FROM "Orders"
WHERE
"CustomerID" = 'VINET' AND (
"CustomerID" >= 'VI''NET' OR
"EmployeeID" IS NOT NULL OR
"ShipAddress" NOT LIKE 'a%' OR
"Freight" NOT BETWEEN 0 AND 1 OR
"OrderDate" BETWEEN '1996-7-4' AND '2096-7-4' OR NOT (
"CustomerID" <> 'VI''NET' AND
"Freight" NOT IN (0, 1) AND
"Freight" <> 1 + 2 AND
"EmployeeID" IS NULL AND
"CustomerID" NOT IN ('VINET')
)
)
ORDER BY "EmployeeID", "Freight" DESC
SELECT *
FROM "Customers"
WHERE
"CustomerID" = 'VINET'
SELECT "RegionDescription", "RegionID"
FROM "Region"