Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsNotFound ¶
Types ¶
type Entry ¶
type Entry interface { // Assigns a generated id for a new entry, or assigns // the existing id when an entry is read AssignId(id string) // Sets the created time for a new entry Created(at time.Time) // Sets the modified time when an entry is updated Modified(at time.Time) }
A database entry representation needs to implement this interface.
type IdGenerator ¶
type IdGenerator func() string
func for generating a new identifier. Use your uuid of choice
type JsonDb ¶
type JsonDb interface { // Create a new entry and write it to the database. Returns // the newly assigned id or an error. Create(entry Entry) (string, error) // Delete an existing entry. Will return NotFoundError if the // record isn't in the database. Delete(id string) error // Read an entry from the database. Returns a NotFoundError // if an entry with the supplied id can't be found. Will // also return any serialisation errors if they occur. Read(id string, entry Entry) error // Update an existing entry. Will return NotFoundError if the // record isn't in the database. Update(id string, entry Entry) error // contains filtered or unexported methods }
func Cache ¶
Create a memory caching wrapper around a JsonDb. Unlike an uncached JsonDb, a cache won't be able to deal with other processes changing the underlying files. Don't use if you've got that scenario.
func New ¶
func New(dir string, newid IdGenerator) JsonDb
Create a new database client pointed at a directory. Will create the directory if it doesn't exist.
type NotFoundError ¶
type NotFoundError struct {
EntityId string
}
func (NotFoundError) Error ¶
func (err NotFoundError) Error() string
type Scanner ¶
type Scanner interface { // Scan to see if there's another record after the // current one Scan() bool // Read the current record, see Db.Read for // error behaviour. Read(entry Entry) error // The length of the underlying dataset Length() int }
Database record scanner. Used for iterating over all the records in a database.
func NewScanner ¶
Click to show internal directories.
Click to hide internal directories.