diff options
| author | Eugene Triguba <eugenetriguba@gmail.com> | 2024-01-06 16:23:02 -0500 |
|---|---|---|
| committer | Eugene Triguba <eugenetriguba@gmail.com> | 2024-01-06 16:23:02 -0500 |
| commit | 263ce3e4b368a50efee1a53af11a76a12af0a119 (patch) | |
| tree | 8917754f3b43830604f6ad4c7115934ed633f1d8 /internal/storage/storage.go | |
| parent | Fix syntax (diff) | |
| download | cli-263ce3e4b368a50efee1a53af11a76a12af0a119.zip | |
Break up migration repo into fs and db with a service
Diffstat (limited to 'internal/storage/storage.go')
| -rw-r--r-- | internal/storage/storage.go | 41 |
1 files changed, 0 insertions, 41 deletions
diff --git a/internal/storage/storage.go b/internal/storage/storage.go deleted file mode 100644 index 25db283..0000000 --- a/internal/storage/storage.go +++ /dev/null @@ -1,41 +0,0 @@ -package storage - -import ( - "database/sql" - "fmt" - - "github.com/eugenetriguba/bolt/internal/configloader" - _ "github.com/lib/pq" -) - -// DBConnect establishes a connection to the database using the driver -// and connection information. -// -// Note that only "postgres" is supported as the driver right now. -func DBConnect(driver string, connectionInfo string) (*sql.DB, error) { - db, err := sql.Open(driver, connectionInfo) - if err != nil { - return nil, err - } - - // Note: `sql.Open` only validates the connection string we provided - // it is sane. It doesn't actually open up a connection to the database. - // For that, we ping the database to ensure the connection string is fully - // valid. - err = db.Ping() - if err != nil { - return nil, err - } - - return db, nil -} - -// DBConnectionString generates a properly formatted connection -// string that can be used to establish a database connection. -// Note that it always creates a connection string with sslmode disabled. -func DBConnectionString(cfg *configloader.ConnectionConfig) string { - return fmt.Sprintf( - "host=%s port=%d user=%s password=%s dbname=%s sslmode=disable", - cfg.Host, cfg.Port, cfg.User, cfg.Password, cfg.DBName, - ) -} |