@@ -35,11 +35,12 @@ func (d *mockDriver) Open(dsn string) (driver.Conn, error) {
3535 return c , nil
3636}
3737
38- // New creates sqlmock database connection
39- // and a mock to manage expectations.
38+ // New creates sqlmock database connection and a mock to manage expectations.
39+ // Accepts options, like ValueConverterOption, to use a ValueConverter from
40+ // a specific driver.
4041// Pings db so that all expectations could be
4142// asserted.
42- func New () (* sql.DB , Sqlmock , error ) {
43+ func New (options ... func ( * sqlmock ) error ) (* sql.DB , Sqlmock , error ) {
4344 pool .Lock ()
4445 dsn := fmt .Sprintf ("sqlmock_db_%d" , pool .counter )
4546 pool .counter ++
@@ -48,11 +49,13 @@ func New() (*sql.DB, Sqlmock, error) {
4849 pool .conns [dsn ] = smock
4950 pool .Unlock ()
5051
51- return smock .open ()
52+ return smock .open (options )
5253}
5354
54- // NewWithDSN creates sqlmock database connection
55- // with a specific DSN and a mock to manage expectations.
55+ // NewWithDSN creates sqlmock database connection with a specific DSN
56+ // and a mock to manage expectations.
57+ // Accepts options, like ValueConverterOption, to use a ValueConverter from
58+ // a specific driver.
5659// Pings db so that all expectations could be asserted.
5760//
5861// This method is introduced because of sql abstraction
@@ -64,7 +67,7 @@ func New() (*sql.DB, Sqlmock, error) {
6467//
6568// It is not recommended to use this method, unless you
6669// really need it and there is no other way around.
67- func NewWithDSN (dsn string ) (* sql.DB , Sqlmock , error ) {
70+ func NewWithDSN (dsn string , options ... func ( * sqlmock ) error ) (* sql.DB , Sqlmock , error ) {
6871 pool .Lock ()
6972 if _ , ok := pool .conns [dsn ]; ok {
7073 pool .Unlock ()
@@ -74,5 +77,5 @@ func NewWithDSN(dsn string) (*sql.DB, Sqlmock, error) {
7477 pool .conns [dsn ] = smock
7578 pool .Unlock ()
7679
77- return smock .open ()
80+ return smock .open (options )
7881}
0 commit comments