vanity-tester-backend-go/cmd/vanity-tester-backend/database.go
2025-01-08 20:16:19 -03:00

29 lines
901 B
Go

package main
import (
"database/sql"
)
func createDb(db *sql.DB) error {
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 {
return 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 {
return err
}
}
}
return nil
}