badger

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package badger implements the srs/db.Handler interface with a badger backend

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler struct {
	Db   *badger.DB
	Algo algo.Algo
}

Handler is a badger client.

It accepts an Algo to allow for atomic operations. (for example Update must read from the db, decode, compute new values according to the review, and write back to db)

func New

func New(db *badger.DB, algo algo.Algo) *Handler

func (*Handler) Due

func (h *Handler) Due(deckId string, t time.Time) (due review.Due, err error)

Due returs th Due cards for the time t

func (*Handler) Insert

func (h *Handler) Insert(r review.Review, deckId string) (res review.Due, err error)

Insert runs the Algo on a all cards of a Review, and saves the result in the db. It returns a slice of review Due structs containing the Due Date for each of the card ids. There are two cases:

1) New cards for existing DeckId: this requires a lookup of the last CardId in the db 2) New cards for new DeckId created in this session, which do no require lookup, index starts at 0.

Insert is atomic

func (*Handler) Update

func (h *Handler) Update(r review.Review) (due review.Due, err error)

Update looks up in the db the (must) existing cards in the review r, run the srs algo on them, and saves the updated result in the db. It returns a slice of reviews containing the Due Date for each of the card ids.

The function is atomic

Jump to

Keyboard shortcuts

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