{"_id":"@knaadh/nestjs-drizzle-pg","_rev":"3-82068fa3113be3982fbe025828e6bc2b","name":"@knaadh/nestjs-drizzle-pg","dist-tags":{"latest":"1.2.0"},"versions":{"1.0.0":{"name":"@knaadh/nestjs-drizzle-pg","version":"1.0.0","keywords":["drizzle","node-postgres","database","orm","nestjs","pg"],"author":{"name":"Mithlesh Jasrotia","email":"mithleshjs@gmail.com"},"license":"MIT","_id":"@knaadh/nestjs-drizzle-pg@1.0.0","maintainers":[{"name":"mithleshjs","email":"mithleshjs@gmail.com"}],"homepage":"https://github.com/knaadh/nestjs-drizzle","bugs":{"url":"https://github.com/knaadh/nestjs-drizzle/issues"},"dist":{"shasum":"2565103bc59220b530c0ef572ae2217c3a18b81a","tarball":"https://registry.npmjs.org/@knaadh/nestjs-drizzle-pg/-/nestjs-drizzle-pg-1.0.0.tgz","fileCount":17,"integrity":"sha512-21Ywzn/5y0QQz3cx1Nc2ZKfzW7LAjWCjATymkT148YECc+BIwpwvWvpejnjPOjFcyM0XfNT2axvRb0913GVfWg==","signatures":[{"sig":"MEUCIB4H9iKRVkCKe+WmijcgjA8IIPAcWvgE0Z5rqn7fNnnFAiEAyV4YeQzbNVTsqXEej4lVlOzubk59yfUmP7KsE3DBgIc=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":13175},"main":"./src/index.js","type":"commonjs","gitHead":"a81c8ec10a0170b836ea9970afcc3026b61874d5","typings":"./src/index.d.ts","_npmUser":{"name":"mithleshjs","email":"mithleshjs@gmail.com"},"repository":{"url":"git+https://github.com/knaadh/nestjs-drizzle.git","type":"git","directory":"packages/node-postgres"},"_npmVersion":"9.8.1","description":"A NestJS module for integrating Drizzle ORM with Node-Postgres driver","directories":{},"_nodeVersion":"18.18.0","dependencies":{"tslib":"^2.3.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"peerDependencies":{"pg":">=8","drizzle-orm":">=0.28.6","@nestjs/common":">=9.0.0"},"_npmOperationalInternal":{"tmp":"tmp/nestjs-drizzle-pg_1.0.0_1698171250845_0.6096704832509363","host":"s3://npm-registry-packages"}},"1.1.0":{"name":"@knaadh/nestjs-drizzle-pg","version":"1.1.0","keywords":["drizzle","node-postgres","database","orm","nestjs","pg"],"author":{"name":"Mithlesh Jasrotia","email":"mithleshjs@gmail.com"},"license":"MIT","_id":"@knaadh/nestjs-drizzle-pg@1.1.0","maintainers":[{"name":"mithleshjs","email":"mithleshjs@gmail.com"}],"homepage":"https://github.com/knaadh/nestjs-drizzle","bugs":{"url":"https://github.com/knaadh/nestjs-drizzle/issues"},"dist":{"shasum":"a33f82aa3ca4e20e92f3662d6b91a17dd6d98764","tarball":"https://registry.npmjs.org/@knaadh/nestjs-drizzle-pg/-/nestjs-drizzle-pg-1.1.0.tgz","fileCount":15,"integrity":"sha512-U/GWLuFfZcjvekkd9NYkBw/FDp0mF4ahw6xRjVLe9wFTJKn/krcVLvz69Zw3C76fUtQv6K/4bzUxgQXfV0nBLg==","signatures":[{"sig":"MEYCIQDRkngDgne4y28szP3n2M+DprWpJiUM6RcQFqhzwkEc/gIhANYsGEkaIsk5pQNKY83L7pQQCltwNks9xyfcGLpDl21h","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":12136},"main":"./src/index.js","type":"commonjs","gitHead":"712ea07b643aac1b6278a7b72ab0ac7d64902845","typings":"./src/index.d.ts","_npmUser":{"name":"mithleshjs","email":"mithleshjs@gmail.com"},"repository":{"url":"git+https://github.com/knaadh/nestjs-drizzle.git","type":"git","directory":"packages/node-postgres"},"_npmVersion":"10.7.0","description":"A NestJS module for integrating Drizzle ORM with Node-Postgres driver","directories":{},"_nodeVersion":"20.15.0","dependencies":{"tslib":"^2.3.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"peerDependencies":{"pg":">=8","drizzle-orm":">=0.28.6","@nestjs/common":">=9.0.0"},"_npmOperationalInternal":{"tmp":"tmp/nestjs-drizzle-pg_1.1.0_1730662323049_0.44877057769521467","host":"s3://npm-registry-packages"},"deprecated":"Version 1.1.0 contains known bugs. Please upgrade to version 1.2.0 or later for fixes."},"1.2.0":{"name":"@knaadh/nestjs-drizzle-pg","version":"1.2.0","keywords":["drizzle","node-postgres","database","orm","nestjs","pg"],"author":{"name":"Mithlesh Jasrotia","email":"mithleshjs@gmail.com"},"license":"MIT","_id":"@knaadh/nestjs-drizzle-pg@1.2.0","maintainers":[{"name":"mithleshjs","email":"mithleshjs@gmail.com"}],"homepage":"https://github.com/knaadh/nestjs-drizzle","bugs":{"url":"https://github.com/knaadh/nestjs-drizzle/issues"},"dist":{"shasum":"0807ef6d591ac530a3d90a66662cc4b0dfedc036","tarball":"https://registry.npmjs.org/@knaadh/nestjs-drizzle-pg/-/nestjs-drizzle-pg-1.2.0.tgz","fileCount":20,"integrity":"sha512-urjl4iBFy46QghmLRyGpGBaLsk6raWDrW0NGHQlDSy7QPdH9jgq40Bar8t72iR7VNPdRDPI5lbBbLa7hQHc5sQ==","signatures":[{"sig":"MEUCIFg18ACT7VYLX/CVCvc4sCGo0XUa16/BxPzDDNu0aqhhAiEAlYefQABr7Pxz6fkiwJqzasJQYUMV9e0Bkbhfs6oAFok=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":16251},"main":"./src/index.js","type":"commonjs","types":"./src/index.d.ts","gitHead":"57041aeae1cf5f5f5e55081cc9839f4b127e7c5e","typings":"./src/index.d.ts","_npmUser":{"name":"mithleshjs","email":"mithleshjs@gmail.com"},"repository":{"url":"git+https://github.com/knaadh/nestjs-drizzle.git","type":"git","directory":"packages/node-postgres"},"_npmVersion":"10.7.0","description":"A NestJS module for integrating Drizzle ORM with Node-Postgres driver","directories":{},"_nodeVersion":"20.15.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"peerDependencies":{"pg":">=8","drizzle-orm":">=0.28.6","@nestjs/common":">=9.0.0"},"_npmOperationalInternal":{"tmp":"tmp/nestjs-drizzle-pg_1.2.0_1730818934315_0.44656539807168594","host":"s3://npm-registry-packages"}}},"time":{"created":"2023-10-24T18:14:10.752Z","modified":"2024-11-05T15:27:53.626Z","1.0.0":"2023-10-24T18:14:11.226Z","1.1.0":"2024-11-03T19:32:03.213Z","1.2.0":"2024-11-05T15:02:14.573Z"},"bugs":{"url":"https://github.com/knaadh/nestjs-drizzle/issues"},"author":{"name":"Mithlesh Jasrotia","email":"mithleshjs@gmail.com"},"license":"MIT","homepage":"https://github.com/knaadh/nestjs-drizzle","keywords":["drizzle","node-postgres","database","orm","nestjs","pg"],"repository":{"url":"git+https://github.com/knaadh/nestjs-drizzle.git","type":"git","directory":"packages/node-postgres"},"description":"A NestJS module for integrating Drizzle ORM with Node-Postgres driver","maintainers":[{"name":"mithleshjs","email":"mithleshjs@gmail.com"}],"readme":"<p align=\"center\">\r\n  <a href=\"https://nestjs.com/\" target=\"blank\"><img src=\"https://nestjs.com/img/logo.svg\" width=\"200\" alt=\"Nest Logo\" /></a>\r\n</p>\r\n\r\n<p align=\"center\">\r\n <a href=\"https://nestjs.com/\" target=\"blank\">A NestJS</a> module for integrating  <a href=\"https://orm.drizzle.team\" target=\"blank\">Drizzle ORM </a> with <a href=\"https://github.com/porsager/postgres\" target=\"blank\">Node-Postgres</a> driver\r\n</p>\r\n\r\n<p align=\"center\">\r\n  <a href=\"https://nx.dev/\" target=\"blank\"><img src=\"https://img.shields.io/badge/built%20with-Nx-orange?style=for-the-badge\" alt=\"Nrwl Nx\" /></a>\r\n</p>\r\n\r\n## Table of Contents\r\n\r\n- [Table of Contents](#table-of-contents)\r\n- [Installation](#installation)\r\n- [Usage](#usage)\r\n- [Configuration](#configuration)\r\n- [Documentation](#documentation)\r\n- [License](#license)\r\n\r\n## Installation\r\n\r\n```bash\r\nnpm install @knaadh/nestjs-drizzle-pg drizzle-orm pg\r\n```\r\n\r\n## Usage\r\n\r\nImport the DrizzlePGModule module and pass an `options` object to initialize it. You can pass `options` object using the usual methods for [custom providers](https://docs.nestjs.com/fundamentals/custom-providers) as shown below:\r\n\r\n```typescript\r\nimport { Module } from '@nestjs/common';\r\nimport { AppController } from './app.controller';\r\nimport { AppService } from './app.service';\r\nimport * as schema from '../db/schema';\r\nimport { DrizzlePGModule } from '@knaadh/nestjs-drizzle-pg';\r\n\r\n@Module({\r\n  imports: [\r\n    // Method #1: Pass options object\r\n    DrizzlePGModule.register({\r\n      tag: 'DB_DEV',\r\n      pg: {\r\n        connection: 'client',\r\n        config: {\r\n          connectionString: 'postgres://postgres:@127.0.0.1:5432/drizzleDB',\r\n        },\r\n      },\r\n      config: { schema: { ...schema } },\r\n    }),\r\n\r\n    // Method #2: useFactory()\r\n    DrizzlePGModule.registerAsync({\r\n      tag: 'DB_PROD',\r\n      useFactory() {\r\n        return {\r\n          pg: {\r\n            connection: 'client',\r\n            config: {\r\n              connectionString: 'postgres://postgres:@127.0.0.1:5432/drizzleDB',\r\n            },\r\n          },\r\n          config: { schema: { ...schema } },\r\n        };\r\n      },\r\n    }),\r\n\r\n    // Method #3: useClass()\r\n    DrizzlePGModule.registerAsync({\r\n      tag: 'DB_STAGING',\r\n      useClass: DBConfigService,\r\n    }),\r\n  ],\r\n  controllers: [AppController],\r\n  providers: [AppService],\r\n})\r\nexport class AppModule {}\r\n```\r\n\r\n```typescript\r\nexport class DBConfigService {\r\n  create = () => {\r\n    return {\r\n      pg: {\r\n        connection: 'client' as const,\r\n        config: {\r\n          connectionString: 'postgres://postgres:@127.0.0.1:5432/drizzleDB',\r\n        },\r\n      },\r\n      config: { schema: { ...schema } },\r\n    };\r\n  };\r\n}\r\n```\r\nYou can inject the Drizzle instances using their respective `tag` specified in the configurations\r\n\r\n```typescript\r\nimport { Inject, Injectable } from '@nestjs/common';\r\nimport * as schema from '../db/schema';\r\nimport { NodePgDatabase } from 'drizzle-orm/node-postgres';\r\n@Injectable()\r\nexport class AppService {\r\n  constructor(\r\n    @Inject('DB_DEV') private drizzleDev: NodePgDatabase<typeof schema>,\r\n    @Inject('DB_PROD') private drizzleProd: NodePgDatabase<typeof schema>\r\n  ) {}\r\n  async getData() {\r\n    const books = await this.drizzleDev.query.books.findMany();\r\n    const authors = await this.drizzleProd.query.authors.findMany();\r\n    return {\r\n      books: books,\r\n      authors: authors,\r\n    };\r\n  }\r\n}\r\n```\r\n\r\n## Configuration\r\n\r\nA DrizzlePGModule `option` object has the following interface:\r\n\r\n```typescript\r\nexport interface DrizzlePGConfig {\r\n  pg: {\r\n    connection: 'client' | 'pool';\r\n    config: ClientConfig | PoolConfig;\r\n  };\r\n  config?: DrizzleConfig<any> | undefined;\r\n}\r\n```\r\n\r\n- `pg.connection:` single `client` connection or a `pool` as mentioned [here](https://orm.drizzle.team/docs/quick-postgresql/node-postgres)\r\n- (optional) `postgres.config:` pass [client config](https://node-postgres.com/apis/client) or [pool config](https://node-postgres.com/apis/pool) according to the connection\r\n- (optional) `config:` DrizzleORM configuration\r\n\r\n## Documentation\r\n\r\n- [NX](https://nx.dev/)\r\n- [DrizzleORM](https://orm.drizzle.team/)\r\n- [Node-PostGres](https://github.com/porsager/postgres)\r\n\r\n## License\r\n\r\nThis package is [MIT licensed](https://github.com/knaadh/nestjs-drizzle/blob/main/LICENSE).\r\n","readmeFilename":"README.md"}