pgxsql

package
v0.0.0-...-86e65d4 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2024 License: BSD-3-Clause Imports: 18 Imported by: 1

Documentation

Index

Examples

Constants

View Source
const (
	PingUri = postgresNID + ":" + pingNSS
	StatUri = postgresNID + ":" + statNSS
)
View Source
const (
	PkgPath = "github/advanced-go/postgresql/pgxsql"
)

Variables

This section is empty.

Functions

func NewHttpRequest

func NewHttpRequest(r *request) *http.Request

func Ping

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

Ping - ping 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", isReady())

	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, h http.Header, resource, template string, values map[string][]string, args ...any) (rows pgx.Rows, status *runtime.Status)

Query - process a SQL select statement

func Readiness

func Readiness() *runtime.Status

Readiness - package readiness

func Scan

func Scan[T Scanner[T]](rows pgx.Rows) ([]T, *runtime.Status)

Scan - templated function for scanning rows

func Stat

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

Stat - retrieve 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", isReady())

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

test: clientStartup() -> [started:true]
test: Stat(nil) -> [status:OK] [stat:true]

Types

type Attr

type Attr struct {
	Key string
	Val any
}

Attr - key value pair

type CommandTag

type CommandTag struct {
	Sql          string `json:"sql"`
	RowsAffected int64  `json:"rows-affected"`
	Insert       bool   `json:"insert"`
	Update       bool   `json:"update"`
	Delete       bool   `json:"delete"`
	Select       bool   `json:"select"`
}

CommandTag - results from an Exec command

func Delete

func Delete(ctx context.Context, h http.Header, resource, template string, where []Attr, args ...any) (tag CommandTag, status *runtime.Status)

Delete - execute a SQL delete statement

func Insert

func Insert(ctx context.Context, h http.Header, resource, template string, values [][]any, args ...any) (tag CommandTag, status *runtime.Status)

Insert - execute a SQL insert statement

func Update

func Update(ctx context.Context, h http.Header, resource, template string, where []Attr, args []Attr) (tag CommandTag, status *runtime.Status)

Update - execute a SQL update statement

type Scanner

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

Scanner - templated interface for scanning rows

Jump to

Keyboard shortcuts

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