github.com/blend/go-sdk@v1.20220411.3/db/dbutil/open_management_connection.go (about)

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