db

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Count added in v0.7.0

func Count(ctx context.Context, db *sql.DB, query string, args ...any) (int64, error)

Count is a helper function that wraps sql rows to scan into a single int. The query should return a single column with interger type such as count,sum etc. with a single row.

func Delete added in v0.7.0

func Delete(ctx context.Context, db *sql.DB, query string, args ...any) (int64, error)

Delete is a helper function that wraps sql exec to delete rows.

func Insert added in v0.7.0

func Insert(ctx context.Context, db *sql.DB, query string, args ...any) (int64, error)

Insert is a helper function that wraps sql exec to insert a row.

func InsertTx added in v0.7.0

func InsertTx(ctx context.Context, db *sql.DB, query string, args ...any) (int64, error)

InsertTx is a helper function that wraps sql exec to insert a row in a transaction.

func Row

func Row[T any](ctx context.Context, db *sql.DB, query string, args ...any) (T, error)

Row is a helper function that wraps sql rows to scan into a single struct. Row scans structs based on their db tag, and scan any fields not tagged with the db tag matched column name, So had better to tag all fields with db tag to avoid unexpected behavior.

func Rows

func Rows[T any](ctx context.Context, db *sql.DB, query string, args ...any) ([]T, error)

Rows is a helper function that wraps sql rows to scan into a slice. Rows scans structs based on their db tag, and scan any fields not tagged with the db tag matched column name, So had better to tag all fields with db tag to avoid unexpected behavior.

func Tx added in v0.7.1

func Tx(ctx context.Context, db *sql.DB, fn func(db *sql.DB, ctx context.Context) error) error

Tx is a helper function that wraps sql exec to run in a transaction.

func Update added in v0.7.0

func Update(ctx context.Context, db *sql.DB, query string, args ...any) (int64, error)

Update is a helper function that wraps sql exec to update rows.

func UpdateTx added in v0.7.0

func UpdateTx(ctx context.Context, db *sql.DB, query string, args ...any) (int64, error)

UpdateTx is a helper function that wraps sql exec to update rows in a transaction.

Types

This section is empty.

Jump to

Keyboard shortcuts

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