vanity-tester-backend-go/cmd/vanity-tester-backend/database.go

30 lines
901 B
Go
Raw Permalink Normal View History

2024-12-27 14:04:18 -03:00
package main
import (
"database/sql"
)
2025-01-08 20:16:19 -03:00
func createDb(db *sql.DB) error {
2024-12-27 14:04:18 -03:00
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 {
2025-01-08 20:16:19 -03:00
return err
2024-12-27 14:04:18 -03:00
}
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 {
2025-01-08 20:16:19 -03:00
_, err = db.Exec(query)
2024-12-27 14:04:18 -03:00
if err != nil {
2025-01-08 20:16:19 -03:00
return err
2024-12-27 14:04:18 -03:00
}
}
}
2025-01-08 20:16:19 -03:00
return nil
2024-12-27 14:04:18 -03:00
}