2024-02-10 16:47:14 +00:00
|
|
|
package db
|
|
|
|
|
|
|
|
import (
|
|
|
|
"embed"
|
|
|
|
"fmt"
|
|
|
|
"github.com/jmoiron/sqlx"
|
|
|
|
)
|
|
|
|
|
|
|
|
//go:embed dev/*.sql
|
|
|
|
var DevMigrations embed.FS
|
|
|
|
|
|
|
|
//go:embed prod/*.sql
|
|
|
|
var ProdMigrations embed.FS
|
|
|
|
|
2024-04-01 09:09:54 +00:00
|
|
|
func ConnectToDbNamed(host string, port string, user string, password string, dbname string, sslMode string, schema string) (*sqlx.DB, error) {
|
|
|
|
psqlInfo := fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=%s search_path=%s",
|
|
|
|
host, port, user, password, dbname, sslMode, schema)
|
2024-02-10 16:47:14 +00:00
|
|
|
|
|
|
|
db, err := sqlx.Open("postgres", psqlInfo)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = db.Ping()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return db, nil
|
|
|
|
}
|