Added db
parent
6e0a6c296a
commit
95f5d5be4d
|
@ -2,4 +2,5 @@ pkg/
|
|||
src/github.com/
|
||||
src/gopkg.in
|
||||
worstcaptcha.gcfg
|
||||
worstcaptcha.db
|
||||
images/
|
||||
|
|
|
@ -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…
Reference in New Issue