1 module shark.entity;
2 
3 static import std.datetime;
4 
5 /**
6  * Base interface that every entity should implement.
7  */
8 interface Entity {
9 
10 	/**
11 	 * Gets the entity's table name.
12 	 */
13 	public @property string tableName();
14 
15 }
16 
17 struct Nullable(T, ubyte id=0) if(!is(T : Object)) {
18 
19 	private bool _isNull = true;
20 	private T _value;
21 
22 	this(E...)(E args) {
23 		_isNull = false;
24 		_value = T(args);
25 	}
26 	
27 	public @property bool isNull() {
28 		return _isNull;
29 	}
30 
31 	public void nullify() {
32 		_isNull = true;
33 	}
34 	
35 	public @property T value() {
36 		return _value;
37 	}
38 	
39 	public @property T value(T value) {
40 		_isNull = false;
41 		return (_value = value);
42 	}
43 
44 	public @property T value(Object object) {
45 		assert(object is null);
46 		nullify();
47 		return _value;
48 	}
49 
50 	string toString() {
51 		import std.conv : to;
52 		return isNull ? "null" : value.to!string;
53 	}
54 	
55 	alias value this;
56 
57 }
58 
59 alias Bool = Nullable!bool;
60 
61 alias Byte = Nullable!byte;
62 
63 alias Short = Nullable!short;
64 
65 alias Integer = Nullable!int;
66 
67 alias Long = Nullable!long;
68 
69 alias Float = Nullable!float;
70 
71 alias Double = Nullable!double;
72 
73 alias Char = Nullable!char;
74 
75 alias String = Nullable!(string, 0);
76 
77 alias Binary = Nullable!(ubyte[], 0);
78 
79 alias Clob = Nullable!(string, 1);
80 
81 alias Blob = Nullable!(ubyte[], 1);
82 
83 alias Date = Nullable!(std.datetime.Date);
84 
85 alias DateTime = Nullable!(std.datetime.DateTime);
86 
87 alias Time = Nullable!(std.datetime.TimeOfDay);
88 
89 struct Name { string name; }
90 
91 enum PrimaryKey;
92 
93 enum AutoIncrement;
94 
95 enum NotNull;
96 
97 enum Unique;
98 
99 struct Length { size_t length; }