txengine

package
v2.6.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 13, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunTransaction added in v2.5.1

func RunTransaction(ctx context.Context, dbName string, fn func(ctx context.Context, sqlTx *sql.Tx) error) (err error)

RunTransaction runs a transaction

func RunTransactionWithLock added in v2.5.1

func RunTransactionWithLock(ctx context.Context, dbName string, lock string, durationInSec int, fn func(ctx context.Context, sqlTx *sql.Tx) error) (err error)

RunTransactionWithLock runs a transaction with a lock for durationInSec seconds

Types

type Tx

type Tx sql.Tx

func WithTx

func WithTx(tx *sql.Tx) *Tx

WithTx converts *sql.Tx to *txengine.Tx.

With *txengine.Tx, you have access to Exec and QueryInt

func (*Tx) Exec

func (o *Tx) Exec(ctx context.Context, query string, params ...any) (sql.Result, error)

Exec given query with given db info & params

func (*Tx) QueryInt

func (o *Tx) QueryInt(ctx context.Context, query string, params ...any) (result int, err error)

QueryInt single int result by query, handy for count(*) querys

type TypedTx

type TypedTx[T any] sql.Tx

func WithTypedTx

func WithTypedTx[T any](tx *sql.Tx) *TypedTx[T]

WithTypedTx converts *sql.Tx to *txengine.TypedTx[T].

With *txengine.TypedTx[T], you have access to FindOne[T], Find[T] and Query[T]

func (*TypedTx[T]) Find

func (o *TypedTx[T]) Find(ctx context.Context, tableName string, whereSQL string, params ...any) ([]*T, error)

Find returns rows from given table type with where query

func (*TypedTx[T]) FindOne

func (o *TypedTx[T]) FindOne(ctx context.Context, tableName string, whereSQL string, params ...any) (*T, error)

FindOne returns a row from given table type with where query. If no rows found, *T will be nil. No error will be returned.

func (*TypedTx[T]) Query

func (o *TypedTx[T]) Query(ctx context.Context, query string, params ...any) (result []*T, err error)

Query rows from given table type with where query & params

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL