feat: Create collection file for routes
This commit is contained in:
30
database/connection.go
Normal file
30
database/connection.go
Normal 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
|
||||
}
|
Reference in New Issue
Block a user