1 /**
2 * Copyright © Webd 2018
3 * License: MIT (https://github.com/DiamondMVC/Webd/blob/master/LICENSE)
4 * Author: Jacob Jensen (bausshf)
5 */
6 module webd.dal.webitems;
7 
8 import diamond.database;
9 
10 import webd.models.database;
11 
12 /**
13 * Gets an item from its id.
14 * Params:
15 *   id = The id of the item.
16 * Returns:
17 *   The item's db representation.
18 */
19 auto getItem(ulong id)
20 {
21   static const sql = "SELECT * FROM @table WHERE `id` = @id AND `disabled` = '0' AND `deleted` = '0' LIMIT 1";
22 
23   auto params = getParams();
24   params["id"] = id;
25 
26   return MySql.readSingle!WebdWebItem(sql, params);
27 }
28 
29 /**
30 * Gets a range of an item's values.
31 * Params:
32 *   itemId = The id of the item.
33 * Returns:
34 *   A range of the item values' db representation.
35 */
36 auto getItemValues(ulong itemId)
37 {
38   static const sql = "SELECT * FROM @table WHERE `itemId` = @itemId AND `parentValue` IS NULL AND `deleted` = '0'";
39 
40   auto params = getParams();
41   params["itemId"] = itemId;
42 
43   return MySql.readMany!WebdWebItemEntry(sql, params);
44 }
45 
46 /**
47 * Gets a range of an item's sub-values.
48 * Params:
49 *   itemId =      The id of the item.
50 *   parentValue = The id of the parent item value.
51 * Returns:
52 *   A range of the item values' db representation.
53 */
54 auto getItemValues(ulong itemId, ulong parentValue)
55 {
56   static const sql = "SELECT * FROM @table WHERE `itemId` = @itemId AND `parentValue` = @parentValue AND `deleted` = '0'";
57 
58   auto params = getParams();
59   params["itemId"] = itemId;
60   params["parentValue"] = parentValue;
61 
62   return MySql.readMany!WebdWebItemEntry(sql, params);
63 }