MCPcopy Create free account
hub / github.com/bytebase/bytebase / createTiDBDriver

Function createTiDBDriver

backend/plugin/schema/tidb/testutil_test.go:14–39  ·  view source on GitHub ↗

createTiDBDriver creates and opens a TiDB driver connection

(ctx context.Context, host, port, database string)

Source from the content-addressed store, hash-verified

12
13// createTiDBDriver creates and opens a TiDB driver connection
14func 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}

Calls 2

OpenMethod · 0.95
ErrorfMethod · 0.80

Tested by

no test coverage detected