Documentation
¶
Index ¶
- Constants
- func NewOTELTracer(t trace.Tracer) *tracer
- func NewTracer(fn TraceFn) *tracer
- func SchemaCreate(ctx context.Context, conn Conn, name string) error
- func SchemaDrop(ctx context.Context, conn Conn, name string) error
- func SchemaExists(ctx context.Context, conn Conn, name string) (bool, error)
- type Bind
- func (bind *Bind) Append(key string, value any) bool
- func (bind *Bind) Copy(pairs ...any) *Bind
- func (bind *Bind) Del(key string)
- func (bind *Bind) Get(key string) any
- func (bind *Bind) Has(key string) bool
- func (bind *Bind) Join(key, sep string) string
- func (bind *Bind) MarshalJSON() ([]byte, error)
- func (bind *Bind) Query(name string) string
- func (bind *Bind) Replace(query string) string
- func (bind *Bind) Set(key string, value any) string
- func (bind *Bind) String() string
- type Conn
- type Err
- type ListReader
- type Listener
- type Notification
- type OffsetLimit
- type Op
- type Opt
- func WithAddr(addr string) Opt
- func WithApplicationName(name string) Opt
- func WithBind(k string, v any) Opt
- func WithCredentials(user, password string) Opt
- func WithDatabase(name string) Opt
- func WithHostPort(host, port string) Opt
- func WithSSLMode(mode string) Opt
- func WithSchemaSearchPath(schemas ...string) Opt
- func WithTrace(fn TraceFn) Opt
- func WithTracer(tracer trace.Tracer) Opt
- func WithURL(value string) Opt
- type PoolConn
- type Queries
- type Reader
- type Row
- type Selector
- type TraceFn
- type Writer
Constants ¶
const (
DefaultPort = "5432"
)
const (
TraceSpanNameArg = "otelspan"
)
Variables ¶
This section is empty.
Functions ¶
func NewOTELTracer ¶ added in v1.1.1
NewOTELTracer creates a new query tracer that emits OpenTelemetry spans. Each query will create a new span. If fn is non-nil, it will also be called on query end.
func NewTracer ¶
func NewTracer(fn TraceFn) *tracer
NewTracer creates a new query tracer with an optional callback function.
func SchemaCreate ¶
SchemaCreate creates a schema with the given name if it does not exist.
func SchemaDrop ¶
SchemaDrop drops a schema with the given name if it exists.
Types ¶
type Bind ¶
Bind represents a set of variables and arguments to be used in a query. The vars are substituted in the query string itself, while the args are passed as arguments to the query.
func NewBind ¶
NewBind creates a new Bind object with the given name/value pairs. Returns nil if the number of arguments is not even.
func (*Bind) Append ¶
Append appends a bind var to a list. Returns false if the key is not a list, or the value is not a list.
func (*Bind) Join ¶
Join joins a bind var with a separator when it is a []any and returns the result as a string. Returns an empty string if the key does not exist.
func (*Bind) MarshalJSON ¶
func (*Bind) Query ¶
Query looks up a named query, sets the span name for OpenTelemetry tracing, and returns the resolved SQL string. The name should match a query key that was loaded via withQueries (e.g., "pgqueue.get").
func (*Bind) Replace ¶
Replace returns a query string with ${subtitution} replaced by the values:
- ${key} => value
- ${'key'} => 'value'
- ${"key"} => "value"
- $1 => $1
- $$ => $$
type Conn ¶
type Conn interface {
// Return a new connection with bound parameters
With(...any) Conn
// Return a new connection with bound queries
WithQueries(...*Queries) Conn
// Return a connection to a remote database
Remote(database string) Conn
// Perform a transaction within a function
Tx(context.Context, func(Conn) error) error
// Perform a bulk operation within a function (and indicate whether this
// should be in a transaction)
Bulk(context.Context, func(Conn) error) error
// Execute a query
Exec(context.Context, string) error
// Perform an insert
Insert(context.Context, Reader, Writer) error
// Perform an update
Update(context.Context, Reader, Selector, Writer) error
// Perform a delete
Delete(context.Context, Reader, Selector) error
// Perform a get
Get(context.Context, Reader, Selector) error
// Perform a list. If the reader is a ListReader, then the
// count of items is also calculated
List(context.Context, Reader, Selector) error
}
type Err ¶
type Err int
type ListReader ¶
ListReader scans database rows and counts total results.
type Listener ¶
type Listener interface {
// Listen to a topic
Listen(context.Context, string) error
// Unlisten from a topic
Unlisten(context.Context, string) error
// Wait for a notification and return it
WaitForNotification(context.Context) (*Notification, error)
// Free resources
Close(context.Context) error
}
Listener is an interface for listening to notifications
type Notification ¶
type OffsetLimit ¶
type OffsetLimit struct {
Offset uint64 `json:"offset,omitempty"`
Limit *uint64 `json:"limit,omitempty"`
}
func (*OffsetLimit) Bind ¶
func (r *OffsetLimit) Bind(bind *Bind, max uint64)
Bind sets the offset and limit SQL fragment on the bind object.
func (*OffsetLimit) Clamp ¶
func (r *OffsetLimit) Clamp(len uint64)
Clamp restricts the limit to the maximum length.
type Opt ¶
type Opt func(*opt) error
Opt is a function which applies options for a connection pool
func WithApplicationName ¶ added in v1.1.0
WithApplicationName sets the application name for the connection. This appears in pg_stat_activity and helps identify connections.
func WithCredentials ¶
WithCredentials sets the connection pool username and password. If the database name is not set, then the username will be used as the default database name.
func WithDatabase ¶
WithDatabase sets the database name for the connection. If the user name is not set, then the database name will be used as the user name.
func WithHostPort ¶
WithHostPort sets the hostname and port for the connection. If the port is not set, then the default port 5432 will be used.
func WithSSLMode ¶
WithSSLMode sets the PostgreSQL SSL mode. Valid values are "disable", "allow", "prefer", "require", "verify-ca", "verify-full".
func WithSchemaSearchPath ¶ added in v1.1.0
WithSchemaSearchPath sets the schema search path for the connection. If no schemas are provided, the search_path parameter is removed.
func WithTracer ¶ added in v1.1.1
WithTracer sets the OTEL tracer for the connection pool.
type PoolConn ¶
type Queries ¶ added in v1.1.0
type Queries struct {
// contains filtered or unexported fields
}
Queries represents a collection of named SQL statements parsed from a reader. SQL statements are separated by comment lines in the format: -- <identifier> Each statement is stored with its identifier as the key.
func NewQueries ¶ added in v1.1.0
NewQueries parses SQL statements from a reader and returns a Queries collection. SQL statements must be separated by comment lines matching the pattern: -- <identifier> where <identifier> consists of alphanumeric characters, underscores, dots, and hyphens. Returns an error if duplicate identifiers are found or if reading fails.
Example input format:
-- user.select SELECT * FROM users WHERE id = $1; -- user.insert INSERT INTO users (name, email) VALUES ($1, $2);
type Selector ¶
type Selector interface {
// Set bind parameters for getting, updating or deleting
Select(*Bind, Op) (string, error)
}
Selector binds parameters for get, update, or delete operations.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
example
command
|
|
|
example2
command
|
|
|
pgmanager
command
|
|
|
pgqueue
command
|
|
|
pkg
|
|
|
manager
Package manager provides a comprehensive API for managing PostgreSQL server resources including roles, databases, schemas, tables, connections, and more.
|
Package manager provides a comprehensive API for managing PostgreSQL server resources including roles, databases, schemas, tables, connections, and more. |
|
manager/httpclient
Package httpclient provides a typed Go client for consuming the PostgreSQL management REST API.
|
Package httpclient provides a typed Go client for consuming the PostgreSQL management REST API. |
|
manager/httphandler
Package httphandler provides REST API endpoints for PostgreSQL management operations.
|
Package httphandler provides REST API endpoints for PostgreSQL management operations. |
|
manager/schema
Package schema defines all data types, request/response structures, and SQL queries for PostgreSQL management resources.
|
Package schema defines all data types, request/response structures, and SQL queries for PostgreSQL management resources. |
|
queue
Package queue provides a PostgreSQL-backed task queue with support for delayed tasks, retries with exponential backoff, and periodic tickers.
|
Package queue provides a PostgreSQL-backed task queue with support for delayed tasks, retries with exponential backoff, and periodic tickers. |
|
queue/httpclient
Package httpclient provides a typed Go client for consuming the PostgreSQL queue management REST API.
|
Package httpclient provides a typed Go client for consuming the PostgreSQL queue management REST API. |
|
queue/httphandler
Package httphandler provides HTTP handlers for the queue package.
|
Package httphandler provides HTTP handlers for the queue package. |
|
test
Package test provides utilities for integration testing with PostgreSQL using testcontainers.
|
Package test provides utilities for integration testing with PostgreSQL using testcontainers. |
|
types
Package types provides utility functions for pointer conversions and string formatting.
|
Package types provides utility functions for pointer conversions and string formatting. |
|
version
Package version provides build version information.
|
Package version provides build version information. |
|
wasm
|
|
|
pgmanager
command
|