DATA-DOG / go-txdb

Immutable transaction isolated sql driver for golang

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Breaks go's sql driver semantics

bouk opened this issue · comments

https://golang.org/pkg/database/sql/driver/#Driver says that Open's returned connection is only used by one goroutine at a time, but because the txdb Driver returns the same connection multiple times, you can end up in a situation where the same connection is used in multiple concurrent threads of execution.

The only correct thing to do is to return an error/panic if another connection is opened while the connection is already being used. It points to a programming error, for example an sql.Rows not being closed, or the *sql.DB being used while a transaction has started.

Hi, txdb has composite behavior when opening, it will always return same connection if DSN is the same. Change DSN if you want a separate transaction opened.

Currently all the tests in this package changes dsn for each test in order to run them concurrently

I do not care if it breaks the contract, it allows to isolate even production code to run within transaction no matter how many times connection is reopened if dsn is the same. I have created this package for people to efficiently test their code in fuctional or integration tests

Thanks for explaining!