forked from NetCoreWebApps/rockwind
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproducts.html
More file actions
36 lines (29 loc) · 1.13 KB
/
products.html
File metadata and controls
36 lines (29 loc) · 1.13 KB
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
```code|q
'id,category,supplier,nameContains' |> importRequestParams
var limit = qs.limit ?? 100
{{ `SELECT p.Id,
ProductName,
c.CategoryName Category,
s.CompanyName Supplier,
QuantityPerUnit,
${sqlCurrency("UnitPrice")} UnitPrice,
UnitsInStock, UnitsOnOrder, ReorderLevel
FROM Product p
INNER JOIN Category c on p.CategoryId = c.Id
INNER JOIN Supplier s on p.SupplierId = s.Id
WHERE Discontinued = 0`
|> to => sql }}
#if !PathArgs.isEmpty()
`${sql} and p.Id = @id` |> dbSingle({ id: PathArgs[0] }) |> return
/if
var filters = []
'p.Id = @id' |> ifExists(id) |> addTo => filters
'c.CategoryName = @category' |> ifExists(category) |> addTo => filters
's.CompanyName = @supplier' |> ifExists(supplier) |> addTo => filters
'ProductName LIKE @name' |> ifExists(nameContains) |> addTo => filters
#if !filters.isEmpty()
sql = `${sql} AND ${filters.join(' AND ')}`
/if
sql = `${sql} ORDER BY CompanyName ${sqlLimit(limit)}`
sql |> dbSelect({ id, category, supplier, name: `%${nameContains}%` }) |> return
```