sqlcredo

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrRecordNotFound = errors.New("record not found")

Functions

This section is empty.

Types

type CRUD

type CRUD[T any, I comparable] interface {
	InitSchema(sql string) error
	InitSchemaContext(ctx context.Context, sql string) error

	// TODO: add paging result info
	GetAll(opts ...PagingOpt) ([]*T, error)
	GetAllContext(ctx context.Context, opts ...PagingOpt) ([]*T, error)
	GetAllValues(opts ...PagingOpt) ([]T, error)
	GetAllValuesContext(ctx context.Context, opts ...PagingOpt) ([]T, error)

	GetByID(id I) (*T, error)
	GetByIDContext(ctx context.Context, id I) (*T, error)
	GetValueByID(id I) (T, error)
	GetValueByIDContext(ctx context.Context, id I) (T, error)

	GetByIDs(ids []I) ([]*T, error)
	GetByIDsContext(ctx context.Context, ids []I) ([]*T, error)
	GetValuesByIDs(ids []I) ([]T, error)
	GetValuesByIDsContext(ctx context.Context, ids []I) ([]T, error)

	Create(e *T) error
	CreateContext(ctx context.Context, e *T) error

	DeleteAll() error
	DeleteAllContext(ctx context.Context) error

	Delete(id I) error
	DeleteContext(ctx context.Context, id I) error

	Update(id I, e *T) error
	UpdateContext(ctx context.Context, id I, e *T) error

	Count() (int64, error)
	CountContext(ctx context.Context) (int64, error)
}

type DebugFunc

type DebugFunc func(sql string, args ...any)

type PagingOpt

type PagingOpt func(*pagingParams)

func WithLimit

func WithLimit(limit uint) PagingOpt

func WithOffset

func WithOffset(offset uint) PagingOpt

func WithOrderColumn

func WithOrderColumn(orderColumn string) PagingOpt

func WithOrderColumnAndDirection

func WithOrderColumnAndDirection(orderColumn string, desc bool) PagingOpt

type SQLCredo

type SQLCredo[T any, I comparable] interface {
	SQLExecutor
	CRUD[T, I]

	WithDebugFunc(newDebugFunc DebugFunc) SQLCredo[T, I]
	GetDebugFunc() DebugFunc
}

func NewSQLCredo

func NewSQLCredo[T any, I comparable](db *sql.DB, driver string, table string, idColumn string) SQLCredo[T, I]

type SQLExecutor

type SQLExecutor interface {
	SelectOne(dest any, query string, args ...any) error
	SelectOneContext(ctx context.Context, dest any, query string, args ...any) error

	SelectMany(dest any, query string, args ...any) error
	SelectManyContext(ctx context.Context, dest any, query string, args ...any) error

	Exec(query string, args ...any) (sql.Result, error)
	ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)

	Begin() (*sql.Tx, error)
	BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)
}

Jump to

Keyboard shortcuts

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