diff options
author | Matthew Lemon <lemon@matthewlemon.com> | 2020-07-18 21:02:41 +0100 |
---|---|---|
committer | Matthew Lemon <lemon@matthewlemon.com> | 2020-07-18 21:02:41 +0100 |
commit | 1db96177350b8d785be2728f3d44907c8998d7b0 (patch) | |
tree | 60290a3f40cbc2d03f636f2fe6f5fe33559a1558 /db/setup.go | |
parent | 91929328acd4dbb6bf1eaf9178fe68e1433ad0be (diff) |
moved db stuff to new package
Diffstat (limited to '')
-rw-r--r-- | db/setup.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/db/setup.go b/db/setup.go new file mode 100644 index 0000000..5cd1041 --- /dev/null +++ b/db/setup.go @@ -0,0 +1,27 @@ +package db + +import ( + "database/sql" + "errors" + "log" + "os" + + _ "github.com/mattn/go-sqlite3" +) + +func SetupDB(path string) (*sql.DB, error) { + os.Create(path) + db, err := sql.Open("sqlite3", path) + if err != nil { + return db, errors.New("Cannot open that damn database file") + } + stmt := `drop table if exists datamap; + create table datamap(id integer no null primary key, name text); + ` + _, err = db.Exec(stmt) + if err != nil { + log.Printf("%q: %s\n", err, stmt) + } + + return db, nil +} |