Documentation
¶
Index ¶
- func Filter(slice []string, filterMap map[string]string) (result []string)
- func NewPipeline() *pipeline
- func Pairs(keyValuePairs []any) (map[string]any, error)
- func PairsHook(keyValuePairs []any, identifiers map[string]any, hook string) (map[string]any, error)
- type CursorToken
- type Exec
- type ExecResult
- type Option
- func WithConnMax(maxOpenConns int) Option
- func WithConnMaxIdleTime(maxConnIdleTime time.Duration) Option
- func WithConnMaxLifetime(maxConnLifetime time.Duration) Option
- func WithDBName(dbName string) Option
- func WithDriverName(driverName string) Option
- func WithDsn(dsn string) Option
- func WithHost(host string) Option
- func WithMaxIdleConns(maxIdleConns int) Option
- func WithMaxOpenConns(maxOpenConns int) Option
- func WithPassword(password string) Option
- func WithPort(port int) Option
- func WithSSLMode(sslMode string) Option
- func WithUser(user string) Option
- type Pagination
- type Postgres
- type RequestGetCursorTokenFromEncoded
- type RequestPaginationCursor
- type RequestPaginationOffset
- type ResponseGetCursorTokenFromEncoded
- type ResponsePaginationCursor
- type ResponsePaginationOffset
- type Select
- type SortField
- type StringSlice
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewPipeline ¶
func NewPipeline() *pipeline
NewPipeline creates a new empty pipeline instance. The pipeline can be used to chain multiple database operations that should be executed atomically in a transaction.
Types ¶
type CursorToken ¶ added in v1.1.5
type Exec ¶
type Exec interface {
Debug() Exec
Exec(ctx context.Context) (any, error)
ExecInTx(ctx context.Context) (result *ExecResult, err error)
Insert(query string, keyValuePairs ...any) Exec
Update(query string, keyValuePairs ...any) Exec
Delete(query string, keyValuePairs ...any) Exec
Select(query string, destination any, keyValuePairs ...any) Exec
Wrap(exec Exec) Exec
FromResult(from string) string
}
type ExecResult ¶
type ExecResult struct {
// contains filtered or unexported fields
}
ExecResult is the result of an exec query.
func (*ExecResult) TxResult ¶
func (e *ExecResult) TxResult(query string) any
type Option ¶
type Option func(*config)
Option is a function that configures the postgres database.
func WithConnMax ¶
WithConnMax sets the max conn. maxOpenConns is the maximum number of open connections to the database.
func WithConnMaxIdleTime ¶
WithConnMaxIdleTime sets the max conn idle time. maxConnIdleTime is the maximum amount of time a connection may be idle.
func WithConnMaxLifetime ¶
WithConnMaxLifetime sets the max conn lifetime. maxConnLifetime is the maximum amount of time a connection may be reused.
func WithDBName ¶
WithDBName sets the db name. dbName is the name of the database to connect to.
func WithDriverName ¶
WithDriverName sets the driver name.
func WithMaxIdleConns ¶
func WithMaxOpenConns ¶
WithMaxOpenConns sets the max open conns. maxOpenConns is the maximum number of open connections to the database.
func WithPassword ¶
WithPassword sets the password. password is the password to connect with.
func WithSSLMode ¶
WithSSLMode sets the ssl mode. sslMode is the SSL mode to use.
type Pagination ¶ added in v1.1.5
type Pagination[T any] interface { Debug() Pagination[T] Offset(ctx context.Context, req *RequestPaginationOffset) (*ResponsePaginationOffset[T], error) Cursor(ctx context.Context, req *RequestPaginationCursor) (*ResponsePaginationCursor[T], error) }
func NewPagination ¶ added in v1.1.5
func NewPagination[T any](repo Postgres) Pagination[T]
type Postgres ¶
type Postgres interface {
Select(query string, destination any, keyValuePairs ...any) Select
Insert(query string, keyValuePairs ...any) Exec
Update(query string, keyValuePairs ...any) Exec
Delete(query string, keyValuePairs ...any) Exec
FromResult(from string) string
}
Postgres is the interface for the postgres database client.
type RequestGetCursorTokenFromEncoded ¶ added in v1.1.5
type RequestGetCursorTokenFromEncoded struct {
// Token is the base64 encoded string containing the cursor state from a previous request.
Token string
// Sorts is a list of sorting definitions that acts as the "Single Source of Truth."
// This field is automatically used to build two components:
// 1. The SQL ORDER BY clause.
// 2. The Row Comparison filter condition (e.g., (col1, col2) > (:val1, :val2)).
//
// IMPORTANT: The order in this slice determines sort priority. The last element
// MUST be a unique column (such as a Primary Key/ID) to ensure deterministic
// pagination (preventing skipped or duplicate data across pages).
Sorts []SortField
// Query is the base SQL query excluding the ORDER BY clause and cursor conditions.
Query string
// Kv contains existing query parameters in a key-value pair format (named parameters).
Kv []any
// IsCustomCTE should be set to true if the Query uses fmt.Sprintf placeholders (%s).
// Typically, the first placeholder is for the cursor condition and the second for ORDER BY.
IsCustomCTE bool
// Keys is a list of field keys to be extracted from the token.
// Usually populated automatically based on the 'Key' fields defined in Sorts.
Keys []string
}
RequestGetCursorTokenFromEncoded holds the parameters required to decode a cursor and rebuild the SQL query for the next or previous page.
type RequestPaginationCursor ¶ added in v1.1.5
type RequestPaginationOffset ¶ added in v1.1.5
type RequestPaginationOffset struct {
Page int64
Size int64
Query string
Kv []any
QueryCount string
}
func (*RequestPaginationOffset) GetTotalPages ¶ added in v1.1.5
func (r *RequestPaginationOffset) GetTotalPages(total int64) int64
type ResponseGetCursorTokenFromEncoded ¶ added in v1.1.5
type ResponsePaginationCursor ¶ added in v1.1.5
type ResponsePaginationOffset ¶ added in v1.1.5
type Select ¶
type Select interface {
Debug() Select
One(ctx context.Context) (found bool, err error)
Many(ctx context.Context) (found bool, err error)
}
Select is an interface for selecting data from the database.
type SortField ¶ added in v1.1.5
type SortField struct {
// Column is the full SQL column name, including table aliases if necessary.
// Example: "u.created_at" or "p.id".
Column string
// Key is the field name used as the key within the JSON map/token.
// This should match the JSON tag or DB tag on the target struct.
// Example: "created_at" or "id".
Key string
// IsDesc determines the sort direction. If true, it uses DESC; if false, it uses ASC.
IsDesc bool
}
SortField defines the mapping between a database column and a token key for ordering.
type StringSlice ¶
type StringSlice []string
func (*StringSlice) Scan ¶
func (s *StringSlice) Scan(src any) error