dbschema/database.go
2023-08-01 17:10:35 +02:00

32 lines
596 B
Go

package dbschema
import (
// Standard
"database/sql"
"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 = sql.Open("postgres", dbase.sqlConnString())
return
}// }}}
func (dbase Database) sqlConnString() string {// {{{
return fmt.Sprintf(
"postgresql://%s:%s@%s:%d/%s?sslmode=disable",
dbase.Username,
dbase.Password,
dbase.Host,
dbase.Port,
dbase.DbName,
)
}// }}}
// vim: foldmethod=marker