Skip to content

Commit

Permalink
Merge pull request #24 from thara/support_mysql_savepoint
Browse files Browse the repository at this point in the history
Support nested transaction for MySQL driver
  • Loading branch information
skateinmars authored Jun 30, 2023
2 parents 6756091 + bc8fac5 commit 07864c1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion sqalx.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ type Option func(*node) error
func SavePoint(enabled bool) Option {
return func(n *node) error {
driverName := n.Driver.DriverName()
if enabled && driverName != "postgres" && driverName != "sqlite3" {
if enabled && driverName != "postgres" && driverName != "sqlite3" && driverName != "mysql" {
return ErrIncompatibleOption
}
n.savePointEnabled = enabled
Expand Down
24 changes: 12 additions & 12 deletions sqalx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@ func TestSqalxConnectMySQL(t *testing.T) {
}

testSqalxConnect(t, "mysql", dataSource)

node, err := sqalx.Connect("mysql", dataSource, sqalx.SavePoint(true))
require.Equal(t, sqalx.ErrIncompatibleOption, err)
require.Nil(t, node)
testSqalxConnect(t, "mysql", dataSource, sqalx.SavePoint(true))
}

func testSqalxConnect(t *testing.T, driverName, dataSource string, options ...sqalx.Option) {
Expand Down Expand Up @@ -132,19 +129,22 @@ func TestSqalxTopLevelTransaction(t *testing.T) {
}

func TestSqalxNestedTransactions(t *testing.T) {
testSqalxNestedTransactions(t, false)
testSqalxNestedTransactions(t, "mock", false)
}

func TestSqalxNestedTransactionsWithSavePoint(t *testing.T) {
testSqalxNestedTransactions(t, true)
}

func testSqalxNestedTransactions(t *testing.T, testSavePoint bool) {
driverName := "mock"
if testSavePoint {
driverName = "postgres"
for _, driver := range []string{
"postgres",
"sqlite3",
"mysql",
} {
t.Run(driver, func(t *testing.T) {
testSqalxNestedTransactions(t, driver, true)
})
}
}

func testSqalxNestedTransactions(t *testing.T, driverName string, testSavePoint bool) {
db, mock, cleanup := prepareDB(t, driverName)
defer cleanup()

Expand Down

0 comments on commit 07864c1

Please sign in to comment.