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: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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
⌂ 换网址