beerapi: Index | Files

package db

import ""

Package db implements a database as required in beerapi/adapters. It does not persist its data, all records are stored in memory. It is not intended to be used in and sort of production environment, but rather as an example of how to implement the adapters interface.


Package Files

db.go model.go table.go

type DBError Uses

type DBError string

func (DBError) Error Uses

func (a DBError) Error() string

type Database Uses

type Database struct {
    // contains filtered or unexported fields

func (*Database) CreateTable Uses

func (database *Database) CreateTable(name string) adapters.Table

Create a table in the database with specified name.

func (*Database) Table Uses

func (database *Database) Table(name string) (adapters.Table, error)

Get the table with specified name, returns nil if that table does not exist.

type Id Uses

type Id string

type Model Uses

type Model struct {
    // contains filtered or unexported fields

func (*Model) Attributes Uses

func (model *Model) Attributes() map[string]interface{}

Return this model's data.

func (*Model) Delete Uses

func (model *Model) Delete() error

Delete this model from the database.

func (*Model) GetId Uses

func (model *Model) GetId() string

Returns and lazily creates this model's ID.

func (*Model) Save Uses

func (model *Model) Save() error

Store this model in the database.

func (*Model) SetAttributes Uses

func (model *Model) SetAttributes(attributes map[string]interface{})

Set the model's data. In this implementation, expects attribures to be map[string]interface{}.

type ModelSet Uses

type ModelSet []*Model

type Table Uses

type Table struct {
    // contains filtered or unexported fields

func NewTable Uses

func NewTable(name string) *Table

Create a new table with specified name. Name should be a plural, singular form is assumed to be name minus its last letter.

func (*Table) All Uses

func (table *Table) All() (result adapters.ModelSet)

Returns all the records in this table.

func (*Table) Delete Uses

func (table *Table) Delete(id string) error

Remove the record with specified ID from the table. Returns a DBError id that ID does not exist.

func (*Table) Find Uses

func (table *Table) Find(id string) (model adapters.Model, err error)

Returns the object with specified ID. If the ID is not found error is DBError and model is nil.

func (*Table) NewRecord Uses

func (table *Table) NewRecord() adapters.Model

Create a new record for this table. The new record is not added to the table until Save is called.

func (*Table) RecordName Uses

func (table *Table) RecordName() string

The name of an individual record.

func (*Table) RecordSetName Uses

func (table *Table) RecordSetName() string

The name of a collection of records.

func (*Table) Save Uses

func (table *Table) Save(model *Model) (err error)

Create or update the specified record.

func (*Table) Search Uses

func (table *Table) Search(query interface{}) (result adapters.ModelSet)

Return the records which match query, or all records in a table when query is nil. In this impelementation query is expected to be map[string]interface. Records are returned if all the fields contained in query are equal by reflect.DeepEqual to their counterparts in the record.

Package db imports 7 packages (graph) and is imported by 1 packages. Updated 2016-07-30. Refresh now. Tools for package owners.