v0.0.519
Some checks failed
Build Docker and Deploy / Run goext test-suite (push) Has been cancelled

This commit is contained in:
Mike Schwörer 2024-10-05 00:58:15 +02:00
parent f6b47792a4
commit dc6cb274ee
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
4 changed files with 41 additions and 33 deletions

View File

@ -1,5 +1,5 @@
package goext
const GoextVersion = "0.0.518"
const GoextVersion = "0.0.519"
const GoextVersionTimestamp = "2024-10-05T00:45:55+0200"
const GoextVersionTimestamp = "2024-10-05T00:58:15+0200"

View File

@ -172,7 +172,7 @@ func (db *database) BeginTransaction(ctx context.Context, iso sql.IsolationLevel
return nil, exerr.Wrap(err, "Failed to start sql transaction").Build()
}
return NewTransaction(xtx, txid, db), nil
return newTransaction(ctx, xtx, txid, db), nil
}
func (db *database) Exit() error {

View File

@ -9,12 +9,15 @@ type PrePingMeta struct {
}
type PreTxBeginMeta struct {
ConstructorContext context.Context
}
type PreTxCommitMeta struct {
ConstructorContext context.Context
}
type PreTxRollbackMeta struct {
ConstructorContext context.Context
}
type PreQueryMeta struct {
@ -30,25 +33,28 @@ type PostPingMeta struct {
}
type PostTxBeginMeta struct {
Init time.Time
Start time.Time
End time.Time
ConstructorContext context.Context
Init time.Time
Start time.Time
End time.Time
}
type PostTxCommitMeta struct {
Init time.Time
Start time.Time
End time.Time
ExecCounter int
QueryCounter int
ConstructorContext context.Context
Init time.Time
Start time.Time
End time.Time
ExecCounter int
QueryCounter int
}
type PostTxRollbackMeta struct {
Init time.Time
Start time.Time
End time.Time
ExecCounter int
QueryCounter int
ConstructorContext context.Context
Init time.Time
Start time.Time
End time.Time
ExecCounter int
QueryCounter int
}
type PostQueryMeta struct {

View File

@ -27,22 +27,24 @@ type Tx interface {
}
type transaction struct {
tx *sqlx.Tx
id uint16
status TxStatus
execCtr int
queryCtr int
db *database
constructorContext context.Context
tx *sqlx.Tx
id uint16
status TxStatus
execCtr int
queryCtr int
db *database
}
func NewTransaction(xtx *sqlx.Tx, txid uint16, db *database) Tx {
func newTransaction(ctx context.Context, xtx *sqlx.Tx, txid uint16, db *database) Tx {
return &transaction{
tx: xtx,
id: txid,
status: TxStatusInitial,
execCtr: 0,
queryCtr: 0,
db: db,
constructorContext: ctx,
tx: xtx,
id: txid,
status: TxStatusInitial,
execCtr: 0,
queryCtr: 0,
db: db,
}
}
@ -50,7 +52,7 @@ func (tx *transaction) Rollback() error {
t0 := time.Now()
preMeta := PreTxRollbackMeta{}
preMeta := PreTxRollbackMeta{ConstructorContext: tx.constructorContext}
for _, v := range tx.db.lstr {
err := v.PreTxRollback(tx.id, preMeta)
if err != nil {
@ -66,7 +68,7 @@ func (tx *transaction) Rollback() error {
tx.status = TxStatusRollback
}
postMeta := PostTxRollbackMeta{Init: t0, Start: t1, End: time.Now(), ExecCounter: tx.execCtr, QueryCounter: tx.queryCtr}
postMeta := PostTxRollbackMeta{ConstructorContext: tx.constructorContext, Init: t0, Start: t1, End: time.Now(), ExecCounter: tx.execCtr, QueryCounter: tx.queryCtr}
for _, v := range tx.db.lstr {
v.PostTxRollback(tx.id, result, postMeta)
}
@ -78,7 +80,7 @@ func (tx *transaction) Commit() error {
t0 := time.Now()
preMeta := PreTxCommitMeta{}
preMeta := PreTxCommitMeta{ConstructorContext: tx.constructorContext}
for _, v := range tx.db.lstr {
err := v.PreTxCommit(tx.id, preMeta)
if err != nil {
@ -94,7 +96,7 @@ func (tx *transaction) Commit() error {
tx.status = TxStatusComitted
}
postMeta := PostTxCommitMeta{Init: t0, Start: t1, End: time.Now(), ExecCounter: tx.execCtr, QueryCounter: tx.queryCtr}
postMeta := PostTxCommitMeta{ConstructorContext: tx.constructorContext, Init: t0, Start: t1, End: time.Now(), ExecCounter: tx.execCtr, QueryCounter: tx.queryCtr}
for _, v := range tx.db.lstr {
v.PostTxCommit(tx.id, result, postMeta)
}