{"id":28355245,"url":"https://github.com/becual/node-pg-notify","last_synced_at":"2025-07-01T03:05:02.853Z","repository":{"id":57100256,"uuid":"125549516","full_name":"becual/node-pg-notify","owner":"becual","description":"NodeJS PostgreSQL pg-notify subscription library","archived":false,"fork":false,"pushed_at":"2018-04-17T20:44:27.000Z","size":192,"stargazers_count":10,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-04T10:03:20.463Z","etag":null,"topics":["nodejs","notify","pg-notify","postgresql","subscription"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/becual.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-16T17:35:34.000Z","updated_at":"2023-09-12T15:11:43.000Z","dependencies_parsed_at":"2022-08-20T21:40:37.397Z","dependency_job_id":null,"html_url":"https://github.com/becual/node-pg-notify","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/becual/node-pg-notify","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/becual%2Fnode-pg-notify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/becual%2Fnode-pg-notify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/becual%2Fnode-pg-notify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/becual%2Fnode-pg-notify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/becual","download_url":"https://codeload.github.com/becual/node-pg-notify/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/becual%2Fnode-pg-notify/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260926985,"owners_count":23083933,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nodejs","notify","pg-notify","postgresql","subscription"],"created_at":"2025-05-28T04:08:54.870Z","updated_at":"2025-07-01T03:05:02.829Z","avatar_url":"https://github.com/becual.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ca name=\"module_pg-notify\"\u003e\u003c/a\u003e\n\n## pg-notify\nConfigure and subscribe to Postgres Notify automatically for a given set of tables.\n\n\n| Param | Type | Default | Description |\n| --- | --- | --- | --- |\n| client | \u003ccode\u003eobject\u003c/code\u003e |  | node-postgres Client instance |\n| configObject | \u003ccode\u003eobject\u003c/code\u003e |  | Configuration object |\n| configObject.schema | \u003ccode\u003estring\u003c/code\u003e | \u003ccode\u003e\u0026quot;public\u0026quot;\u003c/code\u003e | Name of the schema where the tables exists. |\n| configObject.functionName | \u003ccode\u003estring\u003c/code\u003e | \u003ccode\u003e\u0026quot;notify_table_change\u0026quot;\u003c/code\u003e | Name of the function to use notify. |\n| configObject.channelName | \u003ccode\u003estring\u003c/code\u003e | \u003ccode\u003e\u0026quot;notify_table_change_channel\u0026quot;\u003c/code\u003e | Name of the channel where the function will notify. |\n\n\n* [pg-notify](#module_pg-notify)\n    * [~Subscribe to all database events of a given list of tables(tables)](#module_pg-notify..Subscribe to all database events of a given list of tables) ⇒ \u003ccode\u003ePromise\u003c/code\u003e\n    * [~Create the functions and triggers to configure pg-notify.(tables)](#module_pg-notify..Create the functions and triggers to configure pg-notify.) ⇒ \u003ccode\u003ePromise\u003c/code\u003e\n\n\u003ca name=\"module_pg-notify..Subscribe to all database events of a given list of tables\"\u003e\u003c/a\u003e\n\n### pg-notify~Subscribe to all database events of a given list of tables(tables) ⇒ \u003ccode\u003ePromise\u003c/code\u003e\n**Kind**: inner method of [\u003ccode\u003epg-notify\u003c/code\u003e](#module_pg-notify)  \n**Returns**: \u003ccode\u003ePromise\u003c/code\u003e - a promise wich resolves an NodeJS EventEmitter  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| tables | \u003ccode\u003eArray.\u0026lt;string\u0026gt;\u003c/code\u003e | An array of table names to listen |\n\n**Example**  \n```js\nconst { Client }  = require('pg');\n const pgNotify = require('@becual/pg-notify');\n\n let eventHandler = evt =\u003e {\n     console.log(JSON.stringify(evt, null, 4));\n };\n\n (async () =\u003e {\n     // Use your connection string\n     const client = new Client({ connectionString: process.env.PG_CONNECTION_STRING });\n\n     // Choose your tables to listen\n     const tables = ['customer', 'order_detail'];\n\n    try {\n        // Connect client\n        await client.connect();\n\n        // By default schema is public\n        const sub = await pgNotify(client, {schema: 'mySchema'}).subscribe(tables);\n\n        // Listen for changes\n        sub.on('INSERT', eventHandler);\n        sub.on('UPDATE', eventHandler);\n        sub.on('DELETE', eventHandler);\n    }\n    catch(error) {\n        console.log(error.message);\n        await client.end();\n    }\n })();\n```\n\u003ca name=\"module_pg-notify..Create the functions and triggers to configure pg-notify.\"\u003e\u003c/a\u003e\n\n### pg-notify~Create the functions and triggers to configure pg-notify.(tables) ⇒ \u003ccode\u003ePromise\u003c/code\u003e\n**Kind**: inner method of [\u003ccode\u003epg-notify\u003c/code\u003e](#module_pg-notify)  \n**Returns**: \u003ccode\u003ePromise\u003c/code\u003e - A promise that will implement the pg-notify config.  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| tables | \u003ccode\u003eArray.\u0026lt;string\u0026gt;\u003c/code\u003e | The list of tables to create pg notify configuration. |\n\n**Example**  \n```js\nconst { Client } = require('pg');\n const pgNotify = require('@becual/pg-notify');\n\n (async () =\u003e {\n\n     const client = new Client({ connectionString: process.env.PG_CONNECTION_STRING });\n     const tableList = ['customer', 'order_detail'];\n\n     try {\n         // Try to generate configuration\n         await client.connect();\n         await pgNotify(client, {schema: 'mySchema'}).config(tableList);\n     }\n     catch(error) {\n         // Show errors\n         console.log(error.message);\n     }\n     finally {\n         // Close connection\n         await client.end();\n     }\n })();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbecual%2Fnode-pg-notify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbecual%2Fnode-pg-notify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbecual%2Fnode-pg-notify/lists"}