change db location, remove multiple ids
This commit is contained in:
parent
5d45e648a3
commit
69006beddd
@ -29,9 +29,13 @@ var rmCmd = &cobra.Command{
|
||||
Long: `Remove a todo given its id.`,
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
id, err := strconv.ParseUint(args[0], 10, 0)
|
||||
var ids []uint64
|
||||
for _, arg := range args {
|
||||
id, err := strconv.ParseUint(arg, 10, 0)
|
||||
errPanic(err, "failed to parse uint")
|
||||
deleteTodo(id)
|
||||
ids = append(ids, id)
|
||||
}
|
||||
deleteTodo(ids)
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,7 @@ func parseDateString(date string) time.Time {
|
||||
|
||||
// openDB returns gorm database.
|
||||
func openDB() *gorm.DB {
|
||||
db, err := gorm.Open(sqlite.Open("todo.db"), &gorm.Config{})
|
||||
db, err := gorm.Open(sqlite.Open("/home/user/.todo.db"), &gorm.Config{})
|
||||
errPanic(err, "failed to connect database")
|
||||
|
||||
return db
|
||||
@ -82,10 +82,12 @@ func updateTodo(id uint64, desc string, date string, comp bool) {
|
||||
}
|
||||
|
||||
// deleteTodo deletes an entry of id todo in the database.
|
||||
func deleteTodo(id uint64) {
|
||||
func deleteTodo(ids []uint64) {
|
||||
db := openDB()
|
||||
for _, id := range ids {
|
||||
db.Delete(&Todo{}, id)
|
||||
}
|
||||
}
|
||||
|
||||
// getAllTodos return all todos from the database.
|
||||
func getAllTodos() []Todo {
|
||||
|
Loading…
Reference in New Issue
Block a user