@@ -52,6 +52,7 @@ import dpq2;
5252import std.getopt;
5353import std.stdio: writeln;
5454import std.typecons: Nullable;
55+ import std.variant: Variant;
5556import vibe.data.bson;
5657
5758void main(string[] args)
@@ -110,10 +111,15 @@ void main(string[] args)
110111 writeln( "5.1 Json: ", r[0]["json_value"].as!Json);
111112 writeln( "5.2 Bson: ", r[0]["json_value"].as!Bson);
112113
113- // It is possible to read values of unknown type using BSON:
114+ // It is possible to read values of unknown type
115+ // using std.variant.Variant or vibe.data.bson.Bson:
114116 for(auto column = 0; column < r.columnCount; column++)
115117 {
116- writeln("column name: '"~r.columnName(column)~"', bson: ", r[0][column].as!Bson);
118+ writeln(
119+ "column: '", r.columnName(column), "', ",
120+ "Variant: ", r[0][column].as!Variant, ", ",
121+ "Bson: ", r[0][column].as!Bson
122+ );
117123 }
118124
119125 // It is possible to upload CSV data ultra-fast:
@@ -142,11 +148,9 @@ void main(string[] args)
142148Compile and run:
143149```
144150Running ./dpq2_example --conninfo=user=postgres
145- 2018-12-09T10:08:07.862:package.d:__lambda1:19 DerelictPQ loading...
146- 2018-12-09T10:08:07.863:package.d:__lambda1:26 ...DerelictPQ loading finished
147- Text query result by name: 2018-12-09 10:08:07.868141
151+ Text query result by name: 2025-08-22 15:33:57.417629
148152Text query result by index: 456.78
149- bson: "2018-12-09 10:08:07.868141 "
153+ bson: "2025-08-22 15:33:57.417629 "
150154bson: "abc"
151155bson: "123"
152156bson: "456.78"
@@ -164,12 +168,13 @@ second line
1641684.2: [[1, 2, 3], [4, 5, 6]]
1651695.1 Json: {"text_str":"text string","float_value":123.456}
1661705.2 Bson: {"text_str":"text string","float_value":123.456}
167- column name: 'double_field', bson: -1234.56789012345
168- column name: 'text', bson: "first line\nsecond line"
169- column name: 'null_field', bson: null
170- column name: 'array_field', bson: ["first","second",null]
171- column name: 'multi_array', bson: [[1,2,3],[4,5,6]]
172- column name: 'json_value', bson: {"text_str":"text string","float_value":123.456}
171+ column: 'double_field', Variant: -1234.57, Bson: -1234.56789012345
172+ column: 'text', Variant: first line
173+ second line, Bson: "first line\nsecond line"
174+ column: 'null_field', Variant: Nullable.null, Bson: null
175+ column: 'array_field', Variant: [first, second, Nullable.null], Bson: ["first","second",null]
176+ column: 'multi_array', Variant: [[1, 2, 3], [4, 5, 6]], Bson: [[1,2,3],[4,5,6]]
177+ column: 'json_value', Variant: {"text_str":"text string","float_value":123.456}, Bson: {"text_str":"text string","float_value":123.456}
173178```
174179
175180## Using dynamic version of libpq
0 commit comments