sqlutil

package module
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2024 License: MIT Imports: 9 Imported by: 0

README

sqlutil

Go Reference test Go Report Card

Installation

go get github.com/m0t0k1ch1-go/sqlutil

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecFile added in v1.1.0

func ExecFile(ctx context.Context, executer QueryExecuter, path string) error

ExecFile executes a sql file.

func Transact

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

Transact is a helper function to execute a function in a transaction.

func TruncateAll added in v1.1.0

func TruncateAll(ctx context.Context, executer QueryExecuter) error

TruncateAll truncates all tables.

Types

type QueryExecuter added in v1.2.0

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

QueryExecuter 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.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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