feat: Create collection file for routes

This commit is contained in:
Björn Benouarets
2025-08-11 22:15:32 +02:00
commit f00ecb8155
14 changed files with 482 additions and 0 deletions

30
database/connection.go Normal file
View File

@@ -0,0 +1,30 @@
package database
import (
"database/sql"
"fmt"
_ "github.com/lib/pq"
)
type Connection struct {
Connection *sql.DB
}
func NewConnection(host string, port int, user string, password string, dbName string, sslMode string) *Connection {
psqlInfo := fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=%s", host, port, user, password, dbName, sslMode)
db, err := sql.Open("postgres", psqlInfo)
if err != nil {
panic(err)
}
return &Connection{Connection: db}
}
func (db *Connection) Close() error {
return db.Connection.Close()
}
func (db *Connection) Ping() bool {
fmt.Println("🔥 Pinging database...")
return db.Connection.Ping() == nil
}