{"id":20641868,"url":"https://github.com/mits87/nestjs-dynamodb","last_synced_at":"2026-05-08T06:03:31.822Z","repository":{"id":65456988,"uuid":"437399272","full_name":"mits87/nestjs-dynamodb","owner":"mits87","description":"Opinionated way to use DynamoDB with NestJS and typescript","archived":false,"fork":false,"pushed_at":"2021-12-12T00:50:06.000Z","size":13,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-09T14:20:00.152Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/mits87.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2021-12-11T22:11:11.000Z","updated_at":"2022-01-13T16:34:20.000Z","dependencies_parsed_at":"2023-01-24T11:55:12.956Z","dependency_job_id":null,"html_url":"https://github.com/mits87/nestjs-dynamodb","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mits87/nestjs-dynamodb","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mits87%2Fnestjs-dynamodb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mits87%2Fnestjs-dynamodb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mits87%2Fnestjs-dynamodb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mits87%2Fnestjs-dynamodb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mits87","download_url":"https://codeload.github.com/mits87/nestjs-dynamodb/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mits87%2Fnestjs-dynamodb/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32769110,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-08T02:36:36.067Z","status":"ssl_error","status_checked_at":"2026-05-08T02:36:07.210Z","response_time":54,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2024-11-16T16:07:04.371Z","updated_at":"2026-05-08T06:03:31.803Z","avatar_url":"https://github.com/mits87.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NestJS DynamoDB Mapper\n\n## Description\n\nOpinionated way to use DynamoDB with NestJS and typescript, heavily inspired by [nestjs-typed-dynamodb](https://www.npmjs.com/package/nestjs-typed-dynamodb)\n\n## Getting Started\n\nFirst install this module\n\n`npm install nestjs-dynamodb`\n\nNotice that it will install as a dependency:\n\n- [dynamodb-data-mapper-annotations](https://github.com/awslabs/dynamodb-data-mapper-js/tree/master/packages/dynamodb-data-mapper-annotations)\n- [dynamodb-data-mapper](https://github.com/awslabs/dynamodb-data-mapper-js/tree/master/packages/dynamodb-data-mapper)\n\n## Usage\n\nIn order to create a DynamoDB connection\n\n**app.module.ts**\n\n```typescript\nimport { Module } from '@nestjs/common';\nimport { DynamoDBModule } from 'nestjs-dynamodb';\n\nimport { CatsModule } from './cat.module.ts';\n\n@Module({\n  imports: [\n    DynamoDBModule.forRoot({\n      AWSConfig: {},\n      dynamoDBOptions: {},\n    }),\n    CatsModule,\n  ],\n})\nexport class AppModule {}\n```\n\n**cats.module.ts**\n\n```typescript\nimport { Module } from '@nestjs/common';\nimport { DynamoDBModule } from 'nestjs-dynamodb';\n\nimport { CatEntity } from './cat.entity';\nimport { CatsService } from './cats.service';\n\n@Module({\n  imports: [DynamoDBModule.forFeature([CatEntity])],\n  providers: [CatsService],\n})\nexport class CatsModule {}\n```\n\nTo insert records to DynamoDB, you first need to create your table, for this we use [dynamodb-data-mapper-annotations](https://github.com/awslabs/dynamodb-data-mapper-js/tree/master/packages/dynamodb-data-mapper-annotations) (under the hood). Every decorator in that package is exposed in this package as well **BUT CAPITALIZED** .\n\n**cat.entity.ts**\n\n```typescript\nimport { Attribute, ReturnModel, Table } from 'nestjs-dynamodb';\nimport * as nanoid from 'nanoid';\n\n@Table('cat')\nclass CatEntity {\n  @HashKey({ defaultProvider: nanoid })\n  pk: string;\n\n  @RangeKey()\n  sk: string;\n\n  @HashKey()\n  pk2: string;\n\n  @RangeKey()\n  sk2: string;\n\n  @Attribute()\n  age: number;\n\n  @Attribute()\n  alive?: boolean;\n\n  @Attribute()\n  createdAt: Date;\n\n  @Attribute({ defaultProvider: () =\u003e new Date() })\n  updatedAt: Date;\n\n  // This property will not be saved to DynamoDB.\n  notPersistedToDynamoDb: string;\n}\n\nexport const Cat = ReturnModel\u003cCatEntity\u003e();\n```\n\nNote: nanoid is only used a way to assign a random id, feel free to use whatever you want\n\n**cats.service.ts**\n\n```typescript\nimport { Injectable } from '@nestjs/common';\nimport { ReturnModel, InjectModel } from 'nestjs-dynamodb';\n\nimport { Cat } from './cat.entity';\nimport { CatInput } from './cat.input';\n\n@Injectable()\nexport class CatsService {\n  constructor(@InjectModel(CatEntity) private readonly catModel: typeof Cat) {}\n\n  async all(input: Partial\u003cCatInput\u003e): Promise\u003cCat[]\u003e {\n    return this.catModel.query(input);\n  }\n\n  async find(id: string): Promise\u003cCat\u003e {\n    return this.catModel.find(id);\n  }\n\n  async create(input: CatInput): Promise\u003cCat\u003e {\n    return this.catModel.create(input);\n  }\n\n  async delete(input: string): Promise\u003cDynamoDB.DeleteItemOutput\u003e {\n    return this.catModel.delete(input);\n  }\n\n  async update(id: string, item: CatInput): Promise\u003cCat\u003e {\n    return this.catModel.update(id, item);\n  }\n}\n```\n\nNow you can use your service as you wish!\n\n## Async configuration\n\n**app.module.ts**\n\n```typescript\nimport { Module } from '@nestjs/common';\nimport { DynamoDBModule } from 'nestjs-dynamodb';\n\n@Module({\n  imports: [\n    DynamoDBModule.forRootAsync({\n      imports: [ConfigModule],\n      useFactory: async (config: ConfigService) =\u003e ({\n        AWSConfig: {\n          region: 'local',\n          accessKeyId: 'null',\n          secretAccessKey: 'null',\n        },\n        dynamoDBOptions: {\n          endpoint: config.get\u003cstring\u003e('DYNAMODB_URL', 'localhost:8000'),\n          sslEnabled: false,\n          region: 'local-env',\n        },\n      }),\n      inject: [ConfigService],\n    }),\n  ],\n})\nexport class AppModule {}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmits87%2Fnestjs-dynamodb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmits87%2Fnestjs-dynamodb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmits87%2Fnestjs-dynamodb/lists"}