@@ -305,3 +305,70 @@ func ExampleConnect() {
305
305
// Output:
306
306
// Connection is ready
307
307
}
308
+
309
+ // Example demonstrates how to retrieve information with space schema.
310
+ func ExampleSchema () {
311
+ conn := example_connect ()
312
+ defer conn .Close ()
313
+
314
+ schema := conn .Schema
315
+ if schema .SpacesById == nil {
316
+ fmt .Println ("schema.SpacesById is nil" )
317
+ }
318
+ if schema .Spaces == nil {
319
+ fmt .Println ("schema.Spaces is nil" )
320
+ }
321
+
322
+ space1 := schema .Spaces ["test" ]
323
+ space2 := schema .SpacesById [514 ]
324
+ fmt .Printf ("Space 1 ID %d %s\n " , space1 .Id , space1 .Name )
325
+ fmt .Printf ("Space 2 ID %d %s\n " , space2 .Id , space2 .Name )
326
+ // Output:
327
+ // Space 1 ID 512 test
328
+ // Space 2 ID 514 schematest
329
+ }
330
+
331
+ // Example demonstrates how to retrieve information with space schema.
332
+ func ExampleSpace () {
333
+ conn := example_connect ()
334
+ defer conn .Close ()
335
+
336
+ // Save Schema to a local variable to avoid races
337
+ schema := conn .Schema
338
+ if schema .SpacesById == nil {
339
+ fmt .Println ("schema.SpacesById is nil" )
340
+ }
341
+ if schema .Spaces == nil {
342
+ fmt .Println ("schema.Spaces is nil" )
343
+ }
344
+
345
+ // Access Space objects by name or ID
346
+ space1 := schema .Spaces ["test" ]
347
+ space2 := schema .SpacesById [514 ] // It's a map
348
+ fmt .Printf ("Space 1 ID %d %s %s\n " , space1 .Id , space1 .Name , space1 .Engine )
349
+ fmt .Printf ("Space 1 ID %d %t\n " , space1 .FieldsCount , space1 .Temporary )
350
+
351
+ // Access index information by name or ID
352
+ index1 := space1 .Indexes ["primary" ]
353
+ index2 := space2 .IndexesById [3 ] // It's a map
354
+ fmt .Printf ("Index %d %s\n " , index1 .Id , index1 .Name )
355
+
356
+ // Access index fields information by index
357
+ indexField1 := index1 .Fields [0 ] // It's a slice
358
+ indexField2 := index2 .Fields [1 ] // It's a slice
359
+ fmt .Println (indexField1 , indexField2 )
360
+
361
+ // Access space fields information by name or id (index)
362
+ spaceField1 := space2 .Fields ["name0" ]
363
+ spaceField2 := space2 .FieldsById [3 ]
364
+ fmt .Printf ("SpaceField 1 %s %s\n " , spaceField1 .Name , spaceField1 .Type )
365
+ fmt .Printf ("SpaceField 2 %s %s\n " , spaceField2 .Name , spaceField2 .Type )
366
+
367
+ // Output:
368
+ // Space 1 ID 512 test memtx
369
+ // Space 1 ID 0 false
370
+ // Index 0 primary
371
+ // &{0 unsigned} &{2 string}
372
+ // SpaceField 1 name0 unsigned
373
+ // SpaceField 2 name3 unsigned
374
+ }
0 commit comments