package dbschema

import (
	// External
	"github.com/jackc/pgx/v5/pgxpool"

	// Standard
	"context"
	"fmt"
)

func newDatabase(host string, port int, dbName, user, pass string) (dbase Database, err error) {// {{{
	dbase.Host = host
	dbase.Port = port
	dbase.DbName = dbName
	dbase.Username = user
	dbase.Password = pass

	dbase.db, err = pgxpool.New(context.Background(), dbase.sqlConnString())
	return
}// }}}
func databaseFromInstance(db *pgxpool.Pool) (dbase Database, err error) {
	dbase.db = db
	return
}

func (dbase Database) sqlConnString() string {// {{{
	return fmt.Sprintf(
		"host=%s port=%d user=%s password=%s dbname=%s sslmode=disable",
		dbase.Host,
		dbase.Port,
		dbase.Username,
		dbase.Password,
		dbase.DbName,
	)
}// }}}

// vim: foldmethod=marker
