master
Elis Axelsson 2016-04-27 16:13:28 +02:00
parent 6e0a6c296a
commit 95f5d5be4d
2 changed files with 36 additions and 0 deletions

1
.gitignore vendored
View File

@ -2,4 +2,5 @@ pkg/
src/github.com/
src/gopkg.in
worstcaptcha.gcfg
worstcaptcha.db
images/

35
src/WorstCaptcha/Db.go Normal file
View File

@ -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}
}