createTiDBDriver creates and opens a TiDB driver connection
(ctx context.Context, host, port, database string)
| 12 | |
| 13 | // createTiDBDriver creates and opens a TiDB driver connection |
| 14 | func createTiDBDriver(ctx context.Context, host, port, database string) (*tidbdb.Driver, error) { |
| 15 | driver := &tidbdb.Driver{} |
| 16 | config := db.ConnectionConfig{ |
| 17 | DataSource: &storepb.DataSource{ |
| 18 | Type: storepb.DataSourceType_ADMIN, |
| 19 | Username: "root", |
| 20 | Host: host, |
| 21 | Port: port, |
| 22 | Database: database, |
| 23 | }, |
| 24 | Password: "", |
| 25 | ConnectionContext: db.ConnectionContext{ |
| 26 | EngineVersion: "8.5.0", |
| 27 | DatabaseName: database, |
| 28 | }, |
| 29 | } |
| 30 | d, err := driver.Open(ctx, storepb.Engine_TIDB, config) |
| 31 | if err != nil { |
| 32 | return nil, err |
| 33 | } |
| 34 | tidbDriver, ok := d.(*tidbdb.Driver) |
| 35 | if !ok { |
| 36 | return nil, errors.Errorf("failed to cast to TiDB driver") |
| 37 | } |
| 38 | return tidbDriver, nil |
| 39 | } |
no test coverage detected