package db import ( "database/sql" "errors" //Import this driver to be used by the SQL package. _ "github.com/mattn/go-sqlite3" ) var db *sql.DB var ErrNotFound = errors.New("db: the requested entry was not found") var ErrAlreadyExists = errors.New("db: attempting to write to an entry that already exists") func init() { var err error db, err = sql.Open("sqlite3", "terraocean.db") if err != nil { panic(err) } _, err = db.Exec("CREATE TABLE IF NOT EXISTS invite (code TEXT, owner TEXT, used BOOLEAN)") if err != nil { panic(err) } _, err = db.Exec("CREATE TABLE IF NOT EXISTS vote (id INTEGER PRIMARY KEY, messageId TEXT, name TEXT, type TEXT, finished BOOLEAN, UNIQUE(id))") if err != nil { panic(err) } _, err = db.Exec("CREATE TABLE IF NOT EXISTS choices (voteId INTEGER, userId INTEGER, date TIMEDATE, value INTEGER, UNIQUE(voteId, userId))") if err != nil { panic(err) } _, err = db.Exec("CREATE TABLE IF NOT EXISTS trustVote (sourceUser INTEGER, targetUser INTEGER, lastUpdated TIMEDATE, trust INTEGER, UNIQUE(sourceUser, targetUser))") if err != nil { panic(err) } }