store

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// 永続化なしの実装
	Tasks = &TaskStore{Tasks: map[entity.TaskID]*entity.Task{}}

	ErrNotFound = errors.New("not found")
)

Functions

func RunMigrateDown added in v0.0.5

func RunMigrateDown(db *sql.DB) error

func RunMigrateUp added in v0.0.5

func RunMigrateUp(db *sql.DB) error

Types

type Beginner added in v0.0.5

type Beginner interface {
	BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)
}

後にある _ Beginner = (*sqlx.DB)(nil) が成り立つのは *sqlx.DB が下記だから

type DB struct {
	*sql.DB
  ...
}

type DB added in v0.0.5

type DB struct {
	SqlDB  *sql.DB
	SqlxDB *sqlx.DB
}

Closeの対応のため、もともとの実装を変更した

func New added in v0.0.5

func New(ctx context.Context, cfg *config.Config) (*DB, error)

この名前もNewはいまいち、あと store.go でないのも分かりにくい

func (*DB) Close added in v0.0.5

func (d *DB) Close()

本当に sqlx.DB の Close だけではダメなのだろうか

type Execer added in v0.0.5

type Execer interface {
	ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
	NamedExecContext(ctx context.Context, query string, arg interface{}) (sql.Result, error)
}

type Preparer added in v0.0.5

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

type Queryer added in v0.0.5

type Queryer interface {
	Preparer
	QueryxContext(ctx context.Context, query string, args ...any) (*sqlx.Rows, error)
	QueryRowxContext(ctx context.Context, query string, args ...any) *sqlx.Row
	GetContext(ctx context.Context, dest interface{}, query string, args ...any) error
	SelectContext(ctx context.Context, dest interface{}, query string, args ...any) error
}

type Repository added in v0.0.5

type Repository struct {
	Clocker clock.Clocker
}

func (*Repository) AddTask added in v0.0.5

func (r *Repository) AddTask(ctx context.Context, db Execer, task *entity.Task) error

func (*Repository) ListTasks added in v0.0.5

func (r *Repository) ListTasks(ctx context.Context, db Queryer) (entity.Tasks, error)

type TaskStore

type TaskStore struct {
	LastID entity.TaskID
	Tasks  map[entity.TaskID]*entity.Task
}

タスクの操作に関する構造とメソッド

func (*TaskStore) Add

func (ts *TaskStore) Add(t *entity.Task) (entity.TaskID, error)

func (*TaskStore) All

func (ts *TaskStore) All() entity.Tasks

Jump to

Keyboard shortcuts

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