goblog/db/db.go
2024-12-07 17:45:46 -05:00

19 lines
No EOL
427 B
Go

package db
import (
"database/sql"
_ "github.com/lib/pq"
"log"
)
// Replace the "connStr" string with your DB connection username and password.
func ConnectDB() (*sql.DB, error) {
connStr := "user=username password=password123 dbname=cooldatabase sslmode=disable"
db, err := sql.Open("postgres", connStr)
if err != nil {
log.Fatalf("Failed to connect to the database: %v", err)
return nil, err
}
return db, nil
}