feat: support using session to execute statements in transaction (#3252)
This commit is contained in:
@@ -11,9 +11,6 @@ import (
|
||||
// spanName is used to identify the span name for the SQL execution.
|
||||
const spanName = "sql"
|
||||
|
||||
// ErrNotFound is an alias of sql.ErrNoRows
|
||||
var ErrNotFound = sql.ErrNoRows
|
||||
|
||||
type (
|
||||
// Session stands for raw connections or transaction sessions
|
||||
Session interface {
|
||||
@@ -131,6 +128,13 @@ func NewSqlConnFromDB(db *sql.DB, opts ...SqlOption) SqlConn {
|
||||
return conn
|
||||
}
|
||||
|
||||
// NewSqlConnFromSession returns a SqlConn with the given session.
|
||||
func NewSqlConnFromSession(session Session) SqlConn {
|
||||
return txConn{
|
||||
Session: session,
|
||||
}
|
||||
}
|
||||
|
||||
func (db *commonSqlConn) Exec(q string, args ...any) (result sql.Result, err error) {
|
||||
return db.ExecCtx(context.Background(), q, args...)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user