Skip to content

Commit

Permalink
Merge pull request #5 from kodefluence/add-eject-method
Browse files Browse the repository at this point in the history
Adding method to eject real database
  • Loading branch information
insomnius authored Dec 1, 2022
2 parents 17239a4 + c4edeb6 commit ba5b1b0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions db/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,8 @@ func runWithSQLAnalyzer(ktx kontext.Context, executionLevel, function string, f
}
return nil
}

// Eject sql.DB out of db adapter
func (a *Adapter) Eject() *sql.DB {
return a.db
}
10 changes: 10 additions & 0 deletions db/adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ func TestAdapter(t *testing.T) {
})
})

t.Run("Eject", func(t *testing.T) {
t.Run("When ejected it return *sql.DB instance", func(t *testing.T) {
sqldb, _, _ := sqlmock.New(sqlmock.MonitorPingsOption(true))
defer sqldb.Close()

sql := db.Adapt(sqldb)
assert.Equal(t, sqldb, sql.Eject())
})
})

t.Run("QueryRowContext", func(t *testing.T) {
t.Run("When querying done it will return db.Row and scan the value", func(t *testing.T) {

Expand Down
3 changes: 3 additions & 0 deletions db/db.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package db

import (
"database/sql"

"github.com/kodefluence/monorepo/exception"
"github.com/kodefluence/monorepo/kontext"
)
Expand All @@ -12,6 +14,7 @@ type DB interface {
Ping(ktx kontext.Context) exception.Exception
Transactionable
TX
Eject() *sql.DB
}

// Transactionable is wrapper to create transaction process
Expand Down

0 comments on commit ba5b1b0

Please sign in to comment.