sqlxutil

package
v2.1.10 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConflictWrap

func ConflictWrap(err error) error

ConflictWrap converts pq's unique_violation errors to ErrConflict.

func CreateNamed

func CreateNamed(ctx context.Context, c Creator, m Creatable, query string) error

func DeleteFromTable

func DeleteFromTable(ctx context.Context, e sqlx.ExecerContext, id uint64, table string) error

func DynamicGet

func DynamicGet(ctx context.Context, p Preparer, baseQuery string, dq DynamicQuery, args map[string]any, target any) error

func DynamicSelect

func DynamicSelect(ctx context.Context, p Preparer, baseQuery string, dq DynamicQuery, args map[string]any, target any) error

func NotFoundWrap

func NotFoundWrap(err error) error

NotFoundWrap converts sql.ErrNoRows to ErrNotFound.

func Now

func Now() time.Time

func WithTx

func WithTx(ctx context.Context, db *sqlx.DB, fn func(ctx context.Context, tx *sqlx.Tx) error) error

Types

type Creatable

type Creatable interface {
	Create()
	IDRef() *uint64
}

type Creator

type Creator interface {
	PrepareNamedContext(context.Context, string) (*sqlx.NamedStmt, error)
	GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
}

type DynamicQuery

type DynamicQuery struct {
	// contains filtered or unexported fields
}

func (*DynamicQuery) Copy

func (dq *DynamicQuery) Copy() DynamicQuery

type Model

type Model struct {
	ID        uint64     `json:"id" db:"id"`
	CreatedAt time.Time  `json:"createdAt" db:"created_at"`
	UpdatedAt time.Time  `json:"updatedAt" db:"updated_at"`
	DeletedAt *time.Time `json:"-" db:"deleted_at"`
}

Model can be embedded in other structs to provide common fields.

func (*Model) Create

func (m *Model) Create()

Create sets CreatedAt and UpdatedAt fields to current time.

func (*Model) IDRef

func (m *Model) IDRef() *uint64

IDRef returns a pointer to the ID field.

func (*Model) Update

func (m *Model) Update()

Update sets UpdatedAt field to current time.

type Preparer

type Preparer interface {
	PrepareNamedContext(ctx context.Context, query string) (*sqlx.NamedStmt, error)
}

type StaticError

type StaticError string
const (
	ErrNotFound StaticError = "not found"
	ErrConflict StaticError = "conflict"
)

func (StaticError) Error

func (e StaticError) Error() string

Jump to

Keyboard shortcuts

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