go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/sdk/db/dbutil/open_management_connection.go (about) 1 /* 2 3 Copyright (c) 2023 - Present. Will Charczuk. All rights reserved. 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file at the root of the repository. 5 6 */ 7 8 package dbutil 9 10 import ( 11 "go.charczuk.com/sdk/db" 12 ) 13 14 // OpenManagementConnection creates a database connection to the default database (typically postgres). 15 func OpenManagementConnection(options ...db.Option) (*db.Connection, error) { 16 defaults := []db.Option{ 17 db.OptHost("localhost"), 18 db.OptSSLMode("disable"), 19 db.OptConfigFromEnv(), 20 db.OptDatabase("postgres"), 21 } 22 conn, err := db.New( 23 append(defaults, options...)..., 24 ) 25 if err != nil { 26 return nil, err 27 } 28 err = conn.Open() 29 if err != nil { 30 return nil, err 31 } 32 return conn, nil 33 }