@@ -53,12 +53,19 @@ public class AllTypesRecord
5353 public IList < string > ? FloatVector { get ; set ; }
5454 }
5555
56- public class DatabaseWorkloadsMore
56+ public class DatabaseWorkloadsTypes
5757 {
5858
59- public static async Task ProvisionAllTypes ( NpgsqlConnection conn )
59+ public DatabaseWorkloadsTypes ( NpgsqlConnection conn )
6060 {
61- Console . WriteLine ( "Running ProvisionAllTypes" ) ;
61+ this . conn = conn ;
62+ }
63+
64+ private NpgsqlConnection conn ;
65+
66+ public async Task CreateTable ( )
67+ {
68+ Console . WriteLine ( "Running CreateTable" ) ;
6269
6370 // Submit DDL, create database schema.
6471 await using ( var cmd = new NpgsqlCommand ( "DROP TABLE IF EXISTS testdrive.example" , conn ) )
@@ -86,6 +93,7 @@ char CHARACTER(5),
8693 -- Container types
8794 "array" ARRAY(STRING),
8895 "object" OBJECT(DYNAMIC),
96+ "array_object" ARRAY(OBJECT(DYNAMIC)),
8997 -- Geospatial types
9098 geopoint GEO_POINT,
9199 geoshape GEO_SHAPE,
@@ -96,6 +104,11 @@ float_vector FLOAT_VECTOR(3)
96104 {
97105 cmd . ExecuteNonQuery ( ) ;
98106 }
107+ }
108+
109+ public async Task InsertRecord ( )
110+ {
111+ Console . WriteLine ( "Running InsertRecord" ) ;
99112
100113 // Insert single data point.
101114 await using ( var cmd = new NpgsqlCommand ( """
@@ -162,20 +175,26 @@ INSERT INTO testdrive.example (
162175 cmd . ExecuteNonQuery ( ) ;
163176 }
164177
178+ await RefreshTable ( ) ;
179+
180+ }
181+
182+ public async Task RefreshTable ( )
183+ {
165184 // Flush data.
166185 await using ( var cmd = new NpgsqlCommand ( "REFRESH TABLE testdrive.example" , conn ) )
167186 {
168187 cmd . ExecuteNonQuery ( ) ;
169188 }
170-
171189 }
172190
173- public static async Task < DataTable > AllTypesNativeExample ( NpgsqlConnection conn )
191+ public async Task < DataTable > AllTypesNativeExample ( )
174192 {
175193 Console . WriteLine ( "Running AllTypesNativeExample" ) ;
176194
177195 // Provision data.
178- await ProvisionAllTypes ( conn ) ;
196+ await CreateTable ( ) ;
197+ await InsertRecord ( ) ;
179198
180199 // Query back data.
181200 await using ( var cmd = new NpgsqlCommand ( "SELECT * FROM testdrive.example" , conn ) )
@@ -190,18 +209,12 @@ public static async Task<DataTable> AllTypesNativeExample(NpgsqlConnection conn)
190209
191210 }
192211
193- public static async Task < JsonDocument > ObjectJsonDocumentExample ( NpgsqlConnection conn )
212+ public async Task < JsonDocument > ObjectJsonDocumentExample ( )
194213 {
195214 Console . WriteLine ( "Running ObjectJsonDocumentExample" ) ;
196215
197216 // Provision data.
198- await ProvisionAllTypes ( conn ) ;
199-
200- // This test uses the central DDL, but a blank slate to focus on the test case at hand.
201- await using ( var cmd = new NpgsqlCommand ( "DELETE FROM testdrive.example" , conn ) )
202- {
203- cmd . ExecuteNonQuery ( ) ;
204- }
217+ await CreateTable ( ) ;
205218
206219 await using ( var cmd = new NpgsqlCommand ( """
207220 INSERT INTO testdrive.example (
@@ -216,10 +229,7 @@ INSERT INTO testdrive.example (
216229 }
217230
218231 // Flush data.
219- await using ( var cmd = new NpgsqlCommand ( "REFRESH TABLE testdrive.example" , conn ) )
220- {
221- cmd . ExecuteNonQuery ( ) ;
222- }
232+ await RefreshTable ( ) ;
223233
224234 // Query back data.
225235 await using ( var cmd = new NpgsqlCommand ( "SELECT * FROM testdrive.example" , conn ) )
@@ -232,12 +242,13 @@ INSERT INTO testdrive.example (
232242 }
233243 }
234244
235- public static async Task < List < JsonDocument > > ArrayJsonDocumentExample ( NpgsqlConnection conn )
245+ public async Task < List < JsonDocument > > ArrayJsonDocumentExample ( )
236246 {
237247 Console . WriteLine ( "Running ArrayJsonDocumentExample" ) ;
238248
239249 // Provision data.
240- await ProvisionAllTypes ( conn ) ;
250+ await CreateTable ( ) ;
251+ await InsertRecord ( ) ;
241252
242253 // Query back data.
243254 await using ( var cmd = new NpgsqlCommand ( "SELECT * FROM testdrive.example" , conn ) )
@@ -253,34 +264,18 @@ public static async Task<List<JsonDocument>> ArrayJsonDocumentExample(NpgsqlConn
253264 }
254265 }
255266
256- public static async Task ProvisionPoco ( NpgsqlConnection conn )
267+ public async Task InsertPoco ( )
257268 {
258269 /***
259270 * Verify Npgsql POCO mapping with CrateDB.
260271 * https://www.npgsql.org/doc/types/json.html#poco-mapping
261272 */
262- Console . WriteLine ( "Running ProvisionPoco" ) ;
263-
264- // Submit DDL, create database schema.
265- await using ( var cmd = new NpgsqlCommand ( "DROP TABLE IF EXISTS testdrive.poco" , conn ) )
266- {
267- cmd . ExecuteNonQuery ( ) ;
268- }
269-
270- await using ( var cmd = new NpgsqlCommand ( """
271- CREATE TABLE testdrive.poco (
272- "array" ARRAY(OBJECT(DYNAMIC)),
273- "object" OBJECT(DYNAMIC)
274- );
275- """ , conn ) )
276- {
277- cmd . ExecuteNonQuery ( ) ;
278- }
273+ Console . WriteLine ( "Running InsertPoco" ) ;
279274
280275 // Insert single data point.
281276 await using ( var cmd = new NpgsqlCommand ( """
282- INSERT INTO testdrive.poco (
283- "array ",
277+ INSERT INTO testdrive.example (
278+ "array_object ",
284279 "object"
285280 ) VALUES (
286281 @array,
@@ -298,22 +293,20 @@ INSERT INTO testdrive.poco (
298293 }
299294
300295 // Flush data.
301- await using ( var cmd = new NpgsqlCommand ( "REFRESH TABLE testdrive.poco" , conn ) )
302- {
303- cmd . ExecuteNonQuery ( ) ;
304- }
296+ await RefreshTable ( ) ;
305297
306298 }
307299
308- public static async Task < BasicPoco > ObjectPocoExample ( NpgsqlConnection conn )
300+ public async Task < BasicPoco > ObjectPocoExample ( )
309301 {
310302 Console . WriteLine ( "Running ObjectPocoExample" ) ;
311303
312304 // Provision data.
313- await ProvisionPoco ( conn ) ;
305+ await CreateTable ( ) ;
306+ await InsertPoco ( ) ;
314307
315308 // Query back data.
316- await using ( var cmd = new NpgsqlCommand ( "SELECT * FROM testdrive.poco " , conn ) )
309+ await using ( var cmd = new NpgsqlCommand ( "SELECT * FROM testdrive.example " , conn ) )
317310 await using ( var reader = cmd . ExecuteReader ( ) )
318311 {
319312 reader . Read ( ) ;
@@ -323,19 +316,20 @@ public static async Task<BasicPoco> ObjectPocoExample(NpgsqlConnection conn)
323316 }
324317 }
325318
326- public static async Task < List < BasicPoco > > ArrayPocoExample ( NpgsqlConnection conn )
319+ public async Task < List < BasicPoco > > ArrayPocoExample ( )
327320 {
328321 Console . WriteLine ( "Running ArrayPocoExample" ) ;
329322
330323 // Provision data.
331- await ProvisionPoco ( conn ) ;
324+ await CreateTable ( ) ;
325+ await InsertPoco ( ) ;
332326
333327 // Query back data.
334- await using ( var cmd = new NpgsqlCommand ( "SELECT * FROM testdrive.poco " , conn ) )
328+ await using ( var cmd = new NpgsqlCommand ( "SELECT * FROM testdrive.example " , conn ) )
335329 await using ( var reader = cmd . ExecuteReader ( ) )
336330 {
337331 reader . Read ( ) ;
338- var obj = reader . GetFieldValue < List < BasicPoco > > ( "array " ) ;
332+ var obj = reader . GetFieldValue < List < BasicPoco > > ( "array_object " ) ;
339333 Console . WriteLine ( obj [ 0 ] ) ;
340334 Console . WriteLine ( obj [ 1 ] ) ;
341335 return obj ;
0 commit comments