sqlutil

package module
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2025 License: MIT Imports: 5 Imported by: 0

README

sqlutil

Go Reference test Go Report Card

Installation

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

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 an 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 is a helper function to execute a function in a transaction.

func TruncateAll

func TruncateAll(ctx context.Context, queryExecutor QueryExecutor) error

TruncateAll truncates all tables.

Types

type QueryExecutor

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

QueryExecutor is an interface to execute a query.

type TxStarter

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

TxStarter is an interface to start a transaction.

Jump to

Keyboard shortcuts

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