From 91929328acd4dbb6bf1eaf9178fe68e1433ad0be Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Sat, 18 Jul 2020 20:42:54 +0100 Subject: starting playing around with sqlite3 --- reader/reader.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'reader/reader.go') diff --git a/reader/reader.go b/reader/reader.go index 0aa477f..d99f2a8 100644 --- a/reader/reader.go +++ b/reader/reader.go @@ -1,6 +1,7 @@ package reader import ( + "database/sql" "encoding/csv" "errors" "fmt" @@ -10,6 +11,8 @@ import ( "path/filepath" "strings" + _ "github.com/mattn/go-sqlite3" + "github.com/tealeg/xlsx" "github.com/yulqen/coords" ) @@ -38,6 +41,22 @@ type ExtractedCell struct { Value string } +func SetupDB(path string) (*sql.DB, error) { + 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 +} + //sheetInSlice is a helper which returns true // if a string is in a slice of strings. func sheetInSlice(list []string, key string) bool { -- cgit v1.2.3