Files

24 lines
677 B
Go

package main
import (
"database/sql"
"fmt"
_ "github.com/lib/pq"
)
//TODO: maybe we can do the whole databaase connection things on application start and panic right away
//if we can't connect to the database.
func getSQLConnection() *sql.DB {
//Note: The postgres driver seems to get confused when no password is supplied, so omit it in the connection sting.
//https://rajyavardhan.medium.com/when-you-get-relation-does-not-exist-in-postgres-7ffb0c3c674b
psqlInfo := fmt.Sprintf("host=%s port=%d user=%s dbname=%s sslmode=disable", "localhost", 5432, "postgres", "inventory")
db, err := sql.Open("postgres", psqlInfo)
if err != nil {
panic(err)
}
return db
}