@@ -271,7 +271,7 @@ func (a *App) handleNormalMode(e ui.Event) {
271271 }
272272 a .render ()
273273
274- case "<Enter>" , " " :
274+ case "<Enter>" , "<Space> " :
275275 if task , ok := a .getSelectedTask (); ok {
276276 go a .toggleTask (task .ID , ! task .Done )
277277 }
@@ -436,7 +436,7 @@ func (a *App) createTask(title string) {
436436
437437 result , err := a .ditto .Store ().Execute (
438438 "INSERT INTO tasks VALUES (:task)" ,
439- map [ string ] interface {} {"task" : task },
439+ ditto. QueryArguments {"task" : task },
440440 )
441441 if err != nil {
442442 a .setError (err .Error ())
@@ -448,7 +448,7 @@ func (a *App) createTask(title string) {
448448func (a * App ) updateTask (id , title string ) {
449449 result , err := a .ditto .Store ().Execute (
450450 "UPDATE tasks SET title = :title WHERE _id = :id" ,
451- map [ string ] interface {} {
451+ ditto. QueryArguments {
452452 "title" : title ,
453453 "id" : id ,
454454 },
@@ -463,7 +463,7 @@ func (a *App) updateTask(id, title string) {
463463func (a * App ) toggleTask (id string , done bool ) {
464464 result , err := a .ditto .Store ().Execute (
465465 "UPDATE tasks SET done = :done WHERE _id = :id" ,
466- map [ string ] interface {} {
466+ ditto. QueryArguments {
467467 "done" : done ,
468468 "id" : id ,
469469 },
@@ -478,7 +478,7 @@ func (a *App) toggleTask(id string, done bool) {
478478func (a * App ) deleteTask (id string ) {
479479 result , err := a .ditto .Store ().Execute (
480480 "UPDATE tasks SET deleted = true WHERE _id = :id" ,
481- map [ string ] interface {} {"id" : id },
481+ ditto. QueryArguments {"id" : id },
482482 )
483483 if err != nil {
484484 a .setError (err .Error ())
@@ -514,23 +514,13 @@ func parseTasks(result *ditto.QueryResult) []Task {
514514 return []Task {}
515515 }
516516
517- // Don't pre-allocate when we're filtering
518- var tasks []Task
519- items := result .Items ()
520- for _ , queryItem := range items {
521- // Get the value as a map
522- item := queryItem .Value ()
523-
524- // Parse the task from the document
525- task := Task {
526- ID : getStringValue (item , "_id" ),
527- Title : getStringValue (item , "title" ),
528- Done : getBoolValue (item , "done" ),
529- Deleted : getBoolValue (item , "deleted" ),
530- }
531- if ! task .Deleted {
532- tasks = append (tasks , task )
517+ tasks := make ([]Task , 0 , result .ItemCount ())
518+ for _ , queryItem := range result .Items () {
519+ var task Task
520+ if err := queryItem .UnmarshalTo (& task ); err != nil {
521+ panic (err )
533522 }
523+ tasks = append (tasks , task )
534524 }
535525 return tasks
536526}
0 commit comments