{"id":13580197,"url":"https://github.com/hardyscc/nestjs-dynamoose","last_synced_at":"2025-05-15T20:00:57.493Z","repository":{"id":37017795,"uuid":"248698207","full_name":"hardyscc/nestjs-dynamoose","owner":"hardyscc","description":"Dynamoose module for Nest","archived":false,"fork":false,"pushed_at":"2025-05-10T05:54:01.000Z","size":3733,"stargazers_count":146,"open_issues_count":5,"forks_count":24,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-10T06:28:11.972Z","etag":null,"topics":["dynamodb","dynamoose","nest","nestjs"],"latest_commit_sha":null,"homepage":"","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/hardyscc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-03-20T07:54:53.000Z","updated_at":"2025-05-10T05:53:16.000Z","dependencies_parsed_at":"2023-10-14T19:55:28.496Z","dependency_job_id":"da1e037c-6249-4460-bb0b-8487f0605fd8","html_url":"https://github.com/hardyscc/nestjs-dynamoose","commit_stats":{"total_commits":1289,"total_committers":8,"mean_commits":161.125,"dds":0.5531419705197828,"last_synced_commit":"27d58d69763bc2c9152f4dc729005dfbfd15ddcf"},"previous_names":[],"tags_count":51,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hardyscc%2Fnestjs-dynamoose","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hardyscc%2Fnestjs-dynamoose/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hardyscc%2Fnestjs-dynamoose/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hardyscc%2Fnestjs-dynamoose/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hardyscc","download_url":"https://codeload.github.com/hardyscc/nestjs-dynamoose/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254414457,"owners_count":22067263,"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":["dynamodb","dynamoose","nest","nestjs"],"created_at":"2024-08-01T15:01:48.569Z","updated_at":"2025-05-15T20:00:57.118Z","avatar_url":"https://github.com/hardyscc.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003ca href=\"http://nestjs.com/\" target=\"blank\"\u003e\u003cimg src=\"https://nestjs.com/img/logo_text.svg\" width=\"320\" alt=\"Nest Logo\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003eA progressive \u003ca href=\"http://nodejs.org\" target=\"blank\"\u003eNode.js\u003c/a\u003e framework for building efficient and scalable server-side applications.\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://www.npmjs.com/package/nestjs-dynamoose\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/nestjs-dynamoose\" alt=\"NPM Version\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/hardyscc/nestjs-dynamoose/blob/master/LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/github/license/hardyscc/nestjs-dynamoose\" alt=\"Package License\"\u003e\u003c/a\u003e\n\u003ca href=\"https://www.npmjs.com/package/nestjs-dynamoose\"\u003e\u003cimg src=\"https://img.shields.io/npm/dm/nestjs-dynamoose.svg\" alt=\"NPM Downloads\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/hardyscc/nestjs-dynamoose/actions\"\u003e\u003cimg src=\"https://github.com/hardyscc/nestjs-dynamoose/workflows/Node.js%20CI/badge.svg\" alt=\"CI\"\u003e\u003c/a\u003e\n\u003ca href=\"https://twitter.com/hardyscchk\"\u003e\u003cimg src=\"https://img.shields.io/twitter/follow/hardyscchk.svg?style=social\u0026label=Follow\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n## Description\n\n[Dynamoose](https://dynamoosejs.com/) module for [Nest](https://github.com/nestjs/nest).\n\n## Installation\n\n```bash\n$ npm install --save nestjs-dynamoose dynamoose\n```\n\n## Example Project\n\nA [AWS NestJS Starter](https://github.com/hardyscc/aws-nestjs-starter) project has been created to demo the usage of this library.\n\n## Quick Start\n\n**1. Add import into your app module**\n\n`src/app.module.ts`\n\n```ts\nimport { DynamooseModule } from 'nestjs-dynamoose';\nimport { UserModule } from './user/user.module';\n\n@Module({\n imports: [\n   DynamooseModule.forRoot(),\n   UserModule,\n ],\n})\nexport class AppModule {\n```\n\n`forRoot()` optionally accepts the following options defined by `DynamooseModuleOptions`:\n\n```ts\ninterface DynamooseModuleOptions {\n  aws?: {\n    accessKeyId?: string;\n    secretAccessKey?: string;\n    region?: string;\n  };\n  local?: boolean | string;\n  ddb?: DynamoDB;\n  table?: TableOptionsOptional;\n  logger?: boolean | LoggerService;\n}\n```\n\nThere is also `forRootAsync(options: DynamooseModuleAsyncOptions)` if you want to use a factory with dependency injection.\n\n**2. Create a schema**\n\n`src/user/user.schema.ts`\n\n```ts\nimport { Schema } from 'dynamoose';\n\nexport const UserSchema = new Schema({\n  id: {\n    type: String,\n    hashKey: true,\n  },\n  name: {\n    type: String,\n  },\n  email: {\n    type: String,\n  },\n});\n```\n\n`src/user/user.interface.ts`\n\n```ts\nexport interface UserKey {\n  id: string;\n}\n\nexport interface User extends UserKey {\n  name: string;\n  email?: string;\n}\n```\n\n`UserKey` holds the hashKey/partition key and (optionally) the rangeKey/sort key. `User` holds all attributes of the document/item. When creating this two interfaces and using when injecting your model you will have typechecking when using operations like `Model.update()`.\n\n**3. Add the models you want to inject to your modules**\n\nThis can be a feature module (as shown below) or within the root AppModule next to `DynamooseModule.forRoot()`.\n\n`src/user/user.module.ts`\n\n```ts\nimport { DynamooseModule } from 'nestjs-dynamoose';\nimport { UserSchema } from './user.schema';\nimport { UserService } from './user.service';\n\n@Module({\n  imports: [\n    DynamooseModule.forFeature([{\n      name: 'User',\n      schema: UserSchema,\n      options: {\n        tableName: 'user',\n      },\n    }]),\n  ],\n  providers: [\n    UserService,\n    ...\n  ],\n})\nexport class UserModule {}\n```\n\n\u003e `options.tableName` is optional. If it is not provided, `name` will be used as the table name.\n\nThere is also `forFeatureAsync(factories?: AsyncModelFactory[])` if you want to use a factory with dependency injection. Notes that the first parameter of the `useFactory` callback is reserved for future use, so please just add `_,` to ignore it.\n\nThe following example will use `USER_TABLE_NAME` environment variable as the table name.\n\n```ts\nimport { DynamooseModule } from 'nestjs-dynamoose';\nimport { UserSchema } from './user.schema';\nimport { UserService } from './user.service';\n\n@Module({\n  imports: [\n    ConfigModule.forRoot({ isGlobal: true }),\n    DynamooseModule.forFeatureAsync([\n      {\n        name: 'User',\n        useFactory: (_, configService: ConfigService) =\u003e {\n          return {\n            schema: UserSchema,\n            options: {\n              tableName: configService.get\u003cstring\u003e('USER_TABLE_NAME'),\n            },\n          };\n        },\n        inject: [ConfigService],\n      },\n    ]),\n  ],\n  providers: [\n    UserService,\n    ...\n  ],\n})\nexport class UserModule {}\n```\n\n**4. Inject and use your model**\n\n`src/user/user.service.ts`\n\n```ts\nimport { Injectable } from '@nestjs/common';\nimport { InjectModel, Model } from 'nestjs-dynamoose';\nimport { User, UserKey } from './user.interface';\n\n@Injectable()\nexport class UserService {\n  constructor(\n    @InjectModel('User')\n    private userModel: Model\u003cUser, UserKey\u003e,\n  ) {}\n\n  create(user: User) {\n    return this.userModel.create(user);\n  }\n\n  update(key: UserKey, user: Partial\u003cUser\u003e) {\n    return this.userModel.update(key, user);\n  }\n\n  findOne(key: UserKey) {\n    return this.userModel.get(key);\n  }\n\n  findAll() {\n    return this.userModel.scan().exec();\n  }\n}\n```\n\n## Additional Example\n\n**1. Transaction Support**\n\nBoth `User` and `Account` model objects will commit in same transaction.\n\n```ts\nimport { Injectable } from '@nestjs/common';\nimport { InjectModel, Model, TransactionSupport } from 'nestjs-dynamoose';\nimport { User, UserKey } from './user.interface';\nimport { Account, AccountKey } from './account.interface';\n\n@Injectable()\nexport class UserService extends TransactionSupport {\n  constructor(\n    @InjectModel('User')\n    private userModel: Model\u003cUser, UserKey\u003e,\n    @InjectModel('Account')\n    private accountModel: Model\u003cAccount, AccountKey\u003e,\n  ) {\n    super();\n  }\n\n  async create(user: User, account: Account) {\n    await this.transaction([\n      this.userModel.transaction.create(user),\n      this.accountModel.transaction.create(account),\n    ]);\n  }\n}\n```\n\n**2. Serializers Support**\n\nDefine the additional `serializers` under `DynamooseModule.forFeature()`.\n\n```ts\n@Module({\n  imports: [\n    DynamooseModule.forFeature([\n      {\n        name: 'User',\n        schema: UserSchema,\n        serializers: {\n          frontend: { exclude: ['status'] },\n        },\n      },\n    ]),\n  ],\n  ...\n})\nexport class UserModule {}\n```\n\nCall the `serialize` function to exclude the `status` field.\n\n```ts\n@Injectable()\nexport class UserService {\n  ...\n  async create(user: User) {\n    const createdUser = await this.userModel.create(user);\n    return createdUser.serialize('frontend');\n  }\n  ...\n}\n```\n\n## License\n\nDynamoose module for Nest is [MIT licensed](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhardyscc%2Fnestjs-dynamoose","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhardyscc%2Fnestjs-dynamoose","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhardyscc%2Fnestjs-dynamoose/lists"}