store

package
v1.0.13 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrCodeMySQLDuplicateEntry はMySQL系のDUPLICATEエラーコード
	// https://dev.mysql.com/doc/mysql-errors/8.0/en/server-error-reference.html
	// Error number: 1062; Symbol: ER_DUP_ENTRY; SQLSTATE: 23000
	ErrCodeMySQLDuplicateEntry = 1062
)

Variables

View Source
var (
	Tasks = &TaskStore{Tasks: map[entity.TaskID]*entity.Task{}}

	ErrNotFound = errors.New("not found")
)
View Source
var (
	ErrAlreadyEntry = errors.New("duplicate entry")
)

Functions

func New

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

Types

type Beginner

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

type Execer

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 KVS added in v0.0.7

type KVS struct {
	Cli *redis.Client
}

func NewKVS added in v0.0.7

func NewKVS(ctx context.Context, cfg *config.Config) (*KVS, error)

func (*KVS) Load added in v0.0.7

func (k *KVS) Load(ctx context.Context, key string) (entity.UserID, error)

func (*KVS) Save added in v0.0.7

func (k *KVS) Save(ctx context.Context, key string, userID entity.UserID) error

type Preparer

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

type Queryer

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

type Repository struct {
	Clocker clock.Clocker
}

func (*Repository) AddTask

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

func (*Repository) GetUser added in v0.0.7

func (r *Repository) GetUser(
	ctx context.Context, db Queryer, name string,
) (*entity.User, error)

func (*Repository) ListTasks

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

func (*Repository) RegisterUser added in v0.0.6

func (r *Repository) RegisterUser(ctx context.Context, db Execer, u *entity.User) error

type TaskStore

type TaskStore struct {
	// 動作確認用の仮実装なのであえてexportしている。
	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

All はソート済みのタスク一覧を返す

func (*TaskStore) Get

func (ts *TaskStore) Get(id entity.TaskID) (*entity.Task, error)

Jump to

Keyboard shortcuts

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