Documentation
¶
Index ¶
- func Close()
- func Delete(models ...Model) error
- func DeleteById(modelName string, ids ...string) error
- func GetConn() redis.Conn
- func Init(passedConfig *Configuration)
- func KeyExists(key string, conn redis.Conn) (bool, error)
- func Register(in interface{}, modelName string) error
- func Save(models ...Model) error
- func SetContains(key, member string, conn redis.Conn) (bool, error)
- func UnregisterName(modelName string) error
- func UnregisterType(modelType reflect.Type) error
- type Configuration
- type DefaultData
- type Model
- type ModelNameNotRegisteredError
- type ModelQuery
- type ModelTypeNotRegisteredError
- type MultiModelQuery
- func (q *MultiModelQuery) Exclude(fields ...string) *MultiModelQuery
- func (q *MultiModelQuery) Include(fields ...string) *MultiModelQuery
- func (q *MultiModelQuery) Limit(amount uint) *MultiModelQuery
- func (q *MultiModelQuery) Offset(amount uint) *MultiModelQuery
- func (q *MultiModelQuery) Order(order string) *MultiModelQuery
- func (q *MultiModelQuery) Run() (interface{}, error)
- func (q *MultiModelQuery) SortBy(field string) *MultiModelQuery
- type NameAlreadyRegisteredError
- type Query
- type TypeAlreadyRegisteredError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Close ¶
func Close()
Close closes the connection pool and shuts down the Zoom library. It should be run when application exits, e.g. using defer.
func Delete ¶
Delete removes a struct (or structs) from the database. Will throw an error if the type of the struct has not yet been registered, or if the Id field of the struct is empty.
func DeleteById ¶
DeleteById removes a struct (or structs) from the database by its registered name and id. The modelName argument should be the same string name that was used in the Register function. If using variadic paramaters, you can only delete models of the same registered name and type.
func GetConn ¶
GetConn gets a connection from the connection pool and returns it. It can be used for directly interacting with the database. Check out http://godoc.org/github.com/garyburd/redigo/redis for full documentation on the redis.Conn type.
func Init ¶
func Init(passedConfig *Configuration)
Init starts the Zoom library and creates a connection pool. It accepts a Configuration struct as an argument. Any zero values in the configuration will fallback to their default values. Init should be called once during application startup.
func KeyExists ¶
KeyExists returns true iff a given key exists in redis. If conn is nil, a new connection will be created and closed before the end of the function.
func Register ¶
Register adds a type to the list of registered types. Any struct you wish to save must be registered first. Both modelName and type of in must be unique, i.e. not already registered.
func Save ¶
Save writes an arbitrary struct (or structs) to the redis database. Save throws an error if the type of the struct has not yet been registered. If the Id field of the struct is empty, Save will mutate the struct by setting the Id. To make a struct satisfy the Model interface, you can embed zoom.DefaultData.
func SetContains ¶
SetContains returns true iff the redis set identified by key contains member. If conn is nil, a new connection will be created and closed before the end of the function.
func UnregisterName ¶
UnregisterName removes a type (identified by modelName) from the list of registered types. You only need to call UnregisterName or UnregisterType, not both.
func UnregisterType ¶
UnregisterName removes a type from the list of registered types. You only need to call UnregisterName or UnregisterType, not both.
Types ¶
type Configuration ¶
type Configuration struct {
Address string // Address to connect to. Default: "localhost:6379"
Network string // Network to use. Default: "tcp"
Database int // Database id to use (using SELECT). Default: 0
}
Configuration contains various options. It should be created once and passed in to the Init function during application startup.
type DefaultData ¶ added in v0.3.0
type DefaultData struct {
Id string `redis:"-"`
}
DefaultData should be embedded in any struct you wish to save. It includes important fields and required methods to implement Model.
type Model ¶
type Model interface {
// contains filtered or unexported methods
}
Model is an interface encapsulating anything that can be saved. Any struct which includes an embedded DefaultData field satisfies the Model interface.
type ModelNameNotRegisteredError ¶
type ModelNameNotRegisteredError struct {
// contains filtered or unexported fields
}
ModelNameNotRegisteredError is returned if you attempt to perform certain operations for unregistered names.
func NewModelNameNotRegisteredError ¶
func NewModelNameNotRegisteredError(name string) *ModelNameNotRegisteredError
func (*ModelNameNotRegisteredError) Error ¶
func (e *ModelNameNotRegisteredError) Error() string
type ModelQuery ¶ added in v0.3.0
type ModelQuery struct {
// contains filtered or unexported fields
}
A ModelQuery is a query which returns a single item from the database. It can be chained with query modifiers.
func FindById ¶
func FindById(modelName, id string) *ModelQuery
FindById returns a ModelQuery which can be chained with additional modifiers.
func ScanById ¶ added in v0.1.1
func ScanById(id string, m Model) *ModelQuery
ScanById returns a ModelQuery which can be chained with additional modifiers. It expects Model as an argument, which should be a pointer to a struct of a registered type. ScanById will mutate the struct, filling in its fields.
func (*ModelQuery) Exclude ¶ added in v0.3.0
func (q *ModelQuery) Exclude(fields ...string) *ModelQuery
Exclude specifies fields to *not* be filled in. Excluded fields will remain unchanged. Any other fields *will* be filled in with the values stored in redis.
func (*ModelQuery) Include ¶ added in v0.3.0
func (q *ModelQuery) Include(fields ...string) *ModelQuery
Include specifies fields to be filled in. Any fields which are included will be unchanged.
func (*ModelQuery) Run ¶ added in v0.3.0
func (q *ModelQuery) Run() (interface{}, error)
Run executes the query, using a transaction if possible. The first return value is a Model, i.e. a pointer to a struct. When using the ScanById constructor, the first return value is typically not needed. The second return value is the first error (if any) that occured in the query constructor or modifier methods.
type ModelTypeNotRegisteredError ¶
type ModelTypeNotRegisteredError struct {
// contains filtered or unexported fields
}
ModelTypeNotRegisteredError is returned if you attempt to perform certain operations for unregistered types.
func NewModelTypeNotRegisteredError ¶
func NewModelTypeNotRegisteredError(typ reflect.Type) *ModelTypeNotRegisteredError
func (*ModelTypeNotRegisteredError) Error ¶
func (e *ModelTypeNotRegisteredError) Error() string
type MultiModelQuery ¶ added in v0.3.0
type MultiModelQuery struct {
// contains filtered or unexported fields
}
A MultiModelQuery is a query wich returns one or more items from the database. It can be chained with query modifiers.
func FindAll ¶
func FindAll(modelName string) *MultiModelQuery
FindAll returns a MultiModelQuery which can be chained with additional modifiers.
func ScanAll ¶ added in v0.3.0
func ScanAll(models interface{}) *MultiModelQuery
ScanAll returns a MultiModelQuery which can be chained with additional modifiers. It expects a pointer to a slice (or array) of Models as an argument, which should be a pointer to a slice (or array) of pointers to structs of a registered type. ScanAll will mutate the slice or array by appending to it.
func (*MultiModelQuery) Exclude ¶ added in v0.3.0
func (q *MultiModelQuery) Exclude(fields ...string) *MultiModelQuery
Exclude specifies fields to *not* be filled in for each struct. Excluded fields will remain unchanged. Any other fields *will* be filled in with the values stored in redis.
func (*MultiModelQuery) Include ¶ added in v0.3.0
func (q *MultiModelQuery) Include(fields ...string) *MultiModelQuery
Include specifies fields to be filled in for each model. Any fields which are included will be unchanged.
func (*MultiModelQuery) Limit ¶ added in v0.3.0
func (q *MultiModelQuery) Limit(amount uint) *MultiModelQuery
Limit specifies an upper limit on the number of records to return.
func (*MultiModelQuery) Offset ¶ added in v0.3.0
func (q *MultiModelQuery) Offset(amount uint) *MultiModelQuery
Offset specifies a starting index from which to start counting records that will be returned.
func (*MultiModelQuery) Order ¶ added in v0.3.0
func (q *MultiModelQuery) Order(order string) *MultiModelQuery
Order specifies the order in which records should be sorted. It should be either ASC or DESC. Any other argument will cause an error.
func (*MultiModelQuery) Run ¶ added in v0.3.0
func (q *MultiModelQuery) Run() (interface{}, error)
Run executes the query, using a transaction if possible. The first return value of Run will be a slice of Models, i.e. a slice of pointers to structs. When using the ScanAll constructor, the first return value is typically not needed. The second return value is the first error (if any) that occured in the query constructor or modifier methods.
func (*MultiModelQuery) SortBy ¶ added in v0.3.0
func (q *MultiModelQuery) SortBy(field string) *MultiModelQuery
SortBy specifies a field to sort by. The field argument should be exactly the name of an exported field. Will cause an error if the field is not found.
type NameAlreadyRegisteredError ¶
type NameAlreadyRegisteredError struct {
// contains filtered or unexported fields
}
NameAlreadyRegisteredError is returned if you try to register a name which has already been registered.
func NewNameAlreadyRegisteredError ¶
func NewNameAlreadyRegisteredError(name string) *NameAlreadyRegisteredError
func (*NameAlreadyRegisteredError) Error ¶
func (e *NameAlreadyRegisteredError) Error() string
type Query ¶ added in v0.3.0
type Query interface {
Run() (interface{}, error)
}
A Query is an interface which is intended encapsulate sophisticated requests to the database. All queries are executed as redis transactions when possible. You must call Run on the query when you are ready for the query to be run. Depending on the type of the query, certain "modifier" methods may be chained to the constructor. Modifiers are Include, Exclude, Sort, Limit, and Offset. A query will remember any errors that occur and return the first one when you call Run.
type TypeAlreadyRegisteredError ¶
type TypeAlreadyRegisteredError struct {
// contains filtered or unexported fields
}
TypeAlreadyRegisteredError is returned if you try to register a type which has already been registered.
func NewTypeAlreadyRegisteredError ¶
func NewTypeAlreadyRegisteredError(typ reflect.Type) *TypeAlreadyRegisteredError
func (*TypeAlreadyRegisteredError) Error ¶
func (e *TypeAlreadyRegisteredError) Error() string