Documentation
¶
Index ¶
- Constants
- Variables
- func BuildUri(path string) string
- func ClientShutdown()
- func ClientStartup(config map[string]string, credentials messaging.Credentials) error
- func CollectRows[T any](rows Rows, fn RowToFunc[T]) ([]T, error)
- func ContextWithExec(ctx context.Context, fn ExecProxy) context.Context
- func ContextWithQuery(ctx context.Context, fn QueryProxy) context.Context
- func IsContextExec(c context.Context) bool
- func IsContextQuery(c context.Context) bool
- func IsStarted() bool
- func Ping[E template.ErrorHandler](ctx context.Context) (status *template.Status)
- func SetActuator(fn template.ActuatorApply)
- func Stat[E template.ErrorHandler](ctx context.Context) (stat *pgxpool.Stat, status *template.Status)
- type CollectableRow
- type CommandTag
- func ContextExec(ctx context.Context, req Request) (CommandTag, error)
- func Exec[E template.ErrorHandler](ctx context.Context, req Request, arguments ...any) (CommandTag, *template.Status)
- func ExecInsert[E template.ErrorHandler](ctx context.Context, tag *CommandTag, req Request, values []any) (CommandTag, *template.Status)
- func ExecUpdate[E template.ErrorHandler](ctx context.Context, tag *CommandTag, req Request, attrs []sqldml.Attr, ...) (CommandTag, *template.Status)
- func ExecWithCommand[E template.ErrorHandler](ctx context.Context, tag *CommandTag, req Request, arguments ...any) (_ CommandTag, status *template.Status)
- type ExecProxy
- type FieldDescription
- type QueryProxy
- type Request
- type RowToFunc
- type Rows
Examples ¶
Constants ¶
View Source
const (
DatabaseURLKey = "DATABASE_URL"
)
Variables ¶
View Source
var (
Uri = pkgPath
)
Functions ¶
func ClientShutdown ¶
func ClientShutdown()
func ClientStartup ¶
func ClientStartup(config map[string]string, credentials messaging.Credentials) error
func CollectRows ¶
CollectRows iterates through rows, calling fn for each row, and collecting the results into a slice of T.
func ContextWithExec ¶
ContextWithExec - creates a new Context with an Exec function
func ContextWithQuery ¶
func ContextWithQuery(ctx context.Context, fn QueryProxy) context.Context
ContextWithQuery - creates a new Context with a Query function
func IsContextExec ¶
func IsContextQuery ¶
func SetActuator ¶
func SetActuator(fn template.ActuatorApply)
Types ¶
type CollectableRow ¶
type CommandTag ¶
type CommandTag struct { Sql string RowsAffected int64 Insert bool Update bool Delete bool Select bool }
func ContextExec ¶
func ContextExec(ctx context.Context, req Request) (CommandTag, error)
func Exec ¶
func Exec[E template.ErrorHandler](ctx context.Context, req Request, arguments ...any) (CommandTag, *template.Status)
Example ¶
package main import ( "context" "errors" "fmt" "github.com/idiomatic-go/middleware/template" ) func NilEmpty(s string) string { if s == "" { return "<nil>" } return s } const ( execUpdateSql = "update test" execInsertSql = "insert test" execUpdatePath = "exec.update" execInsertPath = "exec.insert" ) func execTestProxy(req Request) (CommandTag, error) { switch req.Uri { case BuildUri(execUpdatePath): return emptyCommandTag, errors.New("exec error") case BuildUri(execInsertPath): return CommandTag{ Sql: req.Sql, RowsAffected: 1234, Insert: true, Update: false, Delete: false, Select: false, }, nil } return emptyCommandTag, nil } func main() { ctx := ContextWithExec(context.Background(), execTestProxy) cmd, status := Exec[template.DebugError](ctx, NewRequest(execUpdatePath, execUpdateSql)) fmt.Printf("test: Exec(%v) -> %v [cmd:%v]\n", execUpdateSql, status, cmd) cmd, status = Exec[template.DebugError](ctx, NewRequest(execInsertPath, execInsertSql)) fmt.Printf("test: Exec(%v) -> %v [cmd:%v]\n", execInsertSql, status, cmd) }
Output: [[] github.com/idiomatic-go/postgresql-adapter/pgxsql/exec [exec error]] test: Exec(update test) -> Internal [cmd:{ 0 false false false false}] test: Exec(insert test) -> OK [cmd:{insert test 1234 true false false false}]
func ExecInsert ¶
func ExecInsert[E template.ErrorHandler](ctx context.Context, tag *CommandTag, req Request, values []any) (CommandTag, *template.Status)
func ExecUpdate ¶
func ExecUpdate[E template.ErrorHandler](ctx context.Context, tag *CommandTag, req Request, attrs []sqldml.Attr, where []sqldml.Attr) (CommandTag, *template.Status)
func ExecWithCommand ¶
func ExecWithCommand[E template.ErrorHandler](ctx context.Context, tag *CommandTag, req Request, arguments ...any) (_ CommandTag, status *template.Status)
type ExecProxy ¶
type ExecProxy func(req Request) (CommandTag, error)
type FieldDescription ¶
type QueryProxy ¶
type Request ¶
func NewRequest ¶
type RowToFunc ¶
type RowToFunc[T any] func(row CollectableRow) (T, error)
RowToFunc is a function that scans or otherwise converts row to a T.
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 sqldml, 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 }
Click to show internal directories.
Click to hide internal directories.