import ( "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/table" ) // Define table schema col1 := table.Column{Name: "id", FieldType: types.NewFieldType(mysql.TypeLonglong)} col2 := table.Column{Name: "name", FieldType: types.NewFieldType(mysql.TypeVarchar)} // Create table instance tbl := table.PhysicalTable{ TableName: "test_table", Columns: []*table.Column{&col1, &col2}, Indices: nil, Partition: nil, }
// Open TiDB session session, err := session.CreateSession(store) if err != nil { panic(err) } defer session.Close() // Get table instance by name tbl, err := session.GetTable(tableName) if err != nil { panic(err) } // Select data from table rows, err := tbl.RowIter(ctx, kv.Range{...}) if err != nil { panic(err) } // Iterate over rows for { data, err := rows.NextRow() if err != nil { if err == io.EOF { break } panic(err) } // Process row data }The examples demonstrate how to define a schema for a new table and how to get a table instance from a TiDB session and select data from it using the RowIter method. The package library is a TiDB storage engine implementation that provides a physical table implementation on top of a distributed key-value storage system.