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

Tx

Overview ​

Tx wraps a sqlx transaction.

Part of the db package — Node.js analog: knex.

Tx is a type exported by gox. Methods on this type are documented separately.

Signature ​

go
type Tx struct {
	SQL *sqlx.Tx
}

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"

err := db.Transaction(ctx, func(tx *db.Tx) error {
    return tx.Insert(ctx, "users", row)
})

Example ​

go
import "github.com/sahilkhaire/gox/db"

err := db.Transaction(ctx, func(tx *db.Tx) error {
    return tx.Insert(ctx, "users", row)
})

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