v0.0.400 added CommentTrimmer and DBOptions to sq
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 2m16s
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 2m16s
This commit is contained in:
169
sq/listener.go
169
sq/listener.go
@@ -17,3 +17,172 @@ type Listener interface {
|
||||
PostQuery(txID *uint16, sqlOriginal string, sqlReal string, params PP)
|
||||
PostExec(txID *uint16, sqlOriginal string, sqlReal string, params PP)
|
||||
}
|
||||
|
||||
type genListener struct {
|
||||
prePing func(ctx context.Context) error
|
||||
preTxBegin func(ctx context.Context, txid uint16) error
|
||||
preTxCommit func(txid uint16) error
|
||||
preTxRollback func(txid uint16) error
|
||||
preQuery func(ctx context.Context, txID *uint16, sql *string, params *PP) error
|
||||
preExec func(ctx context.Context, txID *uint16, sql *string, params *PP) error
|
||||
postPing func(result error)
|
||||
postTxBegin func(txid uint16, result error)
|
||||
postTxCommit func(txid uint16, result error)
|
||||
postTxRollback func(txid uint16, result error)
|
||||
postQuery func(txID *uint16, sqlOriginal string, sqlReal string, params PP)
|
||||
postExec func(txID *uint16, sqlOriginal string, sqlReal string, params PP)
|
||||
}
|
||||
|
||||
func (g genListener) PrePing(ctx context.Context) error {
|
||||
if g.prePing == nil {
|
||||
return g.prePing(ctx)
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (g genListener) PreTxBegin(ctx context.Context, txid uint16) error {
|
||||
if g.preTxBegin == nil {
|
||||
return g.preTxBegin(ctx, txid)
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (g genListener) PreTxCommit(txid uint16) error {
|
||||
if g.preTxCommit == nil {
|
||||
return g.preTxCommit(txid)
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (g genListener) PreTxRollback(txid uint16) error {
|
||||
if g.preTxRollback == nil {
|
||||
return g.preTxRollback(txid)
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (g genListener) PreQuery(ctx context.Context, txID *uint16, sql *string, params *PP) error {
|
||||
if g.preQuery == nil {
|
||||
return g.preQuery(ctx, txID, sql, params)
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (g genListener) PreExec(ctx context.Context, txID *uint16, sql *string, params *PP) error {
|
||||
if g.preExec == nil {
|
||||
return g.preExec(ctx, txID, sql, params)
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (g genListener) PostPing(result error) {
|
||||
if g.postPing != nil {
|
||||
g.postPing(result)
|
||||
}
|
||||
}
|
||||
|
||||
func (g genListener) PostTxBegin(txid uint16, result error) {
|
||||
if g.postTxBegin != nil {
|
||||
g.postTxBegin(txid, result)
|
||||
}
|
||||
}
|
||||
|
||||
func (g genListener) PostTxCommit(txid uint16, result error) {
|
||||
if g.postTxCommit != nil {
|
||||
g.postTxCommit(txid, result)
|
||||
}
|
||||
}
|
||||
|
||||
func (g genListener) PostTxRollback(txid uint16, result error) {
|
||||
if g.postTxRollback != nil {
|
||||
g.postTxRollback(txid, result)
|
||||
}
|
||||
}
|
||||
|
||||
func (g genListener) PostQuery(txID *uint16, sqlOriginal string, sqlReal string, params PP) {
|
||||
if g.postQuery != nil {
|
||||
g.postQuery(txID, sqlOriginal, sqlReal, params)
|
||||
}
|
||||
}
|
||||
|
||||
func (g genListener) PostExec(txID *uint16, sqlOriginal string, sqlReal string, params PP) {
|
||||
if g.postExec != nil {
|
||||
g.postExec(txID, sqlOriginal, sqlReal, params)
|
||||
}
|
||||
}
|
||||
|
||||
func NewPrePingListener(f func(ctx context.Context) error) Listener {
|
||||
return genListener{prePing: f}
|
||||
}
|
||||
|
||||
func NewPreTxBeginListener(f func(ctx context.Context, txid uint16) error) Listener {
|
||||
return genListener{preTxBegin: f}
|
||||
}
|
||||
|
||||
func NewPreTxCommitListener(f func(txid uint16) error) Listener {
|
||||
return genListener{preTxCommit: f}
|
||||
}
|
||||
|
||||
func NewPreTxRollbackListener(f func(txid uint16) error) Listener {
|
||||
return genListener{preTxRollback: f}
|
||||
}
|
||||
|
||||
func NewPreQueryListener(f func(ctx context.Context, txID *uint16, sql *string, params *PP) error) Listener {
|
||||
return genListener{preQuery: f}
|
||||
}
|
||||
|
||||
func NewPreExecListener(f func(ctx context.Context, txID *uint16, sql *string, params *PP) error) Listener {
|
||||
return genListener{preExec: f}
|
||||
}
|
||||
|
||||
func NewPreListener(f func(ctx context.Context, cmdtype string, txID *uint16, sql *string, params *PP) error) Listener {
|
||||
return genListener{
|
||||
preExec: func(ctx context.Context, txID *uint16, sql *string, params *PP) error {
|
||||
return f(ctx, "EXEC", txID, sql, params)
|
||||
},
|
||||
preQuery: func(ctx context.Context, txID *uint16, sql *string, params *PP) error {
|
||||
return f(ctx, "QUERY", txID, sql, params)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func NewPostPingListener(f func(result error)) Listener {
|
||||
return genListener{postPing: f}
|
||||
}
|
||||
|
||||
func NewPostTxBeginListener(f func(txid uint16, result error)) Listener {
|
||||
return genListener{postTxBegin: f}
|
||||
}
|
||||
|
||||
func NewPostTxCommitListener(f func(txid uint16, result error)) Listener {
|
||||
return genListener{postTxCommit: f}
|
||||
}
|
||||
|
||||
func NewPostTxRollbackListener(f func(txid uint16, result error)) Listener {
|
||||
return genListener{postTxRollback: f}
|
||||
}
|
||||
|
||||
func NewPostQueryListener(f func(txID *uint16, sqlOriginal string, sqlReal string, params PP)) Listener {
|
||||
return genListener{postQuery: f}
|
||||
}
|
||||
|
||||
func NewPostExecListener(f func(txID *uint16, sqlOriginal string, sqlReal string, params PP)) Listener {
|
||||
return genListener{postExec: f}
|
||||
}
|
||||
|
||||
func NewPostListener(f func(cmdtype string, txID *uint16, sqlOriginal string, sqlReal string, params PP)) Listener {
|
||||
return genListener{
|
||||
postExec: func(txID *uint16, sqlOriginal string, sqlReal string, params PP) {
|
||||
f("EXEC", txID, sqlOriginal, sqlReal, params)
|
||||
},
|
||||
postQuery: func(txID *uint16, sqlOriginal string, sqlReal string, params PP) {
|
||||
f("QUERY", txID, sqlOriginal, sqlReal, params)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user