{"id":14978698,"url":"https://github.com/onhate/nest-onetable","last_synced_at":"2025-10-28T11:31:49.969Z","repository":{"id":188330828,"uuid":"678574312","full_name":"onhate/nest-onetable","owner":"onhate","description":"A convenient way to integrate the power of DynamoDB OneTable with NestJS applications. It simplifies the process of creating and working with DynamoDB tables using the OneTable library within your NestJS modules.","archived":false,"fork":false,"pushed_at":"2023-11-30T13:24:29.000Z","size":172,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-05T16:50:58.531Z","etag":null,"topics":["bigtable","dynamodb","lambda","module","nestjs","onetable","single-table-design","typescript"],"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/onhate.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,"governance":null}},"created_at":"2023-08-14T21:50:39.000Z","updated_at":"2024-08-16T14:32:03.000Z","dependencies_parsed_at":"2023-10-14T20:28:56.994Z","dependency_job_id":"3d3b4deb-7813-4e21-bea4-798f62b72379","html_url":"https://github.com/onhate/nest-onetable","commit_stats":null,"previous_names":["onhate/nest-onetable"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onhate%2Fnest-onetable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onhate%2Fnest-onetable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onhate%2Fnest-onetable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onhate%2Fnest-onetable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/onhate","download_url":"https://codeload.github.com/onhate/nest-onetable/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238645862,"owners_count":19506919,"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":["bigtable","dynamodb","lambda","module","nestjs","onetable","single-table-design","typescript"],"created_at":"2024-09-24T13:58:12.683Z","updated_at":"2025-10-28T11:31:49.655Z","avatar_url":"https://github.com/onhate.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @OneTable\n\nWelcome to the **Nest-Onetable** library! This library provides a convenient way to integrate the power\nof [DynamoDB OneTable](https://github.com/sensedeep/dynamodb-onetable) with [NestJS](https://nestjs.com/) applications.\nIt simplifies the process of creating and working with DynamoDB tables using the OneTable library within your NestJS\nmodules.\n\n## Table of Contents\n\n- [Installation](#installation)\n- [Usage](#usage)\n    - [Module Registration](#module-registration)\n    - [Creating a Model](#creating-a-model)\n    - [Under the Hood](#under-the-hood)\n- [Contributing](#contributing)\n- [License](#license)\n\n## Installation\n\nTo start using the Nest-Onetable library in your NestJS project, follow these steps:\n\n1. Install the package using npm or yarn:\n\n```bash\nnpm install nest-onetable\n```\n\nor\n\n```bash\nyarn add nest-onetable\n```\n\n## Usage\n\n### Module Registration\n\nTo get started, you need to register the `nest-onetable` module in your NestJS application. Here's how you can do it:\n\n```typescript\nimport { DynamoDBClient } from '@aws-sdk/client-dynamodb';\nimport { Module } from '@nestjs/common';\nimport { ConfigService } from '@nestjs/config';\nimport { OnetableModule } from 'nest-onetable';\n\n@Module({\n  imports: [\n    OnetableModule.register({\n      // here you can pass either the configuration object you would pass to the new Table() constructor directly or \n      // a factory provider that returns the configuration object but with the benefits of dependency injection\n      useFactory(config: ConfigService, client: DynamoDBClient) {\n        return {\n          client,\n          global: false, // optional, defaults to true\n          name: config.get('ONETABLE_NAME'),\n          partial: true,\n          schema: {\n            format: 'onetable:1.1.0',\n            version: '0.0.1',\n            indexes: {\n              primary: { hash: 'pk', sort: 'sk' }\n            },\n            models: {}\n          }\n        };\n      },\n      inject: [ConfigService, DynamoDBClient]\n    })\n  ]\n})\nexport class AppModule {}\n```\n\nNow you can inject the `Table` instance into your services (but you don't need to do that, keep reading!):\n\n```typescript\nimport { Injectable } from '@nestjs/common';\nimport { Table } from 'dynamodb-onetable';\nimport { OneTable } from 'nest-onetable';\n\n@Injectable()\nclass UsersService {\n  constructor(@OneTable() public readonly table: Table) {\n  }\n}\n```\n\n### Creating a Model\n\nThe boring part of creating a model is to have the `Table` instance to pass to the `Model` constructor. But\nthe `nest-onetable` `OneModel` class factory simplifies the process of creating OneTable Models. See below:\n\n```typescript\nimport { Injectable } from '@nestjs/common';\nimport { OneModel } from 'nest-onetable';\n\n@Injectable()\nexport class UsersModel extends OneModel('Users', {\n  pk: { type: String, value: 'Users#', hidden: true },\n  sk: { type: String, value: 'Users#${id}', hidden: true },\n  id: { type: String, generate: 'ulid', required: true },\n  name: { type: String, required: true }\n}) {}\n\n@Injectable()\nclass UsersService {\n  constructor(public readonly model: UsersModel) {\n  }\n\n  getUsers() {\n    return this.model.query(); // thanks to OneTable type inferences from the schema you get a typed object here\n  }\n}\n```\n\n### Under the Hood\n\nThe `OneModel` class factory is a wrapper around the `Model` class constructor. It creates a new class that extends the\n`Model` and already injects the `Table` instance into the constructor facilitated by Nest.js the dependency injection.\n\n[See the code](./src/decorators.ts)\n\n## Contributing\n\nContributions are welcome! If you find a bug or have a feature request, please open an issue on\nthe [GitHub repository](https://github.com/onhate/nest-onetable).\n\n## License\n\nThis project is licensed under the [MIT License](LICENSE).\n\n---\n\nWe hope you find the `nest-onetable` library helpful for your NestJS applications. If you have any questions or need\nassistance, feel free to reach out to us on the [GitHub repository](https://github.com/onhate/nest-onetable). Happy\ncoding! 🚀\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonhate%2Fnest-onetable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fonhate%2Fnest-onetable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonhate%2Fnest-onetable/lists"}