Version zu Ende April 2023
This commit is contained in:
58
postgres/postgres.go
Normal file
58
postgres/postgres.go
Normal file
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
= Creative Commons Lizenzvertrag =
|
||||
Diese Software ist von der archium GmbH, Gera ist lizenziert unter einer Creative Commons Namensnennung - Nicht kommerziell - Keine Bearbeitungen 4.0 International Lizenz. (http://creativecommons.org/licenses/by-nc-nd/4.0/deed.de)
|
||||
Individuelle über diese Lizenz hinausgehende Berechtigungen können Sie unter https://archium.org erhalten.
|
||||
|
||||
= Creative Commons License =
|
||||
Software by archium GmbH, Gera is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. (http://creativecommons.org/licenses/by-nc-nd/4.0/)
|
||||
Individual permissions beyond the scope of this license may be available at https://archium.org.
|
||||
**/
|
||||
|
||||
package postgres
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
// "log"
|
||||
// "strings"
|
||||
|
||||
def "Toolbox/defaults"
|
||||
sql "database/sql"
|
||||
)
|
||||
|
||||
var expdb *sql.DB
|
||||
|
||||
// #############################################################################
|
||||
// get - sql connection
|
||||
// #############################################################################
|
||||
func GetConnection() (*sql.DB, error) {
|
||||
psqlInfo := fmt.Sprintf(def.DEF_coninfo, def.DEF_dbhost, def.DEF_dbport, def.DEF_dbuser, def.DEF_dbpassword, def.DEF_dbname)
|
||||
conn, err := sql.Open("postgres", psqlInfo)
|
||||
//log.Println("GetConnection:", psqlInfo, conn, err)
|
||||
if err != nil {
|
||||
def.LogError("GetConnection()", err)
|
||||
return nil, err
|
||||
}
|
||||
return conn, nil
|
||||
}
|
||||
|
||||
// #############################################################################
|
||||
// close - sql connection
|
||||
// #############################################################################
|
||||
func CloseConnection(_conn *sql.DB) error {
|
||||
var err error = nil
|
||||
if _conn != nil {
|
||||
err = _conn.Close()
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// #############################################################################
|
||||
// ping - sql connection
|
||||
// #############################################################################
|
||||
func PingConnection(_conn *sql.DB) error {
|
||||
var err error = nil
|
||||
if _conn != nil {
|
||||
err = _conn.Ping()
|
||||
}
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user