{"id":16888092,"url":"https://github.com/otbe/typed-db","last_synced_at":"2025-04-11T12:50:33.639Z","repository":{"id":57383366,"uuid":"81616295","full_name":"otbe/typed-db","owner":"otbe","description":"Entity manager for IndexedDB written entirely in TypeScript","archived":false,"fork":false,"pushed_at":"2017-02-12T08:50:59.000Z","size":71,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-25T17:05:41.450Z","etag":null,"topics":[],"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/otbe.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":"2017-02-10T23:29:02.000Z","updated_at":"2024-03-16T23:21:00.000Z","dependencies_parsed_at":"2022-09-26T16:50:29.958Z","dependency_job_id":null,"html_url":"https://github.com/otbe/typed-db","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/otbe%2Ftyped-db","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/otbe%2Ftyped-db/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/otbe%2Ftyped-db/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/otbe%2Ftyped-db/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/otbe","download_url":"https://codeload.github.com/otbe/typed-db/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248402655,"owners_count":21097338,"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":[],"created_at":"2024-10-13T16:48:54.238Z","updated_at":"2025-04-11T12:50:33.621Z","avatar_url":"https://github.com/otbe.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# typed-db\n[![Build Status](https://travis-ci.org/otbe/typed-db.svg?branch=master)](https://travis-ci.org/otbe/typed-db)\n\n```typed-db``` is a small promise-based entity manager for IndexedDB written entirely in TypeScript. \nIn general it exposes almost the same API as the native IndexedDB factory, but all available methods are wrapped in promises.\nAdditionally it allows you to define your entities in a more declarative way.\n\n```typescript\n@Entity()\nclass Employee {\n  @Key({ autoIncrement: true })\n  id?: number;\n\n  name: string;\n\n  @Index()\n  age: number;\n\n  @Index()\n  salary: number;\n}\n\nconst db = new Db('myDb', 1);\ndb.use(Employee);\n\nconst getAllEmployees = () =\u003e \n  db.transaction([Employee], 'readonly', \n    tx =\u003e tx.for(Employee).openCursor().asList()\n  );\n\ngetAllEmployees().then(employees =\u003e {\n  console.log('Transaction has finished successfully.');\n  console.log(employees);\n})\n```\nFor more query examples see ```tests/Db.ts``` :)\n\n## Install\nYour environment needs support for the [Reflect Metadata API](https://rbuckton.github.io/reflect-metadata/), so install a proper polyfill alongside ```typed-db``` if you haven't already one :)\n```\n$ npm install typed-db reflect-metadata --save\n```\nor\n```\n$ yarn add typed-db reflect-metadata\n```\n\nAdditionally you will need a Promise polyfill, Map polyfill and some ES2015 array functions (e.g. find).\n```babel-polyfill``` satisfies all this requirements :)\n\n\n## API\n\n### ```Db```\nCreates the database object, opens the connection if needed and let you register your entities.\n\n```typescript\n// pass in database name and version\nconst db = new Db('dbname', 1);\ndb.use(Foo);\n```\n\nIf you increase the version number, you have to add migrations for you entites. \nSee the migration guide for an example. (TODO)\n\nCreate a transaction:\n```typescript\n// pass in an array of entities which are in the same transaction scope\n// set the mode of the transaction, supported: readwrite | readonly\n// callback with transaction (tx), return value of this function will be the result of the transaction, can be async\ndb.transaction([Foo], 'readwrite', tx =\u003e {...});\n```\n\n### ```@Entity```\n\n```typescript\nfunction Entity(): ClassDecorator;\n```\n\nSets up a class to be used as a collection.\n\n### ```@Key```\n\n```typescript\nfunction Key(options?: KeyOptions): PropertyDecorator;\n```\n\nIndentifies a property as a primary key of the entity.\nYou can create compound keys by applying ```@Key``` multiple times.\nIn this case the optional ```options``` object is omitted.\n\n### ```@Index```\n\nCreates an index for the property its applied on.\n```typescript\nfunction Index(): PropertyDecorator;\nfunction Index(options: IDBIndexParameters): PropertyDecorator;\nfunction Index(key: string): PropertyDecorator;\nfunction Index(key: string, options: IDBIndexParameters): PropertyDecorator;\n```\nThis decorator has multiple overloads, for examle you can create a named\nindex by applying ```@Index('myIndex')``` or set some options ```@Index({ unique: true })```.\n\nYou can easily create an compound index by using the same name for multiple properties:\n```typescript\n@Entity()\nclass Foo {\n  @Index('compoundIndex')\n  age: number;\n\n  @Index('compoundIndex')\n  salary: number;\n}\n```\n\n## Contribution\nFile an issue or place a PR if you want to :)\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fotbe%2Ftyped-db","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fotbe%2Ftyped-db","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fotbe%2Ftyped-db/lists"}