Added dbschema
This commit is contained in:
parent
b7595b4c7b
commit
1c697a028b
4 changed files with 300 additions and 4 deletions
38
dbschema/database.go
Normal file
38
dbschema/database.go
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue