33 lines
535 B
Go
33 lines
535 B
Go
package database
|
|
|
|
import (
|
|
"database/sql"
|
|
"fmt"
|
|
"log"
|
|
|
|
_ "github.com/lib/pq" // Import the PostgreSQL driver
|
|
)
|
|
|
|
const playerTable = `
|
|
CREATE TABLE IF NOT EXISTS players (
|
|
id SERIAL PRIMARY KEY,
|
|
name VARCHAR(100) NOT NULL,
|
|
age INT NOT NULL,
|
|
birthday DATE NOT NULL
|
|
);
|
|
`
|
|
|
|
func InitTables(db *sql.DB) {
|
|
tables := []string{
|
|
playerTable,
|
|
}
|
|
|
|
for _, table := range tables {
|
|
if _, err := db.Exec(table); err != nil {
|
|
log.Fatalf("Error creating table: %v", err)
|
|
}
|
|
}
|
|
|
|
fmt.Println("Tables initialized successfully.")
|
|
}
|