sqlite

package module
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2024 License: MIT Imports: 10 Imported by: 0

README

sqlite

Go Reference

Access SQLite3 through structured repository patterns.

Install

go get github.com/altipla-consulting/sqlite

Contributing

You can make pull requests or create issues in GitHub. Any code you send should be formatted using make gofmt.

License

MIT License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Open

func Open(dsn string, options ...OpenOption) (*sqlx.DB, error)

Types

type Hook added in v0.4.0

type Hook[T any] func(ctx context.Context, model *T) error

type HookAfterPut added in v0.7.2

type HookAfterPut interface {
	AfterPut(ctx context.Context) error
}

type HookBeforePut added in v0.7.2

type HookBeforePut[T any] interface {
	BeforePut(ctx context.Context, tx *Tx[T]) error
}

type Hooks added in v0.4.0

type Hooks[T any] struct {
	BeforePut []Hook[T]
	AfterPut  []Hook[T]
}

type MissingKeyError added in v0.9.0

type MissingKeyError struct {
	Key string
}

func (MissingKeyError) Error added in v0.9.0

func (e MissingKeyError) Error() string

type OpenOption added in v0.9.0

type OpenOption func(opts *openOptions)

func WithDriver added in v0.9.0

func WithDriver(driverName string) OpenOption

func WithLogger added in v0.9.3

func WithLogger(logger *slog.Logger) OpenOption

type Query added in v0.6.0

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

func NewQuery added in v0.6.0

func NewQuery[T any](repo queryable, sql string, pending []string) *Query[T]

func (*Query[T]) Bind added in v0.6.0

func (q *Query[T]) Bind(args ...sql.NamedArg)

func (*Query[T]) Query added in v0.6.0

func (q *Query[T]) Query(ctx context.Context, args ...sql.NamedArg) (*T, error)

func (*Query[T]) QueryValue added in v0.6.0

func (q *Query[T]) QueryValue(ctx context.Context, args ...sql.NamedArg) (T, error)

type RepoConfig

type RepoConfig[T any] struct {
	Table      string
	PrimaryKey string
	Hooks      Hooks[T]
	Logger     *slog.Logger
}

type RepoGeneric

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

func NewRepoGeneric

func NewRepoGeneric[T any](db *sqlx.DB, cnf RepoConfig[T]) *RepoGeneric[T]

func (*RepoGeneric[T]) BeginTx added in v0.7.1

func (repo *RepoGeneric[T]) BeginTx(ctx context.Context) (*Tx[T], error)

func (*RepoGeneric[T]) Count

func (repo *RepoGeneric[T]) Count(ctx context.Context) (int64, error)

func (*RepoGeneric[T]) Delete added in v0.2.0

func (repo *RepoGeneric[T]) Delete(ctx context.Context, model *T) error

func (*RepoGeneric[T]) DeleteKey added in v0.2.0

func (repo *RepoGeneric[T]) DeleteKey(ctx context.Context, key string) error

func (*RepoGeneric[T]) Exec added in v0.5.0

func (repo *RepoGeneric[T]) Exec(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

func (*RepoGeneric[T]) Exists added in v0.3.0

func (repo *RepoGeneric[T]) Exists(ctx context.Context, key string) (bool, error)

func (*RepoGeneric[T]) ExistsQuery added in v0.6.0

func (repo *RepoGeneric[T]) ExistsQuery() *Query[bool]

func (*RepoGeneric[T]) Get

func (repo *RepoGeneric[T]) Get(ctx context.Context, key string) (*T, error)

func (*RepoGeneric[T]) GetMulti

func (repo *RepoGeneric[T]) GetMulti(ctx context.Context, keys []string) ([]*T, error)

func (*RepoGeneric[T]) List

func (repo *RepoGeneric[T]) List(ctx context.Context) ([]*T, error)

func (*RepoGeneric[T]) Put

func (repo *RepoGeneric[T]) Put(ctx context.Context, model *T) error

func (*RepoGeneric[T]) Query

func (repo *RepoGeneric[T]) Query(ctx context.Context, query string, args ...interface{}) (*T, error)

func (*RepoGeneric[T]) QueryList

func (repo *RepoGeneric[T]) QueryList(ctx context.Context, query string, args ...interface{}) ([]*T, error)

func (*RepoGeneric[T]) QueryMap

func (repo *RepoGeneric[T]) QueryMap(ctx context.Context, query string, args ...interface{}) (map[string]*T, error)

type RepoSingleton

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

func NewRepoSingleton

func NewRepoSingleton[T any](db *sqlx.DB, cnf RepoConfig[T]) *RepoSingleton[T]

func (*RepoSingleton[T]) BeginTx added in v0.7.1

func (repo *RepoSingleton[T]) BeginTx(ctx context.Context) (*Tx[T], error)

func (*RepoSingleton[T]) Exists

func (repo *RepoSingleton[T]) Exists(ctx context.Context, key string) (bool, error)

func (*RepoSingleton[T]) Get

func (repo *RepoSingleton[T]) Get(ctx context.Context, key string) (*T, error)

func (*RepoSingleton[T]) List added in v0.8.0

func (repo *RepoSingleton[T]) List(ctx context.Context) ([]*T, error)

func (*RepoSingleton[T]) Put

func (repo *RepoSingleton[T]) Put(ctx context.Context, model *T) error

func (*RepoSingleton[T]) Query

func (repo *RepoSingleton[T]) Query(ctx context.Context, query string, args ...interface{}) (*T, error)

func (*RepoSingleton[T]) QueryList added in v0.8.0

func (repo *RepoSingleton[T]) QueryList(ctx context.Context, query string, args ...interface{}) ([]*T, error)

type Tx added in v0.7.1

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

func (*Tx[T]) Commit added in v0.7.1

func (tx *Tx[T]) Commit() error

func (*Tx[T]) Put added in v0.7.1

func (tx *Tx[T]) Put(ctx context.Context, model *T) error

func (*Tx[T]) Rollback added in v0.7.1

func (tx *Tx[T]) Rollback() error

Jump to

Keyboard shortcuts

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