Skip to content

Commit 57f9919

Browse files
committed
Merge branch 'master' into example_impr8
2 parents acfb601 + 16bf3ce commit 57f9919

File tree

6 files changed

+42
-15
lines changed

6 files changed

+42
-15
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ jobs:
122122
dub run dpq2:integration_tests --build=cov -- --conninfo="$CONN_STRING"
123123
dub run dpq2:example --build=release -- --conninfo="$CONN_STRING"
124124
dub run doveralls
125+
dub test --f-version=NO_VARIANT
125126
shell: bash
126127
- name: Upload coverage data
127128
if: matrix.build == 'tests_and_cov'

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ _Please help us to make documentation better!_
3737
3838
* On Linux, you may install `libpq-dev` for dynamic linking e.g. `sudo apt-get install libpq-dev`
3939

40+
If version **NO_VARIANT** is supplied the function
41+
```
42+
T as(T : Variant, bool isNullablePayload = true)(in Value v);
43+
```
44+
is no longer available and std.variant.Variant is no longer used.
45+
This can speed up compilation significant.
46+
4047
## Example
4148
```D
4249
#!/usr/bin/env rdmd

src/dpq2/conv/time.d

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,8 @@ if( is( T == Interval ) )
342342
);
343343
}
344344

345-
package enum POSTGRES_EPOCH_DATE = Date(2000, 1, 1);
346-
package enum POSTGRES_EPOCH_JDATE = POSTGRES_EPOCH_DATE.julianDay;
345+
package immutable POSTGRES_EPOCH_DATE = Date(2000, 1, 1);
346+
package immutable POSTGRES_EPOCH_JDATE = Date(2000, 1, 1).julianDay;
347347
static assert(POSTGRES_EPOCH_JDATE == 2_451_545); // value from Postgres code
348348

349349
private:

src/dpq2/conv/to_d_types.d

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ import std.traits;
2121
import std.uuid;
2222
import std.datetime;
2323
import std.traits: isScalarType;
24+
version(NO_VARIANT) {
25+
private struct Variant {}
26+
} else {
2427
import std.variant: Variant;
28+
}
2529
import std.typecons : Nullable;
2630
import std.bitmanip: bigEndianToNative, BitArray;
2731
import std.conv: to;
@@ -52,6 +56,8 @@ private alias VF = ValueFormat;
5256
private alias AE = ValueConvException;
5357
private alias ET = ConvExceptionType;
5458

59+
version(NO_VARIANT) {
60+
} else {
5561
/**
5662
Returns cell value as a Variant type.
5763
*/
@@ -62,6 +68,20 @@ T as(T : Variant, bool isNullablePayload = true)(in Value v)
6268
return v.toVariant!isNullablePayload;
6369
}
6470

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+
6585
/**
6686
Returns cell value as a Nullable type using the underlying type conversion after null check.
6787
*/
@@ -100,19 +120,6 @@ if(is(T : const(char)[]) && !is(T == Nullable!R, R))
100120
return v.valueAsString;
101121
}
102122

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-
116123
/**
117124
Returns value as D type value from binary formatted field.
118125
Throws: AssertError if the db value is NULL.

src/dpq2/conv/to_variant.d

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
///
2+
23
module dpq2.conv.to_variant;
34

5+
version(NO_VARIANT) {
6+
/* Without std.variant dpq2 compiles significantly faster, and often the
7+
* ability explore unknown database schemas is not needed, removing the need
8+
* for a Variant type.
9+
*/
10+
} else {
11+
412
import dpq2.value;
513
import dpq2.oids: OidType;
614
import dpq2.result: ArrayProperties;
@@ -156,3 +164,4 @@ Variant toVariant(bool isNullablePayload = true)(in Value v) @safe
156164
);
157165
}
158166
}
167+
}

src/dpq2/value.d

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ struct Value
9595
return _data;
9696
}
9797

98+
version(NO_VARIANT) {
99+
} else {
98100
///
99101
string toString() const @trusted
100102
{
@@ -104,6 +106,7 @@ struct Value
104106

105107
return this.as!Variant.toString~"::"~oidType.to!string~"("~(format == ValueFormat.TEXT? "t" : "b")~")";
106108
}
109+
}
107110
}
108111

109112
@system unittest

0 commit comments

Comments
 (0)