aboutsummaryrefslogtreecommitdiffstats
path: root/db/setup.go
blob: 5cd1041010a1c175bcb4953f236591f46b0ffae0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
}