{"_id":"@knaadh/nestjs-drizzle-postgres","_rev":"3-6cfebac7a7a72d2ce3a0938d97ee4e03","name":"@knaadh/nestjs-drizzle-postgres","dist-tags":{"latest":"1.2.0"},"versions":{"1.0.0":{"name":"@knaadh/nestjs-drizzle-postgres","version":"1.0.0","keywords":["drizzle","postgres.js","database","orm","nestjs"],"author":{"name":"Mithlesh Jasrotia","email":"mithleshjs@gmail.com"},"license":"MIT","_id":"@knaadh/nestjs-drizzle-postgres@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":"5612e028bbf5b702aebd5ec690acf6816abbc939","tarball":"https://registry.npmjs.org/@knaadh/nestjs-drizzle-postgres/-/nestjs-drizzle-postgres-1.0.0.tgz","fileCount":17,"integrity":"sha512-r3elSMh+M3ndJw1EJqYJWK0tqPo0zz+AURkLr/OoOws3wWKTyT0GQsKZTBpPytdZnbHqXPHh5ExsPNEc7eJ8Pw==","signatures":[{"sig":"MEYCIQDyJaCNGHndXECFsUw622P6Pe+2Er/yaM8PingiDoc2DAIhAN0VGDSlKpN9nMj9FvrnsnIn3XW6em1mTYLbuibSwYc/","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":12593},"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/postgres-js"},"_npmVersion":"9.8.1","description":"A NestJS module for integrating Drizzle ORM with PostgresJS driver","directories":{},"_nodeVersion":"18.18.0","dependencies":{"tslib":"^2.3.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"peerDependencies":{"postgres":">=3","drizzle-orm":">=0.28.6","@nestjs/common":">=9.0.0"},"_npmOperationalInternal":{"tmp":"tmp/nestjs-drizzle-postgres_1.0.0_1698170491392_0.1395410563601489","host":"s3://npm-registry-packages"}},"1.1.0":{"name":"@knaadh/nestjs-drizzle-postgres","version":"1.1.0","keywords":["drizzle","postgres.js","database","orm","nestjs"],"author":{"name":"Mithlesh Jasrotia","email":"mithleshjs@gmail.com"},"license":"MIT","_id":"@knaadh/nestjs-drizzle-postgres@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":"681c2c515b4398e3c43207982e6a3bd560c020fe","tarball":"https://registry.npmjs.org/@knaadh/nestjs-drizzle-postgres/-/nestjs-drizzle-postgres-1.1.0.tgz","fileCount":15,"integrity":"sha512-P3aiXZQjQveOLmpm2WnrzTAh5SZMsRrhOBamZCTTTUjPXBStz7ydOm9yC/eSetT9ba94dCJClbBuX//5vkekdA==","signatures":[{"sig":"MEUCIAU0Uhd/wcYSVaF2egVXZyAlKo695OdWgsEQNgJ/yb9vAiEA6n8h0HXRLrJg53MtGHg0bO34Zr21a9CwpfWFHbJ4An8=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":11843},"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/postgres-js"},"_npmVersion":"10.7.0","description":"A NestJS module for integrating Drizzle ORM with PostgresJS driver","directories":{},"_nodeVersion":"20.15.0","dependencies":{"tslib":"^2.3.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"peerDependencies":{"postgres":">=3","drizzle-orm":">=0.28.6","@nestjs/common":">=9.0.0"},"_npmOperationalInternal":{"tmp":"tmp/nestjs-drizzle-postgres_1.1.0_1730662443975_0.3860892802068292","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-postgres","version":"1.2.0","keywords":["drizzle","postgres.js","database","orm","nestjs"],"author":{"name":"Mithlesh Jasrotia","email":"mithleshjs@gmail.com"},"license":"MIT","_id":"@knaadh/nestjs-drizzle-postgres@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":"525e346555c9017151c2ed46ab3ebfb0e0a3caea","tarball":"https://registry.npmjs.org/@knaadh/nestjs-drizzle-postgres/-/nestjs-drizzle-postgres-1.2.0.tgz","fileCount":20,"integrity":"sha512-F6qFm8yh12uqex//GZsrTTuq1RnwgYYBzw2aWeyeoHMk0qbNP5eog7a8PlL/OLnfW1PX8kPAPWIxAdv5Am68+g==","signatures":[{"sig":"MEYCIQDn2Fr52Ko+FGNmNznqw8jVefoOC+yvh5WNSFMnzq34oAIhAPVQwbR+Gqe0I94TLmxQg1RCHBXdUvqNRFsahhKsznf/","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":15819},"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/postgres-js"},"_npmVersion":"10.7.0","description":"A NestJS module for integrating Drizzle ORM with PostgresJS driver","directories":{},"_nodeVersion":"20.15.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"peerDependencies":{"postgres":">=3","drizzle-orm":">=0.28.6","@nestjs/common":">=9.0.0"},"_npmOperationalInternal":{"tmp":"tmp/nestjs-drizzle-postgres_1.2.0_1730819272174_0.44820166228358094","host":"s3://npm-registry-packages"}}},"time":{"created":"2023-10-24T18:01:31.322Z","modified":"2024-11-05T15:27:49.878Z","1.0.0":"2023-10-24T18:01:31.576Z","1.1.0":"2024-11-03T19:34:04.141Z","1.2.0":"2024-11-05T15:07:52.357Z"},"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","postgres.js","database","orm","nestjs"],"repository":{"url":"git+https://github.com/knaadh/nestjs-drizzle.git","type":"git","directory":"packages/postgres-js"},"description":"A NestJS module for integrating Drizzle ORM with PostgresJS 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\">PostgresJS</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-postgres drizzle-orm postgres\r\n```\r\n\r\n## Usage\r\n\r\nImport the DrizzlePostgresModule 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 { DrizzlePostgresModule } from '@knaadh/nestjs-drizzle-postgres';\r\n\r\n@Module({\r\n  imports: [\r\n    // Method #1: Pass options object\r\n    DrizzlePostgresModule.register({\r\n      tag: 'DB_DEV',\r\n      postgres: {\r\n        url: 'postgres://postgres:@127.0.0.1:5432/drizzleDB',\r\n      },\r\n      config: { schema: { ...schema } },\r\n    }),\r\n\r\n    // Method #2: useFactory()\r\n    DrizzlePostgresModule.registerAsync({\r\n      tag: 'DB_PROD',\r\n      useFactory() {\r\n        return {\r\n          postgres: {\r\n            url: 'postgres://postgres:@127.0.0.1:5432/drizzleDB',\r\n          },\r\n          config: { schema: { ...schema } },\r\n        };\r\n      },\r\n    }),\r\n\r\n    // Method #3: useClass()\r\n     DrizzlePostgresModule.registerAsync({\r\n      tag: 'DB_STAGING',\r\n      useClass: DBConfigService,\r\n    }),\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      postgres: {\r\n        url: 'postgres://postgres:@127.0.0.1:5432/drizzleDB',\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 { PostgresJsDatabase } from 'drizzle-orm/postgres-js';\r\nimport * as schema from '../db/schema';\r\n@Injectable()\r\nexport class AppService {\r\n  constructor(\r\n    @Inject('DB_DEV') private drizzleDev: PostgresJsDatabase<typeof schema>,\r\n    @Inject('DB_PROD') private drizzleProd: PostgresJsDatabase<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 DrizzlePostgresModule `option` object has the following interface:\r\n\r\n```typescript\r\nexport interface DrizzlePostgresConfig {\r\n  postgres: {\r\n    url: string;\r\n    config?: Options<Record<string, PostgresType<any>>> | undefined;\r\n  };\r\n  config?: DrizzleConfig<any> | undefined;\r\n}\r\n```\r\n\r\n- `postgres.url:` postgres url connection string\r\n- (optional) `postgres.config:` Postgres.js driver [options](https://github.com/porsager/postgres#connection-details)\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- [PostgresJS](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"}