Skip to content

Commit

Permalink
Merge pull request #30 from smallstep/mariano/driver
Browse files Browse the repository at this point in the history
Add method to return the driver name
  • Loading branch information
maraino authored Jun 21, 2024
2 parents c9d70d9 + 54efd68 commit 3b40c5c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions sequel.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type DB struct {
db *sqlx.DB
clock clock.Clock
doRebindModel bool
driverName string
}

type options struct {
Expand Down Expand Up @@ -83,6 +84,7 @@ func New(dataSourceName string, opts ...Option) (*DB, error) {
db: db,
clock: options.Clock,
doRebindModel: options.RebindModel,
driverName: options.DriverName,
}, nil
}

Expand Down Expand Up @@ -141,6 +143,11 @@ func (d *DB) Close() error {
return d.db.Close()
}

// Driver returns the name of the driver used.
func (d *DB) Driver() string {
return d.driverName
}

// Rebind transforms a query from `?` to the DB driver's bind type.
func (d *DB) Rebind(query string) string {
return d.db.Rebind(query)
Expand Down
12 changes: 12 additions & 0 deletions sequel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -841,3 +841,15 @@ func TestDB_Rebind(t *testing.T) {
})
}
}

func TestDB_Driver(t *testing.T) {
db, err := New(postgresDataSource)
require.NoError(t, err)
assert.Equal(t, "pgx/v5", db.Driver())
assert.NoError(t, db.Close())

db, err = New(postgresDataSource, WithDriver("pgx/v5"))
require.NoError(t, err)
assert.Equal(t, "pgx/v5", db.Driver())
assert.NoError(t, db.Close())
}

0 comments on commit 3b40c5c

Please sign in to comment.