-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add a trigger for sload update notification (#328)
* chore: add a trigger for sload update notification * chore: add triggers into default schema * fix typo * fix: trigger query * lint
- Loading branch information
1 parent
99c5ab3
commit efb3268
Showing
3 changed files
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
CREATE OR REPLACE FUNCTION sload_cache_notify() | ||
RETURNS trigger AS | ||
$$ | ||
BEGIN | ||
PERFORM pg_notify( | ||
'sload_cache_channel', | ||
json_build_object( | ||
'index', encode(NEW.idx, 'hex'), | ||
'value', encode(NEW.value, 'hex'), | ||
'address', encode(NEW.account_address, 'hex'), | ||
'block', NEW.creation_block | ||
)::text | ||
); | ||
RETURN NEW; | ||
END; | ||
$$ LANGUAGE plpgsql; | ||
|
||
CREATE TRIGGER sload_cache | ||
AFTER INSERT OR UPDATE | ||
ON account_slots | ||
FOR EACH ROW | ||
EXECUTE PROCEDURE sload_cache_notify(); |