diff options
| author | Eugene Triguba <eugenetriguba@gmail.com> | 2024-01-06 11:15:53 -0500 |
|---|---|---|
| committer | Eugene Triguba <eugenetriguba@gmail.com> | 2024-01-06 11:15:53 -0500 |
| commit | 3d66d23b7f1f8d496711f01a164ac1d7717527ca (patch) | |
| tree | b4ce8a4deda41c57b1ab13ac4e89bfb9e6978cf0 /internal/db/db.go | |
| parent | Add to changelog (diff) | |
| download | cli-3d66d23b7f1f8d496711f01a164ac1d7717527ca.zip | |
Add database integration tests
Diffstat (limited to 'internal/db/db.go')
| -rw-r--r-- | internal/db/db.go | 48 |
1 files changed, 0 insertions, 48 deletions
diff --git a/internal/db/db.go b/internal/db/db.go deleted file mode 100644 index 3927681..0000000 --- a/internal/db/db.go +++ /dev/null @@ -1,48 +0,0 @@ -package db - -import ( - "database/sql" - "fmt" - - "github.com/eugenetriguba/bolt/internal/configloader" - _ "github.com/lib/pq" -) - -var db *sql.DB - -// Connect to the database using the driver and connection -// parameter that are specified in the bolt configuration file. -// -// Note that subsequent calls to Connect return the same database -// handle. -func Connect() (*sql.DB, error) { - if db == nil { - config, err := configloader.NewConfig() - if err != nil { - return nil, err - } - - connInfo := fmt.Sprintf( - "host=%s port=%d user=%s password=%s dbname=%s sslmode=disable", - config.Connection.Host, config.Connection.Port, config.Connection.User, - config.Connection.Password, config.Connection.DBName, - ) - newDb, err := sql.Open(config.Connection.Driver, connInfo) - 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 = newDb.Ping() - if err != nil { - return nil, err - } - - db = newDb - } - - return db, nil -} |