30 lines
966 B
Go
30 lines
966 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"database/sql"
|
||
|
"log"
|
||
|
)
|
||
|
|
||
|
func createDb(db *sql.DB) {
|
||
|
var exists bool
|
||
|
// rows := db.QueryRow("SELECT EXISTS (SELECT 1 FROM sqlite_schema WHERE type='table' AND name='seventv_ids') AND EXISTS (SELECT 1 FROM sqlite_schema WHERE type='table' AND name='seventv_ids');")
|
||
|
err := db.QueryRow(`SELECT EXISTS (SELECT 1 FROM sqlite_schema WHERE type='table' AND name='seventv_ids') AND EXISTS (SELECT 1 FROM sqlite_schema WHERE type='table' AND name='seventv_ids');`).Scan(&exists)
|
||
|
if err != nil {
|
||
|
log.Fatal("Query failed: ", err)
|
||
|
}
|
||
|
|
||
|
if !exists {
|
||
|
queries := []string{
|
||
|
`CREATE TABLE IF NOT EXISTS seventv_ids (username TEXT UNIQUE, twitch_id TEXT UNIQUE, seventv_id TEXT UNIQUE);`,
|
||
|
`CREATE TABLE IF NOT EXISTS chatty_ids (username TEXT UNIQUE, twitch_id TEXT UNIQUE);`,
|
||
|
}
|
||
|
|
||
|
for _, query := range queries {
|
||
|
_, err := db.Exec(query)
|
||
|
if err != nil {
|
||
|
log.Fatalf("Failed to create table: %s\nError: %v", query, err)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|