pgxsql

package
v0.0.0-...-d5c92cc Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2023 License: BSD-3-Clause Imports: 13 Imported by: 2

Documentation

Index

Examples

Constants

View Source
const (
	PostgresNID = "postgresql"

	PingUri = "urn:" + PostgresNID + ":" + sql.PingNSS
	StatUri = "urn:" + PostgresNID + ":" + sql.StatNSS
)

Variables

View Source
var (
	Uri = 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 *sql.Request) string
Example
rsc := "access-log"
t := "delete from access_log"
req := NewDeleteRequest(rsc, t, nil)

sql := BuildSql(req)
fmt.Printf("test: Delete.BuildSql(%v) -> %v\n", t, sql)

t = "update access_log"
req = NewUpdateRequest(rsc, t, nil, nil)
sql = BuildSql(req)
fmt.Printf("test: Update.BuildSql(%v) -> %v\n", t, sql)
Output:

test: Delete.BuildSql(delete from access_log) -> delete from access_log
test: Update.BuildSql(update access_log) -> update access_log

func BuildUpdateUri

func BuildUpdateUri(resource string) string

BuildUpdateUri - build an uri with the Update NSS

func ClientShutdown

func ClientShutdown()

func ClientStartup

func ClientStartup(db messaging.DatabaseUrl, credentials messaging.Credentials) error

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

Example
db := messaging.DatabaseUrl{Url: ""}
err := ClientStartup(db, nil)
if err == nil {
	defer ClientShutdown()
}
fmt.Printf("test: ClientStartup() -> %v\n", err)
Output:

test: ClientStartup() -> database URL is empty

func IsStarted

func IsStarted() bool

IsStarted - returns status of startup

func NewDeleteRequest

func NewDeleteRequest(resource, template string, where []sql.Attr) *sql.Request

func NewInsertRequest

func NewInsertRequest(resource, template string, values [][]any) *sql.Request

func NewQueryRequest

func NewQueryRequest(resource, template string, where []sql.Attr) *sql.Request

func NewQueryRequestFromValues

func NewQueryRequestFromValues(resource, template string, values map[string][]string) *sql.Request

func NewUpdateRequest

func NewUpdateRequest(resource, template string, attrs []sql.Attr, where []sql.Attr) *sql.Request

func Ping

func Ping[E runtime.ErrorHandler](ctx context.Context) (status *runtime.Status)

Ping - templated 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[runtime.DebugError](nil)
	fmt.Printf("test: Ping(nil) -> %v\n", status)
}
Output:

test: clientStartup() -> [started:true]
test: Ping(nil) -> OK

func Scan

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

Scan - templated function for scanning rows

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[E runtime.ErrorHandler](ctx context.Context, req *sql.Request) (tag CommandTag, status *runtime.Status)

Exec - templated function for executing a SQL statement

type FieldDescription

type FieldDescription struct {
	Name                 string
	TableOID             uint32
	TableAttributeNumber uint16
	DataTypeOID          uint32
	DataTypeSize         int16
	TypeModifier         int32
	Format               int16
}

FieldDescription - data for defining the returned Query fields/columns

type Rows

type Rows interface {
	// Close closes the rows, making the connection ready for use again. It is safe
	// to call Close after rows is already closed.
	Close()

	// Err returns any error that occurred while reading.
	Err() error

	// CommandTag returns the command tag from this query. It is only available after Rows is closed.
	CommandTag() CommandTag

	FieldDescriptions() []FieldDescription

	// Next prepares the next row for reading. It returns true if there is another
	// row and false if no more rows are available. It automatically closes rows
	// when all rows are read.
	Next() bool

	// Scan reads the values from the current row into dest values positionally.
	// dest can include pointers to core pgxsql, values implementing the Scanner
	// interface, and nil. nil will skip the value entirely. It is an error to
	// call Scan without first calling Next() and checking that it returned true.
	Scan(dest ...any) error

	// Values returns the decoded row values. As with Scan(), it is an error to
	// call Values without first calling Next() and checking that it returned
	// true.
	Values() ([]any, error)

	// RawValues returns the unparsed bytes of the row values. The returned data is only valid until the next Next
	// call or the Rows is closed.
	RawValues() [][]byte
}

Rows - interface that proxies the postgresql Rows interface

func Query

func Query[E runtime.ErrorHandler](ctx context.Context, req *sql.Request) (result Rows, status *runtime.Status)

Query - templated function for a Query

type Scanner

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

Scanner - templated interface for scanning rows

type Stats

type Stats = pgxpool.Stat

Stats - pool statistics

func Stat

func Stat[E runtime.ErrorHandler](ctx context.Context) (stat *Stats, status *runtime.Status)

Stat - templated 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[runtime.DebugError](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]

Jump to

Keyboard shortcuts

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