quintodrome/repositories/base_repository.go

30 lines
546 B
Go
Raw Normal View History

package repositories
2016-02-28 09:50:05 -09:00
import (
"fmt"
"crypto/md5"
"strings"
)
type BaseRepository struct {
2016-02-28 09:50:05 -09:00
key string // TODO Rename to 'table'
}
2016-02-28 09:50:05 -09:00
func (r *BaseRepository) NewId(fields ...string) string {
s := fmt.Sprintf("%s\\%s", strings.ToUpper(r.key), strings.Join(fields, ""))
return fmt.Sprintf("%x", md5.Sum([]byte(s)))
2016-02-27 22:56:41 -09:00
}
func (r *BaseRepository) CountAll() (int, error) {
return count(r.key)
}
2016-02-28 09:50:05 -09:00
func (r *BaseRepository) saveOrUpdate(id string, rec interface{}) error {
return saveStruct(r.key, id, rec)
}
func (r *BaseRepository) Dump() {
}