db

package
v1.39.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 22 Imported by: 1 module, 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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecuteQuery

func ExecuteQuery(data map[string]any, opts ...Option) (map[string]any, error)

func Spec added in v1.30.0

func Spec() actionspec.Spec

Spec declares the db action. It keeps to every kind of guard: it runs only a statement that reads under read-only, and connects only to a host the guard allows. It cannot run without dsn and query.

Types

type Action

type Action struct {
	// contains filtered or unexported fields
}

func (*Action) Run

func (a *Action) Run(with map[string]any) (map[string]any, error)

func (*Action) RunStep

func (a *Action) RunStep(call actionrpc.Call) (map[string]any, map[string]any, error)

RunStep runs the query under the guard of the run, which may allow only reading, or only some hosts.

type Callback

type Callback struct {
	// contains filtered or unexported fields
}

type Option

type Option func(*Callback)

func WithAfter

func WithAfter(f func(result *Result)) Option

func WithBefore

func WithBefore(f func(query string, params []any)) Option

func WithGuard

func WithGuard(guard actionrpc.Guard) Option

WithGuard runs the query under the guard of the run.

type Req

type Req struct {
	Driver  string `map:"driver"`
	DSN     string `map:"dsn"`
	Query   string `map:"query"`
	Params  []any  `map:"params"`
	Timeout string `map:"timeout"`
	// contains filtered or unexported fields
}

func ParseRequest

func ParseRequest(with map[string]any) (*Req, string, time.Duration, error)

func (*Req) Execute

func (r *Req) Execute(driverDSN string, timeout time.Duration) (res map[string]any, err error)

type Res

type Res struct {
	Code         int    `map:"code"`
	RowsAffected int64  `map:"rows_affected"`
	Rows         []any  `map:"rows"`
	Error        string `map:"error"`
}

type Result

type Result struct {
	Req    Req           `map:"req"`
	Res    Res           `map:"res"`
	RT     time.Duration `map:"rt"`
	Status int           `map:"status"`
}

Jump to

Keyboard shortcuts

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