1 /**
2 * Copyright © DiamondMVC 2019
3 * License: MIT (https://github.com/DiamondMVC/Diamond/blob/master/LICENSE)
4 * Author: Jacob Jensen (bausshf)
5 */
6 module diamond.data.mapping.attributes;
7 
8 /// Attribute for excluding fields.
9 struct DbNoMap { }
10 
11 /// Attribute for marking fields as nullable.
12 struct DbNull { }
13 
14 /// Attribute for marking fields as db-enums.
15 struct DbEnum { }
16 
17 /// Attribute for ids.
18 struct DbId { }
19 
20 /// Attribute for timestamps.
21 struct DbTimestamp { }
22 
23 // Attribute to mark data as personal. Use this to easily integrate with GDPR.
24 struct DbPersonal { }
25 
26 /// Attribute for relationships.
27 struct DbRelationship
28 {
29   /// A custom sql to retrieve the relationship data.
30   string sql;
31   /// An associative array of members to match when generating the sql to retrieve the relationship data.
32   string[string] members;
33 
34   /// Disables the default ctor for the struct.
35   @disable this();
36 
37   /**
38   * Creates a db relationship with a custom sql query.
39   * Params:
40   *   sql = The sql query.
41   */
42   this(string sql)
43   {
44     this.sql = sql;
45     this.members = null;
46   }
47 
48   /**
49   * Creates a db relationship with an array of members to use for the query generation.
50   * Params:
51   *   members = The members.
52   */
53   this(string[string] members)
54   {
55     this.sql = null;
56     this.members = members;
57   }
58 }
59 
60 /// Attribute for custom data-type handling.
61 struct DbProxy
62 {
63   /// The name of the custom read handler.
64   string readHandler;
65   /// The name of the custom write handler.
66   string writeHandler;
67 }