sqx

package
v0.0.0-...-7d44f7f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 17, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

package sqx contains functions that uses squirrel and scany

Index

Constants

This section is empty.

Variables

View Source
var DefaultPagingOptions = PagingOptions{
	DefaultPageSize:     100,
	MaxPageSize:         1000,
	PageSizeParameter:   "size",
	PageNumberParameter: "page",
	Logger:              logging.Get,
}
View Source
var (
	ErrNoRowsAffected = errors.New("no rows affected")
)

Functions

func DeleteOne

func DeleteOne(ctx context.Context, tx pgx.Tx, sb sq.DeleteBuilder) error

DeleteOne does a sql update and checks if exactly one row if affected by the update.

Returns ErrNoRowsAffected if 0 rows were affaced by the update.

func NewStatementBuilder

func NewStatementBuilder() sq.StatementBuilderType

NewStatementBuilder returns a squirrel statement builder with postgres dollar placeholder format.

func Query

func Query(ctx context.Context, tx pgx.Tx, sb sq.SelectBuilder, v interface{}) (pgx.Rows, error)

func QueryRowScan

func QueryRowScan(ctx context.Context, tx pgx.Tx, sb sq.Sqlizer, v ...interface{}) error

QueryRowScan queries and scans single row responses.

func ScanAll

func ScanAll(ctx context.Context, tx pgx.Tx, sb sq.SelectBuilder, v interface{}) error

func ScanOne

func ScanOne(ctx context.Context, tx pgx.Tx, sb sq.SelectBuilder, v interface{}) error

func Update

func Update(ctx context.Context, tx pgx.Tx, sb sq.UpdateBuilder) (int64, error)

Update does a sql Update and returns the number of rows updated.

func UpdateOne

func UpdateOne(ctx context.Context, tx pgx.Tx, sb sq.UpdateBuilder) error

UpdateOne does a sql update and checks if exactly one row if affected by the update.

Returns ErrNoRowsAffected if 0 rows were affaced by the update.

func WithOrderBy

func WithOrderBy(ctx context.Context, sb sq.SelectBuilder, q url.Values, defaultOrdering string, mapping []OrderByMapping) sq.SelectBuilder

func WithPaging

func WithPaging(ctx context.Context, sb sq.SelectBuilder, q url.Values, opts *PagingOptions) sq.SelectBuilder

WithPaging

Types

type OrderByMapping

type OrderByMapping struct {
	Key    string
	Fields []string
}

OrderByMapping defines the relation between the order_by url parameter and database ordering.

type PagingOptions

type PagingOptions struct {
	DefaultPageSize     int64
	MaxPageSize         int64 // set to -1 to disable max page size
	PageSizeParameter   string
	PageNumberParameter string
	Logger              logging.LoggerFunc
}

PagingOptions. To completley disable logging it is recommended to set

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL