forked from alixaxel/ArrestDB
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdatamodel.txt
147 lines (144 loc) · 3.47 KB
/
datamodel.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
input
=====
{
"order":{
"columns": [
"OrderDate",
"IdOrder",
"ShipName",
{"customer":{
"columns":[
"CompanyName",
"ContactName",
"ContactName"
],
"type": "SELECT",
"from": "Customer"
"as": "a",
"where": "a.IdCustomer=b.IdCustomer",
"arity": "1"
}},
{"lines":{
"columns":[
"UnitPrice",
"Quantity",
{"product":{
"columns":[
"ProductName",
"QuantityPerUnit"
],
"type": "SELECT",
"from": "Product"
"as": "d",
"where": "d.IdProduct = c.IdProduct",
"arity":"1"
}}
],
"type": "SELECT",
"from": "OrderDetail
"as": "c",
"where": "c.IdOrder=b.IdOrder",
"arity": "n"
}}
],
"type": "SELECT",
"from": "Order"
"as":"b",
"where": "IdOrder=10248",
"arity": "1"
}
}
generated SQL query
===================
SELECT '{' ||
(
SELECT '"order":{"OrderDate":"'||"OrderDate" || '","IdOrder":"' || "IdOrder" || '","ShipName":"' || "ShipName" || '","customer":' ||
(
SELECT '{ "CompanyName":"' || CompanyName || '","ContactName":"' || ContactName || '"}' FROM Customer AS a WHERE a.IdCustomer=b.IdCustomer
)
|| ',"lines":[' ||
(
SELECT GROUP_CONCAT("record",',') ||']' FROM(
SELECT '{"UnitPrice":'||UnitPrice || ',"Quantity":' || Quantity||',"product":{' || (
SELECT '"ProductName":"' || "ProductName" || '"' || ',"QuantityPerUnit":"' || "QuantityPerUnit" || '"'
FROM Product as d WHERE d.IdProduct = c.IdProduct
)||'}}' AS record
FROM OrderDetail AS c WHERE c.IdOrder=b.IdOrder
)
)
) || '} }'AS invoice
FROM "Order" AS b
WHERE IdOrder=10248
output
======
{
"order":{
"OrderDate":"1996-07-04",
"IdOrder":"10248",
"ShipName":"Vins et alcools Chevalier"
"customer":{
"CompanyName":"Vins et alcools Chevalier",
"ContactName":"Paul Henriot"
},
"lines":[
{
"UnitPrice":14,
"Quantity":12,
"product":{
"ProductName":"Queso Cabrales",
"QuantityPerUnit":"1 kg pkg."
}
},
{
"UnitPrice":9.8,
"Quantity":10,
"product":{
"ProductName":"Singaporean Hokkien Fried Mee",
"QuantityPerUnit":"32 - 1 kg pkgs."
}
},
{
"UnitPrice":34.8,
"Quantity":5,
"product":{
"ProductName":"Mozzarella di Giovanni",
"QuantityPerUnit":"24 - 200 g pkgs."
}
}
]
}
}
Original idea
=============
{"invoice":
[
"Order":{
"table":"Order",
"columns":["OrderDate","ShipDate","ShipName","ShipAddress","ShipCity","Country"],
"where":"Order.IdOrder={{OrderNumber}}",
"id":"IdOrder"
},
"Customer":{
"table":"Customer",
"columns":["CompanyName","ContactName","Address","City","PostalCode","Country","Phone"],
"where":"Order.IdCustomer=Customer.IdCustomer",
"id":"IdCustomer"
},
"OrderDetail":{
"table":"OrderDetail",
"columns":[
"UnitPrice",
"Quantity",
"Discount",
{
"Product":{
"table":"Product",
"columns":["ProductName","QuantityPerUnit"],
"where":"Product.IdProduct=OrderDetail.IdProduct"},
"id":"idProduct"
}
],
"where":"Order.IdOrder=OrderDetail.IdOrder","id":"idOrderDetail"
}
]
}