Skip to content
Node: knexgithub.com/sahilkhaire/gox/db

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) *DB

Compare: Node.js · Standard Go · gox

js
// Typical knex pattern in Node.js
go
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...)

Back to db package overview

MIT Licensed · Built for Node.js developers moving to Go