{"id":16371294,"url":"https://github.com/deptno/dynalee","last_synced_at":"2025-07-22T21:36:12.216Z","repository":{"id":57217597,"uuid":"154837551","full_name":"deptno/dynalee","owner":"deptno","description":"🍳 DynamoDB Typescript ORM","archived":false,"fork":false,"pushed_at":"2019-01-07T07:43:16.000Z","size":731,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-18T06:25:40.385Z","etag":null,"topics":["dynamodb","dynamodb-orm","dynamodb-typescript","dynamodb-typescript-orm","orm","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/deptno.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":"2018-10-26T13:17:51.000Z","updated_at":"2024-01-29T06:41:20.000Z","dependencies_parsed_at":"2022-08-28T21:41:21.903Z","dependency_job_id":null,"html_url":"https://github.com/deptno/dynalee","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deptno%2Fdynalee","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deptno%2Fdynalee/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deptno%2Fdynalee/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deptno%2Fdynalee/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/deptno","download_url":"https://codeload.github.com/deptno/dynalee/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221843120,"owners_count":16890262,"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","dynamodb-orm","dynamodb-typescript","dynamodb-typescript-orm","orm","typescript"],"created_at":"2024-10-11T03:07:34.347Z","updated_at":"2024-10-28T14:47:55.389Z","avatar_url":"https://github.com/deptno.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dynalee\n\n**dyanlee** is **DML** only **DynamoDB ORM**\n\nStrongly typed.\n\nDefine model with way to follow DynamoDB philosophy.\n\n## usage\n### Model\n#### define hash model\n```typescript\nimport {HashModel} from 'dynalee'\n\ninterface Cat {\n  name: string\n  birth: number\n  color: string\n}\n\nconst CatModel = new HashModel\u003cCat, 'name'\u003e({\n  table: 'TableName',\n  hashKey: 'name'\n})\n\nconst aCat = CatModel.of({\n  name: 'first cat',\n  birth: 2018,\n  color: 'white'\n})\n\nconst docCat = await aCat.put() // save\nconsole.log(docCat.head())\n/*\n{\n  name: 'first cat'\n  birth: 2018\n  color: 'white'\n}\n*/\n```\n\n#### define multiple model in one table\n```typescript\nimport {RangeModel} from 'dynalee'\n\ninterface Index {\n  name: string\n  birth: number\n}\ninterface Cat extends Index {\n  color: string\n  age?: number,\n  doYouWantSet?: string[]|Set\u003cstring\u003e // use union for DynamoDB type and javascript type\n  doYouWantList?: string[]\n}\ninterface Dog extends Index {\n  longLegs: boolean\n}\n\nconst model = new RangeModel\u003cIndex, 'name', 'birth'\u003e({\n  table: 'TableName',\n  hashKey: 'name',\n  rangeKey: 'birth',\n})\nconst CatModel = model as RangeModel\u003cCat, 'name', 'birth'\u003e\nconst DogModel = model as RangeModel\u003cDog, 'name', 'birth'\u003e\n```\n\n#### update \n```typescript\nCatModel\n    .update('deptno cat', '1985')\n    .update(setter =\u003e {\n      setter \n          .of({\n            age: 10,\n            color: 'white'\n          }) // set multiple props\n    })\n    condition(setter =\u003e {\n      setter.attributeNotExists('ID')\n    })\n    .returnValue('NONE')\n    .run()\n```\n\n#### update 2\n```typescript\nCatModel\n    .update('deptno cat', '1985')\n    .update(setter =\u003e {\n      setter \n        .set('color', 'white')\n        .add('age', 10)\n    })\n    condition((and, or, not) =\u003e {\n      and.attributeNotExists('ID')\n    })\n    .returnValue('NONE')\n    .run()\n```\n\n#### delete\n```typescript\nCatModel.delete('deptno cat', '1985')\n```\n\n#### get item\n```typescript\nCatModel.get('deptno cat', '1985')\n```\n\n### Document\n\n#### create\n```typescript\nconst document = await CatModel\n    .of({\n        name: 'son of deptno cat',\n        birth: '2006',\n        age: 10\n    })\n    .put() // save\n```\n\n#### get raw data\n```typescript\nconst document = await CatModel.get('deptno cat', '1985')\nconst rawdata = document.head()\n```\n\n#### delete\n```typescript\nconst document = await CatModel.get('deptno cat', '1985')\ndocument.delete()\n```\n\n#### put\n```typescript\nconst document = await CatModel.get('deptno cat', '1985')\nawait document\n    .set(setter =\u003e {\n      setter.age = 10\n      setter.color = 'white'\n    })\n    .put()\n```\n\n### SecondaryIndex\n#### define secondary index\n```typescript\nimport {SecondaryIndex} from 'dynalee'\n\ninterface Index {\n  name: string\n  birth: number\n}\ninterface Cat extends Index {\n  color: string\n}\ninterface Dog extends Index {\n  longLegs: boolean\n}\n\nconst model = new SecondaryIndex\u003cIndex, 'name', 'birth'\u003e({\n  table: 'TableName',\n  index: 'IndexTable',\n  hashKey: 'species',\n  rangeKey: 'birth'\n})\nconst CatModel = model as SecondaryIndex\u003cCat, 'name', 'birth'\u003e\nconst DogModel = model as SecondaryIndex\u003cDog, 'name', 'birth'\u003e\n```\n\n#### query on secondary index\n```typescript\nconst documents = await CatModel\n    .query('Turkish Angora')\n    .run()\nconst items = documents.Items.map(item =\u003e item.head())\n```\n\n#### query on secondary index\n```typescript\nconst documents = await CatModel\n    .rangeQuery('Turkish Angora')\n    .eq('2006')\n    .run()\nconst items = documents.Items.map(item =\u003e item.head())\n```\n\n#### more query options\n```typescript\nconst nextToken = null\nconst documents = await CatModel\n    .rangeQuery('Turkish Angora')\n    .eq('2006')\n    .desc()\n    .consistent()\n    .limit(10)\n    .startAt(nextToken)\n    .run()\nconst items = documents.Items.map(item =\u003e item.head())\n```\n\n#### scan on secondary index\n```typescript\nconst documents = await CatModel\n    .scan()\n    .filter(setter =\u003e {\n        setter.attributeNotExists('specis')\n    })\n    .run()\nconst items = documents.Items.map(item =\u003e item.head())\n```\n\n### advanced usage\n\n#### Set\n```typescript\nconst cat = await CatModel\n    .of({\n      name: 'my cat',\n      birth: '2018',\n      age: 10,\n      doYouWantSet: new Set(['string set 1', 'string set 2'])\n    })\n    .update(setter =\u003e { // example code, `of` method can include below props\n      setter\n        .plus('age', 1)\n        .add('doYouWantSet', new Set(['string set 3']))\n    })\n    .put()\n    \nconst document = cat.head()\nconsole.log(document.doYouWantSet instanceof Set) // true\n\nconst jsDocument = cat.head(true)\nconsole.log(jsDocument.doYouWantSet instanceof Set) // false\nconsole.log(Array.isArray(jsDocument.doYouWantSet)) // true\n```\n\n#### List\n```typescript\nconst cat = await CatModel\n    .of({\n      name: 'my cat',\n      birth: '2018',\n      age: 10,\n      doYouWantList: ['string 1', 'string 2']\n    })\n    .update(setter =\u003e { // example code, `of` method can include below props\n      setter\n        .plus('age', 1)\n        .add('doYouWantSet', ['string 3'])\n    })\n    .put()\n```\n\n#### Trigger\n\nlikes CreatedAt, UpdatedAt\n\n```typescript\nimport {HashModel, DocumentOptions} from 'dynalee'\nconst document: DocumentOptions = {\n  onCreate: [\n    {\n      attributeName: 'CreatedAt',\n      handler(prevVal?) {\n        return new Date().toISOString()\n      }\n    },\n  ],\n  onUpdate: [\n    {\n      attributeName: 'UpdatedAt',\n      handler(prevVal?) {\n        return new Date().toISOString()\n      }\n    }\n  ],\n}\ninterface Cat {\n  name: string\n}\nconst CatModel = new HashModel\u003cCat, 'name'\u003e({\n  table: 'TableName',\n  hashKey: 'name',\n  options: {\n    document\n  }\n})\n```\n\n#### use with [dynamon](https://github.com/deptno/dynamon)\n```typescript\nimport {HashModel} from 'dynalee'\ninterface Cat {\n  name: string\n}\nconst CatModel = new HashModel\u003cCat, 'name'\u003e({\n  table: 'TableName',\n  hashKey: 'name',\n  options: {\n    aws: {\n      region  : 'dynamon',\n      endpoint: 'http://localhost:8000'\n    },\n  }\n})\n```\n\n## link\n\n[#dynamon](https://github.com/deptno/dynamon)\n\n## license\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeptno%2Fdynalee","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeptno%2Fdynalee","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeptno%2Fdynalee/lists"}