table

package module
v0.0.0-...-593eb99 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2023 License: MIT Imports: 5 Imported by: 0

README

table

sqlx helper library for some db boilerplate

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*helper)

func WithDBGeneratedField

func WithDBGeneratedField(col string) Option

type Table

type Table[T any] struct {
	// contains filtered or unexported fields
}

Table provides boilerplate ops for some table with sqlx.

func New

func New[T any](name, pk string, opts ...Option) *Table[T]

New returns a new Table for the given type.

func (*Table[T]) Delete

func (t *Table[T]) Delete(ctx context.Context, db *sqlx.DB, query string, args ...any) (int64, error)

Delete deletes records matching the query.

func (*Table[T]) Fetch

func (t *Table[T]) Fetch(ctx context.Context, db *sqlx.DB, col string, val any) (*T, error)

Fetch returns a single record with a value matching a given field. Mostly useful for fetching by unique values.

func (*Table[T]) Find

func (t *Table[T]) Find(ctx context.Context, db *sqlx.DB, id any) (*T, error)

Find returns a single record with a value matching a given pk.

func (*Table[T]) Insert

func (t *Table[T]) Insert(ctx context.Context, db *sqlx.DB, obj *T) error

Insert inserts a single record into the table.

func (*Table[T]) Replace

func (t *Table[T]) Replace(ctx context.Context, db *sqlx.DB, obj *T) error

Replace replaces the given record.

func (*Table[T]) Select

func (t *Table[T]) Select(ctx context.Context, db *sqlx.DB, query string, args ...any) ([]*T, error)

Select fetches all records matching a given query.

Jump to

Keyboard shortcuts

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