expose sql.DB to let orm operate on it (#1015)

* expose sql.DB to let orm operate on it

* add missing RawDB methods

* add NewSqlConnFromDB for cooperate with dtm
This commit is contained in:
Kevin Wan
2021-09-09 11:40:28 +08:00
committed by GitHub
parent 56807aabf6
commit f6d9e19ecb
6 changed files with 61 additions and 10 deletions

View File

@@ -21,12 +21,15 @@ func TestSqlConn(t *testing.T) {
mock.ExpectExec("any")
mock.ExpectQuery("any").WillReturnRows(sqlmock.NewRows([]string{"foo"}))
conn := NewMysql(mockedDatasource)
db, err := conn.RawDB()
assert.Nil(t, err)
rawConn := NewSqlConnFromDB(db, withMysqlAcceptable())
badConn := NewMysql("badsql")
_, err := conn.Exec("any", "value")
_, err = conn.Exec("any", "value")
assert.NotNil(t, err)
_, err = badConn.Exec("any", "value")
assert.NotNil(t, err)
_, err = conn.Prepare("any")
_, err = rawConn.Prepare("any")
assert.NotNil(t, err)
_, err = badConn.Prepare("any")
assert.NotNil(t, err)