PostgreSQLã®LISTEN/NOTIFYã§JSONãã¼ã¿ãé£ã°ã
PostgreSQLã§ã¯JSON, JSONBãã¼ã¿åã®ãµãã¼ããããã¾ããMySQLã5.7ããããããã§ãã
ã¢ããªã«å¯¾ãã¦ã¡ãã£ã¨ããéç¥ãé£ã°ããããªã£ãã®ã§ãããã¡ãã£ã¨ããéç¥ã®ããã«å¥ã®ããã«ã¦ã§ã¢ãå°å ¥ããã®ã¯æããã«çãæªãã®ã§Postgresã®LISTEN/NOTIFYã使ããã¨ã«ãã¾ããã
Postgresã®LISTEN/NOTIFYã¯textåãã渡ããªãã®ã§ãããã¯æ§é åããããã¼ã¿ããJSONãªã©ã§æ¸¡ããããªãã®ã人æ ã¨ãããã®ã§ãã
以ä¸ã®ãããªTRIGGERã¨
DROP TRIGGER IF EXISTS my_table_inserted ON my_table; CREATE TRIGGER my_table_inserted AFTER INSERT ON my_table FOR EACH ROW EXECUTE PROCEDURE on_my_table_inserted();
以ä¸ã®ãããªFUNCTIONã§äººæ ãéæãã¾ãã
CREATE OR REPLACE FUNCTION on_my_table_inserted() RETURNS trigger AS $$ BEGIN PERFORM pg_notify('my_table_inserted', json_build_object( 'id', NEW.id, 'data_1', NEW.data_1, 'data_2', NEW.data_2 )::text); RETURN NEW; END; $$ LANGUAGE 'plpgsql';
çµå±ã®ã¨ããéã£ã¦ããã®ã¯textåãªã®ã§ãããåãåãå´ã§JSON decodeããã°åé¡ãªãã§ãã
Pythonã§éåæã«éç¥ãåãåãã³ã¼ãã¯å¥è¨äºã«æ¸ãã¾ãã
å®å ¨ã«ä½è«ã§ãããç¾ç¶ã®PipelineDBã§ã¯TRIGGERã¨LISTEN/NOTIFYããã®ããã«çµã¿åããã¦CONTINUOUS VIEWã®æ´æ°éç¥ãåãåããã¨ã¯åºæ¥ã¾ããã CONTINUOUS TRIGGERã®å®ç¾æ¹æ³ãåå ã ã¨æãã®ã§ãããå¤åãã®ãã¡ä½ã¨ããªãã¨æãã¾ãã