Last active
May 10, 2017 15:49
-
-
Save dlt/fd3e12121b22339f696a3106ffd01643 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package tasks | |
import ( | |
"fmt" | |
"github.com/asdine/storm" | |
"github.com/asdine/storm/q" | |
) | |
// Init storm | |
var DB *storm.DB | |
DB, err := storm.Open("my_storm.db") | |
if err != nil { | |
panic(err) | |
} | |
type task struct { | |
ID int `storm:"id,increment"` | |
Name string `storm:"unique"` | |
Status string | |
Priority int | |
Tags []string | |
} | |
type taskTimer struct { | |
ID int `storm:"id,increment"` | |
TaskID int | |
StartedAt time.Time | |
ExpiresAt time.Time | |
Message string | |
Fired bool | |
} | |
// Add a new task given its name | |
func Add(name string) (err error) { | |
t := &task{Status: "TODO", Name: name} | |
err = DB.Save(t) | |
if err != nil { | |
return err | |
} | |
return | |
} | |
// Delete a task with given id | |
func Delete(ID int) { | |
var t task | |
err := DB.One("ID", ID, &t) | |
if err != nil { | |
panic(err) | |
} | |
if err = DB.DeleteStruct(&t); err != nil { | |
panic(err) | |
} | |
} | |
func createRows() [][]string { | |
var rows = [][]string{} | |
var tasks []task | |
err := DB.Select(q.True()).OrderBy("Name").Find(&tasks) | |
if err != nil { | |
fmt.Println("You still have no tasks added.") | |
fmt.Println("Add the first one by typing 'add <task-name>'") | |
} | |
for _, tt := range tasks { | |
row := []string{ | |
strconv.Itoa(tt.ID), | |
tt.Name, | |
coloredStatus(tt.Status), | |
coloredPriority(tt.Priority), | |
strings.Join(tt.Tags, ","), | |
formatRunningTime(tt.ID), | |
} | |
rows = append(rows, row) | |
} | |
return rows | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment