sqlutil

package module
v3.4.2 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2025 License: MIT Imports: 6 Imported by: 0

README

sqlutil - Utilities for database/sql

Go Reference test codecov Go Report Card

Installation

go get github.com/m0t0k1ch1-go/sqlutil/v3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecFile

func ExecFile(ctx context.Context, queryExecutor QueryExecutor, path string) error

ExecFile executes a SQL file. When using github.com/go-sql-driver/mysql, ensure `multiStatements=true`.

func Transact

func Transact(ctx context.Context, txStarter TxStarter, f func(context.Context, *sql.Tx) error) (err error)

Transact runs the given function within a transaction.

Types

type QueryExecutor

type QueryExecutor interface {
	ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
}

QueryExecutor executes a query.

type TxStarter

type TxStarter interface {
	BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)
}

TxStarter starts a new transaction.

Jump to

Keyboard shortcuts

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