From 95f5d5be4d63a263147d977d21d7a16e5dcf4324 Mon Sep 17 00:00:00 2001 From: Elis Axelsson Date: Wed, 27 Apr 2016 16:13:28 +0200 Subject: [PATCH] Added db --- .gitignore | 1 + src/WorstCaptcha/Db.go | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 src/WorstCaptcha/Db.go diff --git a/.gitignore b/.gitignore index 1a03a5b..e90fb8a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ pkg/ src/github.com/ src/gopkg.in worstcaptcha.gcfg +worstcaptcha.db images/ diff --git a/src/WorstCaptcha/Db.go b/src/WorstCaptcha/Db.go new file mode 100644 index 0000000..b76a5d2 --- /dev/null +++ b/src/WorstCaptcha/Db.go @@ -0,0 +1,35 @@ +package WorstCaptcha + +import ( + "os" + "fmt" + "database/sql" + _ "github.com/mattn/go-sqlite3" +) + +type Db struct { + client *sql.DB +} + +func NewDb() Db { + dir, _ := os.Getwd() + + db, err := sql.Open("sqlite3", dir + "/worstcaptcha.db") + + if err != nil { + fmt.Println("Failed to open database:", err) + + os.Exit(1) + } + + db.Exec(` + CREATE TABLE IF NOT EXISTS ( + "id" integer NOT NULL PRIMARY KEY, + "word" text, + "identifier" text, + "added" datetime + ); + `) + + return Db{db} +}