dbctx

package
v0.0.0-...-73b9a49 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BeginTransaction

func BeginTransaction(db DBContext) (*sql.Tx, error)

Types

type Column

type Column struct {
	Name string
	Kind ColumnKind
}

type ColumnKind

type ColumnKind int
const (
	ValueColumn ColumnKind = iota
	KeyColumn
	GeneratedKeyColumn
	CreatedAtColumn
	UpdatedAtColumn
)

type DBContext

type DBContext interface {
	ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
	QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
	QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
}

type DBTransaction

type DBTransaction interface {
	DBContext
	Commit() error
	Rollback() error
}

type Fields

type Fields map[string]any

type Filters

type Filters map[string]any

type FindOptions

type FindOptions struct {
	Filters    Filters
	Pagination *Pagination
	Order      *Order
}

type Order

type Order struct {
	Field string
	Desc  bool
}

type Pagination

type Pagination struct {
	Offset int
	Limit  int
}

type PgSQLRepo

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

func NewPgSQLRepo

func NewPgSQLRepo[T any](cfg SQLRepoConfig[T]) (*PgSQLRepo[T], error)

func (PgSQLRepo[T]) Columns

func (r PgSQLRepo[T]) Columns() []Column

func (PgSQLRepo[T]) Create

func (r PgSQLRepo[T]) Create(ctx context.Context, db DBContext, item *T) error

func (PgSQLRepo[T]) DeleteMany

func (r PgSQLRepo[T]) DeleteMany(ctx context.Context, db DBContext, filters Filters) error

func (PgSQLRepo[T]) DeleteOne

func (r PgSQLRepo[T]) DeleteOne(ctx context.Context, db DBContext, item T) error

func (PgSQLRepo[T]) FindMany

func (r PgSQLRepo[T]) FindMany(ctx context.Context, db DBContext, opts FindOptions) ([]T, error)

func (PgSQLRepo[T]) FindOne

func (r PgSQLRepo[T]) FindOne(ctx context.Context, db DBContext, filters Filters) (*T, error)

func (PgSQLRepo[T]) TableName

func (r PgSQLRepo[T]) TableName() string

func (PgSQLRepo[T]) UpdateMany

func (r PgSQLRepo[T]) UpdateMany(ctx context.Context, db DBContext, fields Fields, filters Filters) error

func (PgSQLRepo[T]) UpdateOne

func (r PgSQLRepo[T]) UpdateOne(ctx context.Context, db DBContext, item T) error

type Repo

type Repo[T any] interface {
	Create(ctx context.Context, db DBContext, item *T) error
	UpdateOne(ctx context.Context, db DBContext, item T) error
	UpdateMany(ctx context.Context, db DBContext, fields Fields, filters Filters) error
	DeleteOne(ctx context.Context, db DBContext, item T) error
	DeleteMany(ctx context.Context, db DBContext, filters Filters) error
	FindOne(ctx context.Context, db DBContext, filters Filters) (*T, error)
	FindMany(ctx context.Context, db DBContext, opts FindOptions) ([]T, error)
}

type SQLRepoConfig

type SQLRepoConfig[T any] struct {
	Table          string
	Columns        []Column
	MapScan        func(item *T) []any
	NoSoftDelete   bool
	NoCreateUpdate bool
}

type UpdateOptions

type UpdateOptions struct {
	Filters Filters
}

Jump to

Keyboard shortcuts

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