pgxsql

package
v0.0.0-...-4adcc48 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2023 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	QueryNSS  = "query"
	SelectNSS = "select"
	InsertNSS = "insert"
	UpdateNSS = "update"
	DeleteNSS = "delete"
	PingNSS   = "ping"
	StatNSS   = "stat"

	PostgresNID = "postgresql"
	PingUri     = "urn:" + PostgresNID + ":" + PingNSS
	StatUri     = "urn:" + PostgresNID + ":" + StatNSS

	SelectCmd = 0
	InsertCmd = 1
	UpdateCmd = 2
	DeleteCmd = 3

	NullExpectedCount = int64(-1)
)

Variables

View Source
var (
	PkgUri = reflect.TypeOf(any(pkg{})).PkgPath()
)

Functions

func BuildDeleteUri

func BuildDeleteUri(resource string) string

BuildDeleteUri - build an uri with the Delete NSS

func BuildInsertUri

func BuildInsertUri(resource string) string

BuildInsertUri - build an uri with the Insert NSS

func BuildQueryUri

func BuildQueryUri(resource string) string

BuildQueryUri - build an uri with the Query NSS

func BuildSql

func BuildSql(r *request) string

func BuildUpdateUri

func BuildUpdateUri(resource string) string

BuildUpdateUri - build an uri with the Update NSS

func BuildUri

func BuildUri(nid string, nss, resource string) string

func BuildWhere

func BuildWhere(values map[string][]string) []pgxdml.Attr

BuildWhere - build the []Attr based on the URL query parameters

func ClientShutdown

func ClientShutdown()

func ClientStartup

func ClientStartup(rsc startup.Resource, credentials startup.Credentials) error

ClientStartup - entry point for creating the pooling client and verifying a connection can be acquired

Example
rsc := startup.Resource{Uri: ""}
err := ClientStartup(rsc, nil)
if err == nil {
	defer ClientShutdown()
}
fmt.Printf("test: ClientStartup() -> %v\n", err)
Output:
test: ClientStartup() -> database URL is empty

func GetStatus

func GetStatus() *runtime.Status

func Ping

func Ping(ctx context.Context) (status *runtime.Status)

Ping - function for pinging the database cluster

Example
err := testStartup()
if err != nil {
	fmt.Printf("test: testStartup() -> [error:%v]\n", err)
} else {
	defer ClientShutdown()
	fmt.Printf("test: clientStartup() -> [started:%v]\n", isStarted())

	status := Ping(nil)
	fmt.Printf("test: Ping(nil) -> %v\n", status)
}
Output:
test: clientStartup() -> [started:true]
test: Ping(nil) -> OK

func Query

func Query(ctx context.Context, req Request) (result pgx.Rows, status *runtime.Status)

Query - function for a Query

func Scan

func Scan[T Scanner[T]](rows pgx.Rows) ([]T, error)

Scan - templated function for scanning rows

func Stat

func Stat(ctx context.Context) (stat *pgxpool.Stat, status *runtime.Status)

Stat - function for retrieving runtime stats

Example
err := testStartup()
if err != nil {
	fmt.Printf("test: testStartup() -> [error:%v]\n", err)
} else {
	defer ClientShutdown()
	fmt.Printf("test: clientStartup() -> [started:%v]\n", isStarted())

	stat, status := Stat(nil)
	fmt.Printf("test: Stat(nil) -> [status:%v] [stat:%v]\n", status, stat != nil)
}
Output:
test: clientStartup() -> [started:true]
test: Stat(nil) -> [status:OK] [stat:true]

Types

type CommandTag

type CommandTag struct {
	Sql          string
	RowsAffected int64
	Insert       bool
	Update       bool
	Delete       bool
	Select       bool
}

CommandTag - results from an Exec command

func Exec

func Exec(ctx context.Context, req Request) (tag CommandTag, status *runtime.Status)

Exec - function for executing a SQL statement

type ExecController

type ExecController interface {
	Apply(ctx context.Context, r Request) (pgconn.CommandTag, *runtime.Status)
	// contains filtered or unexported methods
}

ExecController - an interface that manages exec resiliency

func NewExecController

func NewExecController(name string, threshold Threshold, logFn log2.AccessHandler) ExecController

NewExecController - create a new resiliency controller

type PingController

type PingController interface {
	Apply(ctx context.Context) *runtime.Status
	// contains filtered or unexported methods
}

PingController - an interface that manages ping resiliency

func NewPingController

func NewPingController(name string, threshold Threshold, logFn log2.AccessHandler) PingController

NewPingController - create a new resiliency controller

type PingFn

type PingFn func(ctx context.Context) *runtime.Status

PingFn - ping function

type QueryController

type QueryController interface {
	Apply(ctx context.Context, r Request) (pgx.Rows, *runtime.Status)
	// contains filtered or unexported methods
}

QueryController - an interface that manages query resiliency

func NewQueryController

func NewQueryController(name string, threshold Threshold, logFn log2.AccessHandler) QueryController

NewQueryController - create a new resiliency controller

type Request

type Request interface {
	Uri() string
	Method() string
	Sql() string
	Args() []any
	String() string
	HttpRequest() *http.Request
}

func NewDeleteRequest

func NewDeleteRequest(uri, template string, where []pgxdml.Attr, args ...any) Request

func NewInsertRequest

func NewInsertRequest(uri, template string, values [][]any, args ...any) Request

func NewQueryRequest

func NewQueryRequest(uri, template string, where []pgxdml.Attr, args ...any) Request

func NewQueryRequestFromValues

func NewQueryRequestFromValues(uri, template string, values map[string][]string, args ...any) Request

func NewUpdateRequest

func NewUpdateRequest(uri, template string, attrs []pgxdml.Attr, where []pgxdml.Attr, args ...any) Request

type Scanner

type Scanner[T any] interface {
	Scan(columnNames []string, values []any) (T, error)
}

Scanner - templated interface for scanning rows

type StatusAgent

type StatusAgent interface {
	Run()
	Stop()
}

StatusAgent - an agent that will manage returning an endpoint back to receiving traffic

func NewStatusAgent

func NewStatusAgent(threshold int, interval time.Duration, query *QueryController, exec *ExecController) (StatusAgent, error)

NewStatusAgent - creation of an agent with configuration

type Threshold

type Threshold struct {
	Limit   rate.Limit // request per second
	Burst   int
	Timeout time.Duration
}

Threshold - rate limiting and timeout

Jump to

Keyboard shortcuts

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