Documentation ¶
Index ¶
- Constants
- func Ping(ctx context.Context, h http.Header) *core.Status
- func Query(ctx context.Context, h http.Header, resource, template string, ...) (rows pgx.Rows, status *core.Status)
- func QueryT[T Scanner[T]](ctx context.Context, h http.Header, resource, template string, ...) (rows []T, status *core.Status)
- func Readiness() *core.Status
- func Rows[T Scanner[T]](entries []T) ([][]any, *core.Status)
- func Scan[T Scanner[T]](rows pgx.Rows) ([]T, *core.Status)
- func Stat() (*pgxpool.Stat, *core.Status)
- func Unmarshal[T Scanner[T]](t any) ([]T, *core.Status)
- type Attr
- type CommandTag
- func Delete(ctx context.Context, h http.Header, resource, template string, where []Attr, ...) (tag CommandTag, status *core.Status)
- func Insert(ctx context.Context, h http.Header, resource, template string, values [][]any, ...) (tag CommandTag, status *core.Status)
- func InsertT[T Scanner[T]](ctx context.Context, h http.Header, resource, template string, entries []T, ...) (tag CommandTag, status *core.Status)
- func NewCommandTag(url string) CommandTag
- func Update(ctx context.Context, h http.Header, resource, template string, where []Attr, ...) (tag CommandTag, status *core.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 ( PkgPath = "github/advanced-go/postgresql/pgxsql" QueryRouteName = "postgresql-query" 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 *core.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 *core.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 *core.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 *core.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 *core.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, *core.Status)
DeleteFunc - type
type InsertFunc ¶
type InsertFunc func(context.Context, http.Header, string, string, [][]any, ...any) (CommandTag, *core.Status)
InsertFunc - type
type InsertFuncT ¶
type InsertFuncT[T Scanner[T]] func(context.Context, http.Header, string, string, []T, ...any) (CommandTag, *core.Status)
InsertFuncT - type
type QueryFunc ¶
type QueryFunc func(context.Context, http.Header, string, string, map[string][]string, ...any) (pgx.Rows, *core.Status)
QueryFunc - type declaration
type QueryFuncT ¶
type QueryFuncT[T Scanner[T]] func(context.Context, http.Header, string, string, map[string][]string, ...any) ([]T, *core.Status)
QueryFuncT - type declaration
Click to show internal directories.
Click to hide internal directories.