Task Store Lab
Build a simple task store backed by database/sql. A minimal mock driver is provided in the starter code so your solution runs in the Go Playground without a real database.
What to implement
-
createTable(db *sql.DB)โ execute aCREATE TABLE IF NOT EXISTSstatement for thetaskstable: -
insertTask(db *sql.DB, title string) int64โ insert a new task with the given title (done=0). Return the ID fromresult.LastInsertId(). -
listTasks(db *sql.DB) []Taskโ query all rows, iterate withrows.Next(), scan each into aTask, and return the slice. Usedefer rows.Close(). -
markDone(db *sql.DB, id int64)โ update the task'sdonecolumn to 1.
Task struct
main()
The main function should:
- Open the mock DB with
sql.Open("mock", "mock://") - Call
createTable - Insert two tasks:
"Buy groceries"and"Write tests" - List all tasks and print each one
- Mark the first task done
- List again and print updated results
Expected output (approximate)
The mock driver returns deterministic results โ see the starter code. Your SQL strings are validated by pattern matching; the mock driver accepts any query.