2019-10-09 14:13:59 +07:00
|
|
|
package main
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
2019-10-10 12:35:53 +07:00
|
|
|
_, err = db.Exec("CREATE TABLE IF NOT EXISTS vote (id INTEGER PRIMARY KEY, messageId TEXT, name TEXT, type TEXT, finished BOOLEAN, UNIQUE(id))")
|
2019-10-10 10:38:30 +07:00
|
|
|
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)
|
|
|
|
}
|
2019-10-09 14:13:59 +07:00
|
|
|
}
|