@@ -21,7 +21,11 @@ import std.traits;
21
21
import std.uuid ;
22
22
import std.datetime ;
23
23
import std.traits : isScalarType;
24
+ version (NO_VARIANT) {
25
+ private struct Variant {}
26
+ } else {
24
27
import std.variant : Variant ;
28
+ }
25
29
import std.typecons : Nullable;
26
30
import std.bitmanip : bigEndianToNative, BitArray ;
27
31
import std.conv : to;
@@ -52,6 +56,8 @@ private alias VF = ValueFormat;
52
56
private alias AE = ValueConvException;
53
57
private alias ET = ConvExceptionType;
54
58
59
+ version (NO_VARIANT) {
60
+ } else {
55
61
/**
56
62
Returns cell value as a Variant type.
57
63
*/
@@ -62,6 +68,20 @@ T as(T : Variant, bool isNullablePayload = true)(in Value v)
62
68
return v.toVariant! isNullablePayload;
63
69
}
64
70
71
+ @system unittest
72
+ {
73
+ import core.exception : AssertError ;
74
+
75
+ auto v = Value(ValueFormat.BINARY , OidType.Text );
76
+
77
+ assert (v.isNull);
78
+ assertThrown! AssertError (v.as! string == " " );
79
+ assert (v.as! (Nullable! string ).isNull == true );
80
+
81
+ assert (v.as! Variant .get ! (Nullable! string ).isNull == true );
82
+ }
83
+ }
84
+
65
85
/**
66
86
Returns cell value as a Nullable type using the underlying type conversion after null check.
67
87
*/
@@ -100,19 +120,6 @@ if(is(T : const(char)[]) && !is(T == Nullable!R, R))
100
120
return v.valueAsString;
101
121
}
102
122
103
- @system unittest
104
- {
105
- import core.exception : AssertError ;
106
-
107
- auto v = Value(ValueFormat.BINARY , OidType.Text );
108
-
109
- assert (v.isNull);
110
- assertThrown! AssertError (v.as! string == " " );
111
- assert (v.as! (Nullable! string ).isNull == true );
112
-
113
- assert (v.as! Variant .get ! (Nullable! string ).isNull == true );
114
- }
115
-
116
123
/**
117
124
Returns value as D type value from binary formatted field.
118
125
Throws: AssertError if the db value is NULL.
0 commit comments