Maladroit Elusive Transaction Hub
A wrapper around upper.io/db to ease some repetitive tasks.
Working with upper.io/db sometimes becomes a little bit repetitive, so METH is an attempt to minimize the scaffolding needed in some basic tasks [fetching by id, by certain conditions].
go get github.com/worg/meth
Any type must implement Persistent
interface and return an initalized and valid db.Collection in order to use METH functions.
package person
import (
"upper.io/db"
"upper.io/db/some_driver"
)
type Person struct {
ID int `db:"id"`
Name string `db:"name"`
Address string `db:"address"`
}
var (
collection db.Collection
)
func init() {
//init DB and set collection
}
func (p *Person) Collection() db.Collection {
return collection
}
func (p *Person) ById(id int) {
if err := meth.One(&p); err := nil {
// handle err
}
// by this point p should've been filled with db data
}