|
| 1 | +package ydb_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "log" |
| 6 | + "path" |
| 7 | + |
| 8 | + "github.com/ydb-platform/ydb-go-sdk/v3" |
| 9 | + "github.com/ydb-platform/ydb-go-sdk/v3/table" |
| 10 | + "github.com/ydb-platform/ydb-go-sdk/v3/table/options" |
| 11 | + "github.com/ydb-platform/ydb-go-sdk/v3/table/types" |
| 12 | +) |
| 13 | + |
| 14 | +func Example_tableCreateTable() { |
| 15 | + ctx := context.Background() |
| 16 | + db, err := ydb.New(ctx, |
| 17 | + ydb.WithConnectionString("grpcs://localhost:2135/?database=/local"), |
| 18 | + ydb.WithAnonymousCredentials(), |
| 19 | + ) |
| 20 | + if err != nil { |
| 21 | + log.Fatal(err) |
| 22 | + } |
| 23 | + defer func() { |
| 24 | + _ = db.Close(ctx) |
| 25 | + }() |
| 26 | + err = db.Table().Do( |
| 27 | + ctx, |
| 28 | + func(ctx context.Context, s table.Session) (err error) { |
| 29 | + return s.CreateTable(ctx, path.Join(db.Name(), "series"), |
| 30 | + options.WithColumn("series_id", types.Optional(types.TypeUint64)), |
| 31 | + options.WithColumn("title", types.Optional(types.TypeUTF8)), |
| 32 | + options.WithColumn("series_info", types.Optional(types.TypeUTF8)), |
| 33 | + options.WithColumn("release_date", types.Optional(types.TypeDate)), |
| 34 | + options.WithColumn("comment", types.Optional(types.TypeUTF8)), |
| 35 | + options.WithPrimaryKeyColumn("series_id"), |
| 36 | + ) |
| 37 | + }, |
| 38 | + ) |
| 39 | + if err != nil { |
| 40 | + log.Printf("unexpected error: %v", err) |
| 41 | + } |
| 42 | +} |
0 commit comments