{"id":18304569,"url":"https://github.com/numtel/meteor-pg","last_synced_at":"2025-04-05T15:31:21.417Z","repository":{"id":30484585,"uuid":"34038686","full_name":"numtel/meteor-pg","owner":"numtel","description":"Reactive PostgreSQL for Meteor","archived":false,"fork":false,"pushed_at":"2015-08-12T19:44:14.000Z","size":413,"stargazers_count":300,"open_issues_count":8,"forks_count":16,"subscribers_count":30,"default_branch":"master","last_synced_at":"2025-03-21T06:40:59.299Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/numtel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-16T06:38:02.000Z","updated_at":"2024-04-19T14:32:36.000Z","dependencies_parsed_at":"2022-09-07T20:11:40.945Z","dependency_job_id":null,"html_url":"https://github.com/numtel/meteor-pg","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/numtel%2Fmeteor-pg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/numtel%2Fmeteor-pg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/numtel%2Fmeteor-pg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/numtel%2Fmeteor-pg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/numtel","download_url":"https://codeload.github.com/numtel/meteor-pg/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247358653,"owners_count":20926266,"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":[],"created_at":"2024-11-05T15:29:23.864Z","updated_at":"2025-04-05T15:31:20.357Z","avatar_url":"https://github.com/numtel.png","language":"JavaScript","funding_links":[],"categories":["Alternative Databases"],"sub_categories":[],"readme":"# numtel:pg [![Build Status](https://travis-ci.org/numtel/meteor-pg.svg?branch=master)](https://travis-ci.org/numtel/meteor-pg)\n\nReactive PostgreSQL for Meteor\n\nProvides Meteor integration of the [`pg-live-select` NPM module](https://github.com/numtel/pg-live-select), bringing reactive `SELECT` statement result sets from PostgreSQL \u003e= 9.3.\n\n\u003e If you do not have PostgreSQL server already installed, you may use [the numtel:pg-server Meteor Package](https://github.com/numtel/meteor-pg-server) to bundle the PostgreSQL server directly to your Meteor application.\n\n* [How to publish joined queries that update efficiently](https://github.com/numtel/meteor-pg/wiki/Publishing-Efficient-Joined-Queries)\n* [Leaderboard example modified to use PostgreSQL](https://github.com/numtel/meteor-pg-leaderboard)\n* [Reactive MySQL for Meteor](https://github.com/numtel/meteor-mysql)\n\n## Server Implements\n\nThis package provides the `LivePg` class as defined in the [`pg-live-select` NPM package](https://github.com/numtel/pg-live-select).\n\nAlso exposed on the server is the `pg` object as defined in the [`node-postgres` NPM package](https://github.com/brianc/node-postgres) (useful for other operations like `INSERT` and `UPDATE`).\n\n### `LivePg.prototype.select()`\n\nIn this Meteor package, the `SelectHandle` object returned by the `select()` method is modified to act as a cursor that can be published.\n\n```javascript\nvar liveDb = new LivePg(CONNECTION_STRING, CHANNEL);\n\nMeteor.publish('allPlayers', function(){\n  return liveDb.select('SELECT * FROM players ORDER BY score DESC');\n});\n```\n\n## Client/Server Implements\n\n### `PgSubscription([connection,] name, [args...])`\n\nConstructor for subscribing to a published select statement. No extra call to `Meteor.subscribe()` is required. Specify the name of the subscription along with any arguments.\n\nThe first argument, `connection`, is optional. If connecting to a different Meteor server, pass the DDP connection object in this first argument. If not specified, the first argument becomes the name of the subscription (string) and the default Meteor server connection will be used.\n\nThe prototype inherits from `Array` and is extended with the following methods:\n\nName | Description\n-----|--------------------------\n`change([args...])` | Change the subscription's arguments. Publication name and connection are preserved.\n`addEventListener(eventName, listener)` | Bind a listener function to this subscription\n`removeEventListener(eventName)` | Remove listener functions from an event queue\n`dispatchEvent(eventName, [args...])` | Call the listeners for a given event, returns boolean\n`depend()` | Call from inside of a Template helper function to ensure reactive updates\n`reactive()` | Same as `depend()` except returns self\n`changed()`| Signal new data in the subscription\n`ready()` | Return boolean value corresponding to subscription fully loaded\n`stop()` | Stop updates for this subscription\n\n**Notes:**\n\n* `changed()` is automatically called when the query updates and is most likely to only be called manually from a method stub on the client.\n* Event listener methods are similar to native methods. For example, if an event listener returns `false` exactly, it will halt listeners of the same event that have been added previously. A few differences do exist though to make usage easier in this context:\n  * The event name may also contain an identifier suffix using dot namespacing (e.g. `update.myEvent`) to allow removing/dispatching only a subset of listeners.\n  * `removeEventListener()` and `dispatchEvent()` both refer to listeners by name only. Regular expessions allowed.\n  * `useCapture` argument is not available.\n\n#### Event Types\n\nName | Listener Arguments | Description\n-----|-------------------|-----------------------\n`update` | `diff, data` | New change, before data update\n`updated` | `diff, data` | New change, after data update\n`reset` | `msg` | Subscription reset (most likely due to code-push), before update\n\n## Closing connections between hot code-pushes\n\nWith Meteor's hot code-push feature, new triggers and functions on database server are created with each restart. In order to remove old items, a handler to your application process's `SIGTERM` signal event must be added that calls the `cleanup()` method on each `LivePg` instance in your application. Also, a handler for `SIGINT` can be used to close connections on exit.\n\nOn the server-side of your application, add event handlers like this:\n\n```javascript\n\nvar liveDb = new LivePg(CONNECTION_STRING, CHANNEL);\n\nvar closeAndExit = function() {\n  // Call process.exit() as callback\n  liveDb.cleanup(process.exit);\n};\n\n// Close connections on hot code push\nprocess.on('SIGTERM', closeAndExit);\n// Close connections on exit (ctrl + c)\nprocess.on('SIGINT', closeAndExit);\n```\n\n## Tests / Benchmarks\n\nThe test suite does not require a separate Postgres server installation as it uses [the `numtel:pg-server` package](https://github.com/numtel/meteor-pg-server) to run the tests.\n\nThe database connection settings must be configured in `test/settings/local.json`.\n\nThe database specified should be an empty database with no tables because the tests will create and delete tables as needed.\n\n```bash\n# Install Meteor\n$ curl -L https://install.meteor.com/ | /bin/sh\n\n# Clone Repository\n$ git clone https://github.com/numtel/meteor-pg.git\n$ cd meteor-pg\n\n# Optionally, configure port and data dir in test/settings/test.pg.json.\n# If changing port, keep port value updated in test/index.es6 as well.\n\n# Test database will be created in dbtest directory.\n\n# Run test server\n$ meteor test-packages ./\n\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnumtel%2Fmeteor-pg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnumtel%2Fmeteor-pg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnumtel%2Fmeteor-pg/lists"}