Browse Source

Added db

master
Elis Axelsson 6 years ago
parent
commit
95f5d5be4d
  1. 1
      .gitignore
  2. 35
      src/WorstCaptcha/Db.go

1
.gitignore

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

35
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}
}
Loading…
Cancel
Save