summaryrefslogtreecommitdiff
path: root/model
diff options
context:
space:
mode:
authorKevin Chabowski <kevin@kch42.de>2013-08-28 21:48:47 +0200
committerKevin Chabowski <kevin@kch42.de>2013-08-28 21:48:47 +0200
commit8ecfe7a2fc61caf890e319e7a2f298b71dc90826 (patch)
treeebec6cedcafd2c6bae07ff2edeaff4e5d5377466 /model
parent3e52620c29e6893ce1cf5e45ec4e00a37184edd6 (diff)
downloadmailremind-8ecfe7a2fc61caf890e319e7a2f298b71dc90826.tar.gz
mailremind-8ecfe7a2fc61caf890e319e7a2f298b71dc90826.tar.bz2
mailremind-8ecfe7a2fc61caf890e319e7a2f298b71dc90826.zip
Some improvements to the model
Diffstat (limited to 'model')
-rw-r--r--model/dbmodel.go2
-rw-r--r--model/mysql/jobs.go13
-rw-r--r--model/mysql/queries.go2
3 files changed, 8 insertions, 9 deletions
diff --git a/model/dbmodel.go b/model/dbmodel.go
index 76414c7..cc4a6d7 100644
--- a/model/dbmodel.go
+++ b/model/dbmodel.go
@@ -66,7 +66,7 @@ type DBCon interface {
InactiveUsers(olderthan time.Time) []DBID
- JobsBefore(t time.Time) []DBID // Get Jobs with next <= t
+ JobsBefore(t time.Time) []Job // Get Jobs with next <= t
}
type DBInfo struct {
diff --git a/model/mysql/jobs.go b/model/mysql/jobs.go
index d5abb1b..2695d50 100644
--- a/model/mysql/jobs.go
+++ b/model/mysql/jobs.go
@@ -182,21 +182,20 @@ func (j *Job) Delete() error {
return err
}
-func (con *MySQLDBCon) JobsBefore(t time.Time) []model.DBID {
+func (con *MySQLDBCon) JobsBefore(t time.Time) (jobs []model.Job) {
rows, err := con.stmt[qJobsBefore].Query(t.Unix())
if err != nil {
log.Fatalf("Could not get jobs before %s: %s", t, err) // TODO: Really fatal?
}
- ids := make([]model.DBID, 0)
for rows.Next() {
- var _id uint64
- if err := rows.Scan(&_id); err != nil {
- log.Printf("Could not get all jobs before %s: %s", t, err)
+ job, err := jobFromSQL(con, rows)
+ if err != nil {
+ log.Fatalf("Could not get all jobs before %s: %s", t, err)
break
}
- ids = append(ids, DBID(_id))
+ jobs = append(jobs, job)
}
- return ids
+ return
}
diff --git a/model/mysql/queries.go b/model/mysql/queries.go
index da2a554..7d7b860 100644
--- a/model/mysql/queries.go
+++ b/model/mysql/queries.go
@@ -44,7 +44,7 @@ var queries = map[int]string{
qSetContent: "UPDATE `jobs` SET `content` = ? WHERE `id` = ?",
qSetNext: "UPDATE `jobs` SET `next` = ? WHERE `id` = ?",
qDelJob: "DELETE FROM `jobs` WHERE `id` = ?",
- qJobsBefore: "SELECT `id` FROM `jobs` WHERE `next` <= ?",
+ qJobsBefore: qfragSelJob + "WHERE `next` <= ?",
qInsertJob: "INSERT INTO `jobs` (`user`, `subject`, `content`, `next`, `chronos`) VALUES (?, ?, ?, ?, ?)",
qInsertUser: "INSERT INTO `users` (`email`, `passwd`, `location`, `active`, `activationcode`, `added`) VALUES (?, ?, ?, ?, ?, ?)",
qSetChronos: "UPDATE `jobs` SET `chronos` = ? WHERE `id` = ?",