TerraOceanPlugin/GoBot/db/db.go

43 lines
1.3 KiB
Go

2019-10-12 08:07:10 +07:00
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
2019-10-12 08:07:10 +07:00
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))")
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-11 14:29:07 +07:00
_, err = db.Exec("CREATE TABLE IF NOT EXISTS trustVote (sourceUser INTEGER, targetUser INTEGER, lastUpdated TIMEDATE, trust INTEGER, UNIQUE(sourceUser, targetUser))")
2019-10-11 12:25:09 +07:00
if err != nil {
panic(err)
}
2019-10-13 09:59:35 +07:00
_, err = db.Exec("CREATE TABLE IF NOT EXISTS minecraftUsername (discordId TEXT, minecraftUsername TEXT, UNIQUE(discordId), UNIQUE(minecraftUsername))")
2019-10-12 15:33:06 +07:00
if err != nil {
panic(err)
}
}