{"_id":"@ameno/nest-postgres","name":"@ameno/nest-postgres","dist-tags":{"latest":"0.0.14"},"versions":{"0.0.14":{"name":"@ameno/nest-postgres","version":"0.0.14","description":"PostgreSQL module for Nest framework (node.js) 😻","author":{"name":"Tony133"},"license":"MIT","directories":{"lib":"lib","test":"tests"},"scripts":{"build":"tsc -p tsconfig.json --noEmit","format":"prettier --write \"**/*.ts\"","lint":"eslint 'lib/**/*.ts' --fix","prepublish:npm":"npm run build","publish:npm":"npm publish --access public","prepublish:next":"npm run build","publish:next":"npm publish --access public --tag next","test:e2e":"jest --config ./tests/jest-e2e.json --detectOpenHandles --forceExit","test:e2e:dev":"jest --config ./tests/jest-e2e.json --runInBand --watch","prerelease":"npm run build","release":"release-it"},"devDependencies":{"@commitlint/cli":"19.3.0","@commitlint/config-angular":"19.3.0","@nestjs/common":"10.3.9","@nestjs/config":"3.2.2","@nestjs/core":"10.3.9","@nestjs/platform-express":"10.3.9","@nestjs/platform-fastify":"^10.3.7","@nestjs/testing":"10.3.9","@types/jest":"29.5.12","@types/node":"20.14.2","@types/pg":"8.11.6","@types/supertest":"6.0.2","@typescript-eslint/eslint-plugin":"7.13.0","@typescript-eslint/parser":"7.13.0","eslint":"8.57.0","eslint-config-prettier":"9.1.0","eslint-plugin-import":"2.29.1","husky":"9.0.11","jest":"29.7.0","pg":"8.12.0","prettier":"3.3.2","reflect-metadata":"0.2.2","release-it":"17.3.0","rxjs":"7.8.1","supertest":"7.0.0","ts-jest":"29.1.4","ts-node":"10.9.2","tsconfig-paths":"4.2.0","typescript":"5.4.5"},"peerDependencies":{"@nestjs/common":"^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0","@nestjs/core":"^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0","pg":"^8.7.3","reflect-metadata":"^0.1.13 || ^0.2.0","rxjs":"^6.6.3 || ^7.2.0"},"lint-staged":{"**/*.{ts,json}":[]},"publishConfig":{"access":"public"},"repository":{"type":"git","url":"git+https://github.com/ameno-/nest-postgres.git"},"_id":"@ameno/nest-postgres@0.0.14","gitHead":"6851b8c0460e0abd02026605cee64563e8dc79ea","types":"./index.d.ts","bugs":{"url":"https://github.com/ameno-/nest-postgres/issues"},"homepage":"https://github.com/ameno-/nest-postgres#readme","_nodeVersion":"22.13.1","_npmVersion":"10.9.2","dist":{"integrity":"sha512-bGTtUKphuv1Rgrb8FU3skvgdvTyNtfYnCA1vbcO9jSmsi/hYY97Ccz+5RITSGUnPP5AWXUe82zjy9zSqwFBFLA==","shasum":"5a536a49f48bb1be647eff3b04e652b0289c5522","tarball":"https://registry.npmjs.org/@ameno/nest-postgres/-/nest-postgres-0.0.14.tgz","fileCount":29,"unpackedSize":29779,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIFbPfTbclCeAYiSql82SuH9wz+gYm2HyqPzu++o921KrAiEAgafOHSYmdNfVaO21kuQCLNI+TuV3kQjP5NUfp8CnpjM="}]},"_npmUser":{"name":"ameno","email":"ameno.osman13@gmail.com"},"maintainers":[{"name":"ameno","email":"ameno.osman13@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/nest-postgres_0.0.14_1770349901464_0.16358868365248047"},"_hasShrinkwrap":false}},"time":{"created":"2026-02-06T03:51:41.274Z","0.0.14":"2026-02-06T03:51:41.627Z","modified":"2026-02-06T03:51:41.883Z"},"maintainers":[{"name":"ameno","email":"ameno.osman13@gmail.com"}],"description":"PostgreSQL module for Nest framework (node.js) 😻","homepage":"https://github.com/ameno-/nest-postgres#readme","repository":{"type":"git","url":"git+https://github.com/ameno-/nest-postgres.git"},"author":{"name":"Tony133"},"bugs":{"url":"https://github.com/ameno-/nest-postgres/issues"},"license":"MIT","readme":"<p align=\"center\">\n  <a href=\"http://nestjs.com/\" target=\"blank\"><img src=\"https://nestjs.com/img/logo-small.svg\" width=\"200\" alt=\"Nest Logo\" /></a>\n</p>\n\n[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456\n[circleci-url]: https://circleci.com/gh/nestjs/nest\n\n  <p align=\"center\">A progressive <a href=\"http://nodejs.org\" target=\"_blank\">Node.js</a> framework for building efficient and scalable server-side applications.</p>\n    <p align=\"center\">\n<a href=\"https://www.npmjs.com/~nestjscore\" target=\"_blank\"><img src=\"https://img.shields.io/npm/v/@nestjs/core.svg\" alt=\"NPM Version\" /></a>\n<a href=\"https://www.npmjs.com/~nestjscore\" target=\"_blank\"><img src=\"https://img.shields.io/npm/l/@nestjs/core.svg\" alt=\"Package License\" /></a>\n<a href=\"https://www.npmjs.com/~nestjscore\" target=\"_blank\"><img src=\"https://img.shields.io/npm/dm/@nestjs/common.svg\" alt=\"NPM Downloads\" /></a>\n<a href=\"https://circleci.com/gh/nestjs/nest\" target=\"_blank\"><img src=\"https://img.shields.io/circleci/build/github/nestjs/nest/master\" alt=\"CircleCI\" /></a>\n<a href=\"https://coveralls.io/github/nestjs/nest?branch=master\" target=\"_blank\"><img src=\"https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#9\" alt=\"Coverage\" /></a>\n<a href=\"https://discord.gg/G7Qnnhy\" target=\"_blank\"><img src=\"https://img.shields.io/badge/discord-online-brightgreen.svg\" alt=\"Discord\"/></a>\n<a href=\"https://opencollective.com/nest#backer\" target=\"_blank\"><img src=\"https://opencollective.com/nest/backers/badge.svg\" alt=\"Backers on Open Collective\" /></a>\n<a href=\"https://opencollective.com/nest#sponsor\" target=\"_blank\"><img src=\"https://opencollective.com/nest/sponsors/badge.svg\" alt=\"Sponsors on Open Collective\" /></a>\n  <a href=\"https://paypal.me/kamilmysliwiec\" target=\"_blank\"><img src=\"https://img.shields.io/badge/Donate-PayPal-ff3f59.svg\"/></a>\n    <a href=\"https://opencollective.com/nest#sponsor\"  target=\"_blank\"><img src=\"https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg\" alt=\"Support us\"></a>\n  <a href=\"https://twitter.com/nestframework\" target=\"_blank\"><img src=\"https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow\"></a>\n</p>\n  <!--[![Backers on Open Collective](https://opencollective.com/nest/backers/badge.svg)](https://opencollective.com/nest#backer)\n  [![Sponsors on Open Collective](https://opencollective.com/nest/sponsors/badge.svg)](https://opencollective.com/nest#sponsor)-->\n\n## Description\n\nPostgreSQL module for Nest framework (node.js) 😻\n\n## Installation\n\nFirst install the module via `yarn` or `npm` or `pnpm` and do not forget to install the driver package as well:\n\n\n```bash\n    $ npm i --save @ameno/nest-postgres pg\n```\nor\n\n```bash\n    $ yarn add @ameno/nest-postgres pg\n```\n\nor\n\n```bash\n    $ pnpm add @ameno/nest-postgres pg\n```\n\n## Table of Contents\n\n- [Description](#description)\n- [Table of Contents](#table-of-contents)\n- [Usage](#usage)\n  - [PostgresModule](#postgresmodule)\n  - [MultiConnectionsDatabase](#multi-connections-database)\n  - [ExampleOfUse](#example-of-use)\n\n## Usage\n\n### PostgresModule\n\nPostgresModule is the primary entry point for this package and can be used synchronously\n\n```typescript\n@Module({\n  imports: [\n    PostgresModule.forRoot({\n        connectionString: 'postgresql://[user]:[password]@[host]/[nameDb]',\n        // or \n        // host: 'localhost',\n        // database: [:databaseName],\n        // password: [:passwordDb],\n        // user: [:userDb],\n        // port: 5432,\n    }),\n  ],\n})\n```\n\nor asynchronously\n\n```typescript\n@Module({\n  imports: [\n    PostgresModule.forRootAsync({\n      useFactory: () => ({\n        connectionString: 'postgresql://[user]:[password]@[host]/[nameDb]',\n        // or \n        // host: 'localhost',\n        // database: [:databaseName],\n        // password: [:passwordDb],\n        // user: [:userDb],\n        // port: 5432,\n      }),\n    }),\n  ],\n})\n```\n\n## Example of use\n\nUsersService:\n\n```typescript\nimport { Client } from 'pg';\nimport { InjectClient } from '@ameno/nest-postgres';\n\n@Injectable()\nexport class UsersService {\n  constructor(@InjectClient() private readonly pg: Client) {}\n\n  public async findAll(): Promise<User[]> {\n    const users = await this.pg.query('SELECT * FROM users');\n    return users.rows;\n  }\n}\n```\n\nUsersController:\n\n```typescript\nimport { Controller, Get } from '@nestjs/common';\nimport { UsersService } from './users.service';\n\n@Controller()\nexport class UsersController {\n  constructor(private readonly usersService: UsersService) {}\n\n  @Get()\n  async getAllUsers(): Promise<User[]> {\n    return await this.usersService.findAll();\n  }\n}\n```\n\n## Multi Connections Database\n\n```typescript\n@Module({\n  imports: [\n    PostgresModule.forRoot(\n      {\n        connectionString: 'postgresql://postgres:pass123@localhost:5432/nest1',\n        // or \n        // host: 'localhost',\n        // database: [:databaseName],\n        // password: [:passwordDb],\n        // user: [:userDb],\n        // port: 5432,\n      },\n      'db1Connection',\n    ),\n    PostgresModule.forRoot(\n      {\n        connectionString: 'postgresql://postgres:pass123@localhost:5434/nest2',\n      },\n      'db2Connection',\n    ),\n  ],\n  controllers: [],\n  providers: [],\n})\nexport class AppModule {}\n```\n\nUsage example with Multi Connection\n\nPostService:\n\n```typescript\nimport { Client } from 'pg';\nimport { InjectConnection } from '@ameno/nest-postgres';\nimport { CreatePostDto } from './dto/create-post.dto';\nimport { Post } from './interfaces/post.interface';\n\n@Injectable()\nexport class PostService {\n  constructor(\n    @InjectConnection('db2Connection')\n    private dbConnection: Client,\n  ) {}\n\n  public async findAll(): Promise<Post[]> {\n    const users = await this.dbConnection.query('SELECT * FROM posts');\n    return users.rows;\n  }\n\n  public async create(createPostDto: CreatePostDto): Promise<Post[]> {\n    try {\n      const user = await this.dbConnection.query(\n        'INSERT INTO posts (title, description)  VALUES ($1, $2) RETURNING *',\n        [createPostDto.title, createPostDto.description],\n      );\n      return user.rows;\n    } catch (err) {\n      throw new HttpException(err, HttpStatus.BAD_REQUEST);\n    }\n  }\n}\n```\n\nUsersService:\n\n```typescript\nimport { Client } from 'pg';\nimport { InjectConnection } from '@ameno/nest-postgres';\nimport { CreateUserDto } from './dto/create-user.dto';\nimport { User } from './interfaces/user.interface';\n\n@Injectable()\nexport class UsersService {\n  constructor(\n    @InjectConnection('db1Connection')\n    private dbConnection: Client,\n  ) {}\n\n  public async findAll(): Promise<User[]> {\n    const users = await this.dbConnection.query('SELECT * FROM users');\n    return users.rows;\n  }\n\n  public async create(createUserDto: CreateUserDto): Promise<User[]> {\n    try {\n      const user = await this.dbConnection.query(\n        'INSERT INTO users (firstName, lastName)  VALUES ($1, $2) RETURNING *',\n        [createUserDto.firstName, createUserDto.lastName],\n      );\n      return user.rows;\n    } catch (err) {\n      throw new HttpException(err, HttpStatus.BAD_REQUEST);\n    }\n  }\n}\n```\n\nFor more information on `node-postgres` for Nodejs see [here](https://node-postgres.com/)\n\n## Contribute\nFeel free to help this library, I'm quite busy with also another Nestjs packages, but the community will appreciate the effort of improving this library. Make sure you follow the guidelines\n\n## Stay in touch\n\n- Author - [Tony133](https://github.com/Tony133)\n- Framework - [https://nestjs.com](https://nestjs.com/)\n\n## License\n\n [MIT licensed](LICENSE)\n","readmeFilename":"README.md","_rev":"1-ce9eb6dda757143b4a4c4aa17591758e"}