MCPcopy Create free account
hub / github.com/subquery/subql / createNotifyTrigger

Function createNotifyTrigger

packages/node-core/src/db/sync-helper.ts:242–256  ·  view source on GitHub ↗
(schema: string, table: string)

Source from the content-addressed store, hash-verified

240}
241
242export function createNotifyTrigger(schema: string, table: string): string {
243 const triggerName = hashName(schema, 'notify_trigger', table);
244 const channelName = hashName(schema, 'notify_channel', table);
245 return `
246DO $$
247BEGIN
248 CREATE TRIGGER "${triggerName}" AFTER INSERT OR UPDATE OR DELETE
249 ON "${schema}"."${table}"
250 FOR EACH ROW EXECUTE FUNCTION "${schema}".send_notification('${channelName}');
251EXCEPTION
252 WHEN duplicate_object THEN
253 RAISE NOTICE 'Trigger already exists. Ignoring...';
254END$$;
255 `;
256}
257
258function dropTrigger(schema: string, table: string, triggerName: string): string {
259 return `DROP TRIGGER IF EXISTS "${triggerName}"

Callers 2

Calls 1

hashNameFunction · 0.90

Tested by

no test coverage detected