{"id":16694041,"url":"https://github.com/haoliangyu/pg-reactive","last_synced_at":"2026-01-04T08:15:41.414Z","repository":{"id":19168246,"uuid":"85904768","full_name":"haoliangyu/pg-reactive","owner":"haoliangyu","description":"PostgreSQL + RxJS = pg-reactive","archived":false,"fork":false,"pushed_at":"2023-01-06T01:32:47.000Z","size":1069,"stargazers_count":41,"open_issues_count":3,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-13T16:43:32.784Z","etag":null,"topics":["javascript","nodejs","postgresql","reactivex","rxjs","typescript"],"latest_commit_sha":null,"homepage":"https://haoliangyu.github.io/pg-reactive/","language":"TypeScript","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/haoliangyu.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2017-03-23T03:52:51.000Z","updated_at":"2024-02-04T19:09:26.000Z","dependencies_parsed_at":"2023-01-13T20:12:50.831Z","dependency_job_id":null,"html_url":"https://github.com/haoliangyu/pg-reactive","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haoliangyu%2Fpg-reactive","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haoliangyu%2Fpg-reactive/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haoliangyu%2Fpg-reactive/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haoliangyu%2Fpg-reactive/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/haoliangyu","download_url":"https://codeload.github.com/haoliangyu/pg-reactive/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221669507,"owners_count":16860896,"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":["javascript","nodejs","postgresql","reactivex","rxjs","typescript"],"created_at":"2024-10-12T16:43:33.467Z","updated_at":"2026-01-04T08:15:41.408Z","avatar_url":"https://github.com/haoliangyu.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pg-reactive\n\n[![npm](https://img.shields.io/npm/v/pg-reactive.svg)](https://www.npmjs.com/package/pg-reactive)\n\n[RxJS](https://github.com/ReactiveX/rxjs) interface for PostgreSQL in node.js\n\n\n## Installation\n\n``` bash\nnpm install pg-reactive\n```\n\nIf you are using RxJS v5, install a previous version:\n\n``` bash\nnpm install pg-reactive@^0.3.5\n```\n\n## Example\n\n``` javascript\nimport PgRx from 'pg-reactive';\nimport { map } from \"rxjs/operators\";\n\nconst db = new PgRx('postgres://postgres@$localhost/tester');\n\ndb.query('SELECT id FROM user')\n  .pipe(\n    map((row) =\u003e row.id)\n  )\n  .subscribe((id) =\u003e {\n    console.log('ID: ', id);\n  });\n```\n\n## Documentation\n\n* [latest (for RxJS 6)](https://haoliangyu.github.io/pg-reactive)\n* [v0.3.x (for RxJS 5)](https://github.com/haoliangyu/pg-reactive/blob/v0.3.5/README.md)\n\n## TypeScript\n\n`pg-reactive` is shipped with its type declaration file and it can be used in a TypeScript directly.\n\n## How it works?\n\nBefore using this library or reading its source code, you should know [Reactive Programming \u0026 RxJS](http://reactivex.io/intro.html).\n\n`pg-reactive` wraps the low-level [pg](https://github.com/brianc/node-postgres) APIs and exposes a RxJS-compatible interface. The work of `pg-reactive` includes the following three aspects.\n\n### Deferred Query\n\nUnlike [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) as the final state of an asynchronous action, [Observable](http://reactivex.io/documentation/observable.html) works as a data source of asynchronous actions. When providing a observable-based API, `pg-reactive` [cools down](https://stackoverflow.com/questions/32190445/hot-and-cold-observables-are-there-hot-and-cold-operators) the original `pg` functions by deferring their execution using [Rx.Observable.defer()](http://reactivex.io/rxjs/class/es6/Observable.js~Observable.html#static-method-defer).\n\nIn this way, the data stream is controllable with `subscribe()` / `unsubscribe()` without worrying data leak. The data stream is generated using the `row`, `error`, `end` event of the [query](https://github.com/brianc/node-postgres/wiki/Client#events) object of `pg`, which ensures the query result is emitted by rows.\n\n### Transaction as an Observable\n\nThe `tx()` function of `pg-reactive` accepts a callback function where the user is able to organization the data flow within a transaction, which may includes different database operations. The data flow behind this function is actually `query('BEGIN') -\u003e query('Your Command') -\u003e query('COMMIT')` and a `query('ROLLBACK')` will be executed in cause of any error.\n\nNote that unlike the query observable, the tx observable doesn't emit data until the query is completely done. Therefore, the tx observable guarantees to emit nothing if error happens.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhaoliangyu%2Fpg-reactive","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhaoliangyu%2Fpg-reactive","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhaoliangyu%2Fpg-reactive/lists"}