Move responsibility for importing Colors
This commit is contained in:
parent
256b6e96f2
commit
f09472a505
|
@ -1,9 +1,40 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"log"
|
||||
)
|
||||
|
||||
func populateColorTable(db *sql.DB) {
|
||||
query := `INSERT INTO Color (Name, Abbreviation) VALUES (?, ?);`
|
||||
|
||||
insert, err := db.Prepare(query)
|
||||
defer insert.Close()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
colors := map[string]string{
|
||||
"White": "W",
|
||||
"Blue": "U",
|
||||
"Black": "B",
|
||||
"Red": "R",
|
||||
"Green": "G",
|
||||
}
|
||||
for name, abbrev := range colors {
|
||||
// TODO: Don't import a color if it's already in the database
|
||||
result, err := insert.Exec(name, abbrev)
|
||||
rowsAffected, err := result.RowsAffected()
|
||||
if err != nil || rowsAffected != 1 {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
// Import colors
|
||||
// populateColorTable(db)
|
||||
// Import sets
|
||||
// Import keywords
|
||||
// Import formats
|
||||
|
|
|
@ -81,31 +81,6 @@ func createColorTable(db *sql.DB) {
|
|||
}
|
||||
}
|
||||
|
||||
func populateColorTable(db *sql.DB) {
|
||||
query := `INSERT INTO Color (Name, Abbreviation) VALUES (?, ?);`
|
||||
|
||||
insert, err := db.Prepare(query)
|
||||
defer insert.Close()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
colors := map[string]string{
|
||||
"White": "W",
|
||||
"Blue": "U",
|
||||
"Black": "B",
|
||||
"Red": "R",
|
||||
"Green": "G",
|
||||
}
|
||||
for name, abbrev := range colors {
|
||||
result, err := insert.Exec(name, abbrev)
|
||||
rowsAffected, err := result.RowsAffected()
|
||||
if err != nil || rowsAffected != 1 {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func createGamepieceColorTable(db *sql.DB) {
|
||||
query := `CREATE TABLE IF NOT EXISTS GamepieceColor (
|
||||
ColorId INT,
|
||||
|
@ -269,7 +244,6 @@ func createCardPrintingTable(db *sql.DB) {
|
|||
func CreateDatabaseSchema(db *sql.DB) {
|
||||
createGamepieceTable(db)
|
||||
createColorTable(db)
|
||||
populateColorTable(db)
|
||||
createGamepieceColorTable(db)
|
||||
createGamepieceColorIdentityTable(db)
|
||||
createGamepieceColorIndicatorTable(db)
|
||||
|
|
Loading…
Reference in New Issue