DB.MustOpen
Overview
MustOpen connects or panics.
Part of the db package — Node.js analog: knex.
Method on DB — call it on a value of that type after constructing or receiving one from a constructor.
Signature
go
func MustOpen(driver, dsn string) *DBCompare: Node.js · Standard Go · gox
js
// Typical knex pattern in Node.jsgo
db, err := sqlx.Connect("postgres", dsn)
db.GetContext(ctx, &row, query, args...)go
import "github.com/sahilkhaire/gox/db"
db := db.MustOpen(ctx, "postgres", dsn)Example
go
import "github.com/sahilkhaire/gox/db"
db := db.MustOpen(ctx, "postgres", dsn)Tips
Pass context.Context as the first argument so cancellation and deadlines propagate correctly.
Standard library alternative
Use the standard library directly:
go
db, err := sqlx.Connect("postgres", dsn)
db.GetContext(ctx, &row, query, args...)