Skip to content

Commit

Permalink
MustOpen, just like Open but panics on error
Browse files Browse the repository at this point in the history
  • Loading branch information
troyk committed Oct 23, 2014
1 parent 3e4894d commit 55e83b3
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions sqlx.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,15 @@ func Open(driverName, dataSourceName string) (*DB, error) {
return &DB{DB: db, driverName: driverName, Mapper: mapper()}, err
}

// MustOpen is the same as sql.Open, but returns an *sqlx.DB instead and panics on error.
func MustOpen(driverName, dataSourceName string) *DB {
db, err := Open(driverName, dataSourceName)
if err != nil {
panic(err)
}
return db
}

// MapperFunc sets a new mapper for this db using the default sqlx struct tag
// and the provided mapper function.
func (db *DB) MapperFunc(mf func(string) string) {
Expand Down

0 comments on commit 55e83b3

Please sign in to comment.