2014-03-02 00:02:24 +01:00
|
|
|
package irc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
_ "github.com/mattn/go-sqlite3"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
func InitDB(path string) {
|
|
|
|
os.Remove(path)
|
|
|
|
db := OpenDB(path)
|
|
|
|
defer db.Close()
|
|
|
|
_, err := db.Exec(`
|
|
|
|
CREATE TABLE channel (
|
|
|
|
name TEXT NOT NULL UNIQUE,
|
|
|
|
flags TEXT NOT NULL,
|
|
|
|
key TEXT NOT NULL,
|
|
|
|
topic TEXT NOT NULL,
|
|
|
|
user_limit INTEGER DEFAULT 0)`)
|
|
|
|
if err != nil {
|
2014-03-06 08:07:55 +01:00
|
|
|
log.Fatal("initdb error: ", err)
|
2014-03-02 00:02:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func OpenDB(path string) *sql.DB {
|
|
|
|
db, err := sql.Open("sqlite3", path)
|
|
|
|
if err != nil {
|
2014-03-06 08:07:55 +01:00
|
|
|
log.Fatal("open db error: ", err)
|
2014-03-02 00:02:24 +01:00
|
|
|
}
|
|
|
|
return db
|
|
|
|
}
|