Documentation
¶
Index ¶
- Constants
- func Ping(ctx context.Context, h http.Header) *messaging.Status
- func Query(ctx context.Context, h http.Header, resource, template string, ...) (rows pgx.Rows, status *messaging.Status)
- func QueryT[T Scanner[T]](ctx context.Context, h http.Header, resource, template string, ...) (rows []T, status *messaging.Status)
- func Readiness() *messaging.Status
- func Rows[T Scanner[T]](entries []T) ([][]any, *messaging.Status)
- func Scan[T Scanner[T]](rows pgx.Rows) ([]T, *messaging.Status)
- func Stat() (*pgxpool.Stat, *messaging.Status)
- func Unmarshal[T Scanner[T]](t any) ([]T, *messaging.Status)
- type Attr
- type CommandTag
- func Delete(ctx context.Context, h http.Header, resource, template string, where []Attr, ...) (tag CommandTag, status *messaging.Status)
- func Insert(ctx context.Context, h http.Header, resource, template string, values [][]any, ...) (tag CommandTag, status *messaging.Status)
- func InsertT[T Scanner[T]](ctx context.Context, h http.Header, resource, template string, entries []T, ...) (tag CommandTag, status *messaging.Status)
- func NewCommandTag(url string) CommandTag
- func Update(ctx context.Context, h http.Header, resource, template string, where []Attr, ...) (tag CommandTag, status *messaging.Status)
- type DeleteFunc
- type InsertFunc
- type InsertFuncT
- type QueryFunc
- type QueryFuncT
- type Scanner
- type UpdateFunc
Examples ¶
Constants ¶
View Source
const ( StartTimeName = "start_time" DurationName = "duration_ms" TrafficName = "traffic" CreatedTSName = "created_ts" RegionName = "region" ZoneName = "zone" SubZoneName = "sub_zone" HostName = "host" InstanceIdName = "instance_id" RequestIdName = "request_id" RelatesToName = "relates_to" ProtocolName = "protocol" MethodName = "method" FromName = "from" ToName = "to" UrlName = "url" PathName = "path" StatusCodeName = "status_code" EncodingName = "encoding" BytesName = "bytes" RouteName = "route" RouteToName = "route_to" TimeoutName = "timeout" RateLimitName = "rate_limit" RateBurstName = "rate_burst" ReasonCodeName = "rc" )
View Source
const ( StatusTxnBeginError = int(102) // Transaction processing begin error StatusTxnRollbackError = int(103) // Transaction processing rollback error StatusTxnCommitError = int(104) // Transaction processing commit error StatusExecError = int(105) // Execution error, as in a database call StatusNotStarted = int(98) // Not started )
View Source
const ( PkgPath = "github/behavioral-ai/postgres/pgxsql" QueryRouteName = "postgresql-retrieval" InsertRouteName = "postgresql-insert" UpdateRouteName = "postgresql-update" DeleteRouteName = "postgresql-delete" PingRouteName = "postgresql-ping" )
Variables ¶
This section is empty.
Functions ¶
func Ping ¶
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, newPingRequest())
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 *messaging.Status)
Query - process a SQL select statement
func QueryT ¶
func QueryT[T Scanner[T]](ctx context.Context, h http.Header, resource, template string, values map[string][]string, args ...any) (rows []T, status *messaging.Status)
QueryT - process a SQL select statement, returning a type
func Stat ¶
Stat - retrieve Pgx pool 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()
fmt.Printf("test: Stat() -> [status:%v] [stat:%v]\n", status, stat1 != nil)
}
Output: test: clientStartup() -> [started:true] test: Stat(nil) -> [status:OK] [stat:true]
Types ¶
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 *messaging.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 *messaging.Status)
Insert - execute a SQL insert statement
func InsertT ¶
func InsertT[T Scanner[T]](ctx context.Context, h http.Header, resource, template string, entries []T, args ...any) (tag CommandTag, status *messaging.Status)
InsertT - execute a SQL insert statement
func NewCommandTag ¶
func NewCommandTag(url string) CommandTag
Example ¶
package main
import (
"fmt"
)
var (
//var cmdJson = "{\"sql\":\"select * from table\",\"rows-affected\":123,\"insert\":false,\"update\":true,\"delete\":false,\"select\":false}"
updateCmdTag2 = "file://[cwd]/test/update-cmd-tag.json"
)
func main() {
/*
cmd := CommandTag{
Sql: "select * from table",
RowsAffected: 123,
Insert: false,
Update: true,
Delete: false,
Select: false,
}
buf, status := json.Marshal(cmd)
fmt.Printf("test: NewCommandTag() -> %v [status:%v]\n", string(buf), status)
*/
cmd2 := NewCommandTag(updateCmdTag2)
fmt.Printf("test: NewCommandTag() -> %v\n", cmd2)
}
Output: test: NewCommandTag() -> {update test 123 false true false false}
type DeleteFunc ¶
type DeleteFunc func(context.Context, http.Header, string, string, []Attr, ...any) (CommandTag, *messaging.Status)
DeleteFunc - type
type InsertFunc ¶
type InsertFunc func(context.Context, http.Header, string, string, [][]any, ...any) (CommandTag, *messaging.Status)
InsertFunc - type
type InsertFuncT ¶
type InsertFuncT[T Scanner[T]] func(context.Context, http.Header, string, string, []T, ...any) (CommandTag, *messaging.Status)
InsertFuncT - type
type QueryFunc ¶
type QueryFunc func(context.Context, http.Header, string, string, map[string][]string, ...any) (pgx.Rows, *messaging.Status)
QueryFunc - type declaration
type QueryFuncT ¶
type QueryFuncT[T Scanner[T]] func(context.Context, http.Header, string, string, map[string][]string, ...any) ([]T, *messaging.Status)
QueryFuncT - type declaration
Click to show internal directories.
Click to hide internal directories.