upper / db

Data Access Layer (DAL) for PostgreSQL, CockroachDB, MySQL, SQLite and MongoDB with ORM-like features.
https://upper.io/
MIT License
3.54k stars 235 forks source link

[Question]: How to get sql.Tx with orignal database/sql ? #626

Closed BeanWei closed 3 years ago

BeanWei commented 3 years ago

I write a plugin for my project, but I don't want to rely on upper/db.

I need get the tx *sql.Tx from upper db db.Session. How can i do?

gmhafiz commented 2 years ago

For reference, code is in https://github.com/upper/db/blob/cb7617e42999485f9d94c799ae3fb62585600662/session.go#L70

To use

internalSQLDriver := sess.Driver().(*sql.DB)
tx, err := internalSQLDriver.BeginTx(ctx, &sql.TxOptions{
    Isolation: ...
    ReadOnly:  ...,
})