summaryrefslogtreecommitdiff
path: root/model
diff options
context:
space:
mode:
authorKevin Chabowski <kevin@kch42.de>2013-08-27 12:11:44 +0200
committerKevin Chabowski <kevin@kch42.de>2013-08-27 12:11:44 +0200
commit57872925e3b438122520a245caacf2843bebf185 (patch)
tree7be9fbb486a692dad2b2d7102acaa2fbe7aa91be /model
parentbac5337e6584a7201ba73be64dee3922721aba5a (diff)
downloadmailremind-57872925e3b438122520a245caacf2843bebf185.tar.gz
mailremind-57872925e3b438122520a245caacf2843bebf185.tar.bz2
mailremind-57872925e3b438122520a245caacf2843bebf185.zip
Rough idea for a database model.
Diffstat (limited to 'model')
-rw-r--r--model/dbmodel.go83
1 files changed, 83 insertions, 0 deletions
diff --git a/model/dbmodel.go b/model/dbmodel.go
new file mode 100644
index 0000000..9dd2c91
--- /dev/null
+++ b/model/dbmodel.go
@@ -0,0 +1,83 @@
+package model
+
+import (
+ "errors"
+ "fmt"
+ "kch42.de/gostuff/mailremind/chronos"
+ "sync"
+ "time"
+)
+
+var (
+ NotFound = errors.New("Not Found")
+)
+
+type DBID interface {
+ fmt.Stringer
+}
+
+type User interface {
+ ID() DBID
+ Email() string
+
+ PWHash() []byte
+ SetPWHash([]byte) error
+
+ AddJob() Job
+ Jobs() []Job
+ JobByID(DBID) (Job, error)
+
+ Delete() error
+}
+
+type Job interface {
+ ID() DBID
+ User() User
+
+ Subject() string
+ SetSubject(string) error
+
+ Content() []byte
+ SetContent([]byte) error
+
+ Chronos() []chronos.Chronos
+ SetChronos([]chronos.Chronos) error
+
+ Next() time.Time
+ SetNext(time.Time) error
+
+ Delete() error
+}
+
+type DBCon interface {
+ Close()
+
+ UserByID(DBID) (User, error)
+ UserByMail(string) (User, error)
+
+ LastAccess() time.Time
+ SetLastAccess(time.Time) error
+
+ JobsBetween(a, b time.Time) ([]Job, error)
+}
+
+type DBInfo struct {
+ Connect func(dbconf string) (DBCon, error)
+ ParseDBID func(string) (DBID, error)
+}
+
+var dbinfos map[string]DBInfo
+var dbinfoInit sync.Once
+
+func Register(name string, dbinfo DBInfo) {
+ dbinfoInit.Do(func() {
+ dbinfos = make(map[string]DBInfo)
+ })
+
+ dbinfos[name] = dbinfo
+}
+
+func GetDBInfo(name string) (DBInfo, bool) {
+ dbinfo, ok := dbinfos[name]
+ return dbinfo, ok
+}