Browse Source

Initial commit

pull/1/head
grumbulon 4 months ago
commit
d052bc79df
  1. 0
      README.md
  2. 58
      db.go
  3. 5
      go.mod
  4. 2
      go.sum
  5. BIN
      godo.db
  6. 31
      main.go

0
README.md

58
db.go

@ -0,0 +1,58 @@
package main
import (
"database/sql"
"log"
"os"
_ "github.com/mattn/go-sqlite3"
)
func InitDb(){
Dbname := "godo.db"
if _, err := os.Stat(Dbname); err == nil {
log.Printf("DB exists")
os.Remove(Dbname)
} else if os.IsNotExist(err) {
file, err := os.Create(Dbname)
if err != nil {
log.Printf("Unable to write file %w", err)
}
defer file.Close()
}
db, err := sql.Open("sqlite3", Dbname)
if err != nil {
log.Fatal(err)
}
defer db.Close()
sqlStmt := `
create table tasks (id integer not null primary key AUTOINCREMENT, task);
delete from tasks;
`
_, err = db.Exec(sqlStmt)
if err != nil {
log.Printf("%q: %s\n", err, sqlStmt)
return
}
}
func LsTask() {
Dbname := "godo.db"
db, err := sql.Open("sqlite3", Dbname)
if err != nil {
log.Fatal(err)
}
db.Exec("SELECT task FROM tasks;")
}
func AddTask() {
Dbname := "godo.db"
db, err := sql.Open("sqlite3", Dbname)
}

5
go.mod

@ -0,0 +1,5 @@
module git.freecumextremist.com/grumbulon/go-do
go 1.16
require github.com/mattn/go-sqlite3 v1.14.8

2
go.sum

@ -0,0 +1,2 @@
github.com/mattn/go-sqlite3 v1.14.8 h1:gDp86IdQsN/xWjIEmr9MF6o9mpksUgh0fu+9ByFxzIU=
github.com/mattn/go-sqlite3 v1.14.8/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=

BIN
godo.db

Binary file not shown.

31
main.go

@ -0,0 +1,31 @@
package main
import (
"fmt"
"flag"
)
func main() {
initDb := flag.Bool("init", false, "Init a new DB - this will delete all existing tasks")
addTask := flag.String("add", "", "Add a new task to your list")
rmTask := flag.Int("rm", 0, "Removes a task from your list")
lsTask := flag.Bool("ls", false, "List all tasks")
flag.Parse()
fmt.Println("add:", *addTask)
fmt.Println("rm:", *rmTask)
fmt.Println("ls:", *lsTask)
fmt.Println("init:", *initDb)
fmt.Println("tail:", flag.Args())
if *initDb == true {
InitDb()
}
if *lsTask == true {
LsTask()
}
}
Loading…
Cancel
Save