Skip to content

Commit 8228b07

Browse files
committed
Add trigger callbacks
1 parent 2266cd7 commit 8228b07

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

sql/core.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,7 @@ type TriggerDefinition struct {
820820
Name string // The name of this trigger. Trigger names in a database are unique.
821821
CreateStatement string // The text of the statement to create this trigger.
822822
CreatedAt time.Time // The time that the trigger was created.
823+
Callback func() // Optional Go callback invoked after each row the trigger fires on. Not persisted.
823824
}
824825

825826
// TriggerDatabase is a Database that supports the creation and execution of triggers. The engine handles all parsing

sql/plan/trigger.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,15 @@ func (t *triggerIter) Next(ctx *sql.Context) (row sql.Row, returnErr error) {
172172
// For some logic statements, we want to return the result of the logic operation as our row, e.g. a Set that alters
173173
// the fields of the new row
174174
if ok, returnRow := shouldUseLogicResult(logic, logicRow); ok {
175+
if t.TriggerDefinition.Callback != nil {
176+
t.TriggerDefinition.Callback()
177+
}
175178
return returnRow, nil
176179
}
177180

181+
if t.TriggerDefinition.Callback != nil {
182+
t.TriggerDefinition.Callback()
183+
}
178184
return childRow, nil
179185
}
180186

0 commit comments

Comments
 (0)