@@ -71,13 +71,6 @@ void main(string[] args)
7171 writeln( "Text query result by name: ", answer[0]["current_time"].as!string );
7272 writeln( "Text query result by index: ", answer[0][3].as!string );
7373
74- // It is possible to read values of unknown type using BSON:
75- auto firstRow = answer[0];
76- foreach(cell; rangify(firstRow))
77- {
78- writeln("bson: ", cell.as!Bson);
79- }
80-
8174 // Binary arguments query with binary result:
8275 QueryParams p;
8376 p.sqlCommand = "SELECT "~
@@ -142,6 +135,20 @@ void main(string[] args)
142135 // Signal that the COPY is finished. Let Postgresql finalize the command
143136 // and return any errors with the data.
144137 conn.putCopyEnd();
138+
139+ import std.range: enumerate;
140+
141+ // rangify() template helps to iterate over Answer and Row:
142+ auto few_rows = conn.exec("SELECT v1, v2 FROM test_dpq2_copy");
143+ foreach(row_num, row; few_rows.rangify.enumerate)
144+ {
145+ foreach(col_num, cell; row.rangify.enumerate)
146+ writeln(
147+ "row_num: ", row_num,
148+ " col_num: ", col_num,
149+ " value: ", cell.as!Bson
150+ );
151+ }
145152}
146153```
147154
@@ -175,6 +182,14 @@ column: 'null_field', Variant: Nullable.null, Bson: null
175182column: 'array_field', Variant: [first, second, Nullable.null], Bson: ["first","second",null]
176183column: 'multi_array', Variant: [[1, 2, 3], [4, 5, 6]], Bson: [[1,2,3],[4,5,6]]
177184column: 'json_value', Variant: {"text_str":"text string","float_value":123.456}, Bson: {"text_str":"text string","float_value":123.456}
185+ row_num: 0 col_num: 0 value: "This, right here, is a test"
186+ row_num: 0 col_num: 1 value: "8"
187+ row_num: 1 col_num: 0 value: "Wow! it works"
188+ row_num: 1 col_num: 1 value: "13"
189+ row_num: 2 col_num: 0 value: "Horray!"
190+ row_num: 2 col_num: 1 value: "3456"
191+ row_num: 3 col_num: 0 value: "Super fast!"
192+ row_num: 3 col_num: 1 value: "325"
178193```
179194
180195## Using dynamic version of libpq
0 commit comments