{"id":25001582,"url":"https://github.com/arkerlabs/redisk","last_synced_at":"2025-04-12T10:07:17.483Z","repository":{"id":38203197,"uuid":"236066492","full_name":"ArkerLabs/redisk","owner":"ArkerLabs","description":"TypeScript ORM for Redis. ","archived":false,"fork":false,"pushed_at":"2023-01-05T05:42:25.000Z","size":1540,"stargazers_count":33,"open_issues_count":22,"forks_count":8,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-12T10:06:48.012Z","etag":null,"topics":["redis","redis-orm","redisk","typescript-orm","user-entities"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ArkerLabs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-01-24T19:12:04.000Z","updated_at":"2024-07-28T18:11:58.000Z","dependencies_parsed_at":"2023-02-03T14:00:33.346Z","dependency_job_id":null,"html_url":"https://github.com/ArkerLabs/redisk","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArkerLabs%2Fredisk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArkerLabs%2Fredisk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArkerLabs%2Fredisk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArkerLabs%2Fredisk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ArkerLabs","download_url":"https://codeload.github.com/ArkerLabs/redisk/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248550635,"owners_count":21122933,"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":["redis","redis-orm","redisk","typescript-orm","user-entities"],"created_at":"2025-02-04T20:36:06.330Z","updated_at":"2025-04-12T10:07:17.465Z","avatar_url":"https://github.com/ArkerLabs.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e\n  \u003cimg src=\"https://raw.githubusercontent.com/ArkerLabs/redisk/master/docs/images/logo.png\" alt=\"Redisk\"\u003e\n\u003c/h1\u003e\n\n[![npm version](https://badge.fury.io/js/redisk.svg)](https://badge.fury.io/js/redisk) \n![Redisk CI](https://github.com/ArkerLabs/redisk/workflows/Redisk%20CI/badge.svg)\n\nRedisk is a TypeScript ORM library for Redis.\n\n\n## Features:\n\n* Store entities.\n* Single relation support.\n* Unique keys support.\n* Retrieve entities by his primary keys or his unique keys.\n* Indexes support.\n* List entities with common filters, like limit, count and sort by.\n* Find entities with multiple conditions ('\u003e', '\u003c', '=', '!=').\n* Search (Similar to LIKE in SQL)\n* And much more.\n\n\n## Quick overview\n```ts\nconst redisk = Redisk.init({url: 'redis://127.0.0.1:6379/0'});\n\n@Entity('user')\nexport class User {\n\n  @Primary()\n  @Property()\n  public readonly id: string;\n\n  @Property()\n  public name: string;\n\n  constructor(\n      id: string,\n      name: string,\n    ) {\n      this.id = id;\n      this.name = name;\n  }\n}\n\nawait redisk.save(new User('::id::', 'Foo'));\n\nconsole.log(await redisk.getOne(User, '::id::'));\n\n```\n\n\n## Installation\n```bash\nnpm install redisk --save\n```\n\n## Contents\n\n- [Connection](#connection)\n  - [Options](#options)\n- [Models](#models)\n  - [Model definition](#model-definition)\n  - [Entity](#entity)\n  - [Property](#property)\n    - [Supported types](#supported-types)\n  - [Primary](#primary)\n  - [Unique](#unique)\n  - [Embedding other entities](#embedding-other-entities)\n- [Queries](#queries)\n  - [Save](#save)\n  - [Update](#update)\n  - [Get by primary key](#get-by-primary-key)\n  - [Get by unique key](#get-by-unique-key)\n  - [Count](#count)\n  - [List all](#list-all)\n  - [List all with conditions](#find-all-by-index)\n    - [Simple](#simple)\n    - [Multiple conditions](#multiple-conditions)\n  - [Pattern matching](#pattern-matching)\n  - [Delete](#delete)\n- [Logging](#logging)\n\n\n## Connection\n\n```ts\nconst redisk = Redisk.init(options);\n```\n\n### Options\n| Property | Description                                                                                                                             |\n|----------|-----------------------------------------------------------------------------------------------------------------------------------------|\n| url      | URL of the Redis server. Format [redis[s]:]//[[user][:password@]][host][:port][/db-number][?db=db-number[\u0026password=bar[\u0026option=value]]] |\n| host     | Host of the Redis server                                                                                                                |\n| port     | Port of the Redis server                                                                                                                |\n| db       | Number of the db (Default: 0)                                                                                                           |\n| password | Password of the Redis server     \n\n\nClosing connection to Redis:\n\n```ts\nawait redisk.close();\n```\n\n## Models\n\n### Model definition\n```ts\n@Entity('user')\nexport class User {\n\n  @Primary()\n  @Property()\n  public readonly id: string;\n\n  @Property({searchable: true})\n  public name: string;\n\n  @Unique()\n  @Property()\n  public email: string;\n\n  @Property({indexed: true})\n  public color: string;\n\n  @HasOne(type =\u003e Group, {cascadeInsert: true, cascadeUpdate: true})\n  @Property()\n  public group: Group;\n\n  @Property({indexed: true})\n  public created: Date;\n\n  constructor(\n      id: string,\n      name: string,\n      email: string,\n      color: string,\n      group: Group,\n      created: Date,\n    ) {\n      this.id = id;\n      this.name = name;\n      this.email = email;\n      this.color = color;\n      this.group = group;\n      this.created = created;\n  }\n}\n```\n\n### Entity\nUse the decorator `Entity` to convert your class into a Redisk entity.\n\nYou can pass the option canBeListed to 'false' (Default is true) to save some space, but you will not be able to list user entities. \n\n```ts\n@Entity('user', { canBeListed: true })\nexport class User {\n}\n```\n\n### Property\nThe decorator `Property` is used to save the fields into redis.\n\nOptionally, you can pass the options `indexed` if you want to use the field to sort or to use as a condition in the 'list' method or `searchable` if you want to use pattern matching in this field.\n\nYou can also set a default value.\n\nBoth options are false by default.\n\n```ts\n@Entity('user')\nexport class User {\n\n    @Property({indexed: true, searchable: false, defaultValue: 'foo'})\n    public readonly created: Date;\n\n}\n```\n\n#### Supported types\nRedisk support multiple types to store and query. \n- String\n- Date (Will be saved as a timestamp)\n- Boolean\n- Number\n\nAll other types will be converted to a string.\n\n### Primary\n`Primary` decorator is used to define the primary key of the entity. It can only be one primary key and his value must be unique for all the same entities.\n```ts\n@Entity('user')\nexport class User {\n\n  @Primary()\n  @Property()\n  public readonly id: string;\n}\n```\n\n### Unique\nThis decorator is used to make the value of this field unique for all the same entities. \nThen you can use it to query the entity.\n```ts\n@Entity('user')\nexport class User {\n\n  @Unique()\n  @Property()\n  public readonly email: string;\n}\n```\n\n### Embedding other entities\nYou can make one to one relations with the `HasOne` decorator.\n\nCascade inserts and updates are supported. (These options are false by default)\n\n```ts\n@Entity('user')\nexport class User {\n\n  @HasOne(type =\u003e Group, {cascadeInsert: true, cascadeUpdate: true})\n  @Property()\n  public readonly group: Group;\n}\n```\n\n## Queries\n\n### Save\n\n```ts\nawait redisk.save(new User(id, name));\n```\n\n### Update\n\n```ts\nconst user = await redisk.getOne(User, id);\nuser.name = 'Bar';\nawait redisk.save(user);\n```\n#### Note: Null fields will be removed from the persisted entity, undefined fields will not be modified from persisted entity.\n\n### Get by primary key\n\n```ts\nawait redisk.getOne(User, id);\n```\n\n### Get by unique key \n\n```ts\nconst value = 'john@doe.com';\nconst uniqueKeyName = 'email';\nawait redisk.getOne(User, value, uniqueKeyName);\n```\n\n### Count\n\n```ts\nawait redisk.count(User);\n```\n\n### List all\nReturns an array of all user entities.\n```ts\nawait redisk.list(User); \n```\n\nReturns the first 10 user entities\n```ts\nconst limit = 10;\nconst offset = 0;\nawait redis.list(User, limit, offset);\n```\n\nReturn an array of user entities sorted by his creation date in descending order\n```ts\nawait redisk.list(User, undefined, undefined, undefined, {\n    field: 'created',\n    strategy: 'DESC',\n});\n```\n\n### List all with conditions\n#### Simple\nReturns an array of users where his color is red\n\n```ts\nconst where = \n    conditions: [\n        {\n            key: 'color',\n            value: 'red',\n            comparator: '=',\n        },\n    ],\n    type: 'AND',\n};\nawait redisk.list(User, where, limit, offset); \n```\n\nReturns an array of users where his creation date is greater than the day 23\n```ts\nconst where = \n    conditions: [\n        {\n            key: 'created',\n            value: new Date('2020-02-23 00:00:00'),\n            comparator: '\u003e',\n        },\n    ],\n    type: 'AND',\n};\nawait redisk.list(User, where, limit, offset); \n```\n\n#### Multiple conditions\nReturns an array of entities that his color field is 'red' or 'blue'.\n\nWarning: Using multiple conditions leads to multiple queries with table intersections, to achieve high performance queries try to reduce the results with more concise conditional.\n\n```ts\nconst where = \n    conditions: [\n        {\n            key: 'color',\n            value: 'red',\n            comparator: '=',\n        },\n        {\n            key: 'color',\n            value: 'blue',\n            comparator: '=',\n        },\n    ],\n    type: 'OR',\n};\nawait redisk.list(User, where, limit, offset);\n```\n\nReturns an array of entities that his color field is 'red' and his food field is 'avocado'\n```ts\nconst where = \n    conditions: [\n        {\n            key: 'color',\n            value: 'red',\n            comparator: '=',\n        },\n        {\n            key: 'food',\n            value: 'avocado',\n            comparator: '=',\n        },\n    ],\n    type: 'AND',\n};\nawait redisk.list(User, where, limit, offset);\n```\n\n### Pattern matching\n\nYou can search entities by properties marked as searchables.\n\n```ts\nconst condition = {\n    key: 'name',\n    value: 'John',\n};\nconst maxNumberOfResults = 10;\nawait redisk.search(User, condition, maxNumberOfResults);\n```\n\n### Delete\n\n```ts\nawait redisk.delete(User, id);\n```\n\n## Logging\n\nWe use [winston](https://github.com/winstonjs/winston) for logging, if you want to see more info, like redis command that are being executed you can set process.env.REDISK_LOG_LEVEL to 'info'.\n\nFor example:\n\n```bash\nREDISK_LOG_LEVEL=info npm test\n```\n\n## Stay in touch\n- Author - [Nytyr](https://keybase.io/nytyr)\n- Website - [https://arkerlabs.com/](https://arkerlabs.com/)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farkerlabs%2Fredisk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farkerlabs%2Fredisk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farkerlabs%2Fredisk/lists"}