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.websites; 7 8 import diamond.database; 9 10 import webd.models.database; 11 12 /** 13 * Gets website from its name. 14 * Params: 15 * name = The name of the website. 16 * Returns: 17 * The website's db representation. 18 */ 19 auto getWebsite(string name) 20 { 21 static const sql = "SELECT * FROM @table WHERE `name` = @name LIMIT 1"; 22 23 auto params = getParams(); 24 params["name"] = name; 25 26 return MySql.readSingle!WebdWebsite(sql, params); 27 } 28 29 /** 30 * Gets website from its id. 31 * Params: 32 * id = The id of the website. 33 * Returns: 34 * The website's db representation. 35 */ 36 auto getWebsite(ulong id) 37 { 38 static const sql = "SELECT * FROM @table WHERE `id` = @id LIMIT 1"; 39 40 auto params = getParams(); 41 params["id"] = id; 42 43 return MySql.readSingle!WebdWebsite(sql, params); 44 } 45 46 /** 47 * Gets a range of all websites. 48 * Returns: 49 * A range of all the websites' db representation. 50 */ 51 auto getAllWebsites() 52 { 53 static const sql = "SELECT * FROM @table WHERE ORDER BY `id` DESC"; 54 55 return MySql.readMany!WebdWebsite(sql, null); 56 }