MCPcopy
hub / github.com/jmoiron/sqlx / Connect

Function Connect

sqlx.go:640–651  ·  view source on GitHub ↗

Connect to a database and verify with a ping.

(driverName, dataSourceName string)

Source from the content-addressed store, hash-verified

638
639// Connect to a database and verify with a ping.
640func Connect(driverName, dataSourceName string) (*DB, error) {
641 db, err := Open(driverName, dataSourceName)
642 if err != nil {
643 return nil, err
644 }
645 err = db.Ping()
646 if err != nil {
647 db.Close()
648 return nil, err
649 }
650 return db, nil
651}
652
653// MustConnect connects to a database and panics on error.
654func MustConnect(driverName, dataSourceName string) *DB {

Callers 3

MustConnectFunction · 0.85
ConnectAllFunction · 0.85
TestDoNotPanicOnConnectFunction · 0.85

Calls 2

OpenFunction · 0.85
CloseMethod · 0.65

Tested by 2

ConnectAllFunction · 0.68
TestDoNotPanicOnConnectFunction · 0.68