Browse Source

Added db

master
Elis Axelsson 4 years ago
parent
commit
95f5d5be4d
2 changed files with 36 additions and 0 deletions
  1. +1
    -0
      .gitignore
  2. +35
    -0
      src/WorstCaptcha/Db.go

+ 1
- 0
.gitignore View File

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

+ 35
- 0
src/WorstCaptcha/Db.go 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}
}

Loading…
Cancel
Save