{"id":24612716,"url":"https://github.com/scaffolds00/type-dynamodb","last_synced_at":"2025-06-20T14:10:53.967Z","repository":{"id":48642350,"uuid":"385744627","full_name":"scaffolds00/type-dynamodb","owner":"scaffolds00","description":"simple but powerful dynamodb ORM that uses decorators to get the most benefits from typescript and OOP like inheritance, override  methods and adding multiple  layers of decorators.","archived":false,"fork":false,"pushed_at":"2021-07-16T08:28:36.000Z","size":88,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-20T14:08:56.233Z","etag":null,"topics":["aws","decorator-pattern","decorators","dynamodb","orm","orm-framework","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/scaffolds00.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-07-13T21:57:07.000Z","updated_at":"2023-08-22T07:46:25.000Z","dependencies_parsed_at":"2022-08-30T02:02:23.636Z","dependency_job_id":null,"html_url":"https://github.com/scaffolds00/type-dynamodb","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/scaffolds00/type-dynamodb","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scaffolds00%2Ftype-dynamodb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scaffolds00%2Ftype-dynamodb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scaffolds00%2Ftype-dynamodb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scaffolds00%2Ftype-dynamodb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/scaffolds00","download_url":"https://codeload.github.com/scaffolds00/type-dynamodb/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scaffolds00%2Ftype-dynamodb/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260959194,"owners_count":23088822,"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":["aws","decorator-pattern","decorators","dynamodb","orm","orm-framework","typescript"],"created_at":"2025-01-24T20:25:11.973Z","updated_at":"2025-06-20T14:10:48.949Z","avatar_url":"https://github.com/scaffolds00.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# type-dynamodb\n\n**type-dynamodb** is simple but powerful dynamodb ORM that uses decorators to get the most benefits from typescript and OOP like inheritance, override methods and adding multiple  layers of decorators.\n\n[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)\n\n-----\n\n## Installation\n- first install the lib and its peerDependencies\n```shell\nnpm i class-transformer aws-sdk type-dynamodb --save\n```\n- install reflect-metadata :\n```shell\nnpm install `reflect-metadata` --save\n\n```\n- add `reflect-metadata` to the root file of your project\n```typescript\nimport \"reflect-metadata\";\n```\n- make sure to set AWS credients in your env variables using command line or .env ...etc:\n```shell\nexport AWS_ACCESS_KEY_ID=\u003cAWS_ID\u003e # macos or linux\nexport AWS_SECRET_ACCESS_KEY=\u003cAWS_ACCESS_KEY\u003e\nexport AWS_DEFAULT_REGION=\u003cAWS_REGION\u003e\n```\nor [here](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html) for other os. \n\n- in typescript, you need to add the following config to your `tsconfig.json`:\n```json\n\"emitDecoratorMetadata\": true,\n\"experimentalDecorators\": true,\n```\n-----\n## Usage example with table User:\n1- first we add `@DyTable` decorator and extends `BaseDyTable` to get the db functionalities. \n```typescript\n@DyTable('\u003cTableName\u003e') // default is User\nclass User extends BaseDyTable{\n    id: string\n    name: string\n    userPassword: string\n    created: string\n}\n```\n2- then we determined which fields are part of our dynamodb table by adding `@DyField`:\n```typescript\n@DyTable()\nclass User extends BaseDyTable{\n    @DyField()\n    id: string\n\n    @DyField()\n    name: string\n\n    @DyField()\n    userPassword: string\n\n    @DyField()\n    created: string\n}\n```\n3- then we specify the partition key field in `@DyField` and sorting key fields if exist:\n```typescript\n    ...\n\n    @DyField({isPartitionKey: true})\n    id: string\n\n    @DyField({isSortingKey: true})\n    created: string\n    \n    ...\n```\n4- now we can use the db functions (`dyGet`, `dyUpdate`, `dyDelete`, `dyPut`, `dyScan`, `dyQuery`) as shown here:\n```typescript\n    /* using await */\n    \n    const user = await User.dyGet({id: \"id1\"})\n    await user.dyUpdate({userPassword: \"12345\"});\n    await user.dyDelete();\n    // scan function\n    const scannedUsers = await User.dyScan(\n        {\n            filter: {\n                created: {range: {to:\"\u003cISOSTRING\u003e\"}},\n                name: {equal: \"Amro\"}\n            },// note every key can have only one   filter parameter.\n            limit: 50,\n        }\n    );\n    // faster query method that uses PartitionKey(must be specified) and specify sortingKey automatically\n    const users = await User.dyQuery(\n        \"PARTITION_KEY_VALUE\",\n        {\n        filter: {\n                created: {range: {from:\"\u003cISOSTRING\u003e\"}},\n                name: {contains: \"Amro\"}\n            } \n        }\n    );\n\n    /* using then */\n    User.dyGet({id: \"user1\"})\n        .then((user)=\u003e user.dyUpdate( {userPassword: \"12345\"}))\n        .then((updatedUser)=\u003e {\n            // some other logic\n            updatedUser.dyDelete();\n        })\n\n```\n\n-----\n\n## DyGlobalSecondaryIndex and DyLocalSecondaryIndex\n- for specifying local and global secondary index, use the following decorators:\n```typescript\n@DyTable()\nclass User {\n    ... \n\n    @DyGlobalSecondaryIndex(\"name_index\", {isPartitionKey: true})\n    @DyField()\n    name: string\n\n    @DyLocalSecondaryIndex(\"created_index\")\n    @DyField({isSortingKey: true})\n    created: string\n    \n    ...\n}\n```\n-  to use it specify the IndexName in the filter options:\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscaffolds00%2Ftype-dynamodb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscaffolds00%2Ftype-dynamodb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscaffolds00%2Ftype-dynamodb/lists"}