{"id":28092370,"url":"https://github.com/freshgiammi-lab/connect-typeorm","last_synced_at":"2025-05-13T13:09:51.931Z","repository":{"id":26893790,"uuid":"109745287","full_name":"freshgiammi-lab/connect-typeorm","owner":"freshgiammi-lab","description":"A TypeORM-based session store.","archived":false,"fork":false,"pushed_at":"2023-02-04T14:09:40.000Z","size":1391,"stargazers_count":48,"open_issues_count":9,"forks_count":25,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-17T09:52:31.424Z","etag":null,"topics":["nodejs","typeorm","typescript"],"latest_commit_sha":null,"homepage":"https://npmjs.com/package/connect-typeorm","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/freshgiammi-lab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null}},"created_at":"2017-11-06T20:20:34.000Z","updated_at":"2023-04-05T17:29:14.000Z","dependencies_parsed_at":"2023-02-13T21:05:16.477Z","dependency_job_id":null,"html_url":"https://github.com/freshgiammi-lab/connect-typeorm","commit_stats":null,"previous_names":["makepost/connect-typeorm"],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freshgiammi-lab%2Fconnect-typeorm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freshgiammi-lab%2Fconnect-typeorm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freshgiammi-lab%2Fconnect-typeorm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freshgiammi-lab%2Fconnect-typeorm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/freshgiammi-lab","download_url":"https://codeload.github.com/freshgiammi-lab/connect-typeorm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253948432,"owners_count":21988957,"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":["nodejs","typeorm","typescript"],"created_at":"2025-05-13T13:06:38.611Z","updated_at":"2025-05-13T13:09:51.919Z","avatar_url":"https://github.com/freshgiammi-lab.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003ch1\u003e🔗 connect-typeorm\u003c/h1\u003e\n  \u003ch3\u003eA TypeORM-based session store.\u003ch3\u003e\u003cbr/\u003e\n\n[![CodeFactor](https://www.codefactor.io/repository/github/freshgiammi-lab/connect-typeorm/badge)](https://www.codefactor.io/repository/github/freshgiammi-lab/connect-typeorm)\n[![GitHub Repo stars](https://img.shields.io/github/stars/freshgiammi-lab/connect-typeorm)](https://github.com/freshgiammi-lab/connect-typeorm/stargazers)\n\n\u003c/div\u003e\n\n## Setup \u0026 Usage\n\nConfigure TypeORM with back end of your choice:\n\n### NPM\n\n```bash\nnpm install connect-typeorm express-session typeorm sqlite3\nnpm install -D @types/express-session\n```\n\n## Implement the `Session` entity:\n\n```typescript\n// src/domain/Session/Session.ts\n\nimport { ISession } from 'connect-typeorm';\nimport { Column, DeleteDateColumn, Entity, Index, PrimaryColumn } from 'typeorm';\n\n@Entity()\nexport class Session implements ISession {\n  @Index()\n  @Column('bigint')\n  public expiredAt = Date.now();\n\n  @PrimaryColumn('varchar', { length: 255 })\n  public id = '';\n\n  @Column('text')\n  public json = '';\n\n  @DeleteDateColumn()\n  public destroyedAt?: Date;\n}\n```\n\nPass repository to `TypeormStore`:\n\n```typescript\n// src/app/Api/Api.ts\n\nimport { TypeormStore } from 'connect-typeorm';\nimport { getRepository } from 'typeorm';\nimport * as Express from 'express';\nimport * as ExpressSession from 'express-session';\n\nimport { Session } from '../../domain/Session/Session';\n\nexport class Api {\n  public sessionRepository = getRepository(Session);\n\n  public express = Express().use(\n    ExpressSession({\n      resave: false,\n      saveUninitialized: false,\n      store: new TypeormStore({\n        cleanupLimit: 2,\n        limitSubquery: false, // If using MariaDB.\n        ttl: 86400,\n      }).connect(this.sessionRepository),\n      secret: 'keyboard cat',\n    })\n  );\n}\n```\n\nTypeORM uses `{ \"bigNumberStrings\": true }` option by default for node-mysql,\nyou can use a Transformer to fix this issue:\n\n```typescript\nimport { Bigint } from \"typeorm-static\";\n\n@Column(\"bigint\", { transformer: Bigint })\n```\n\n## Options\n\nConstructor receives an object. Following properties may be included:\n\n- `cleanupLimit` For every new session, remove this many expired ones (does not distinguish between users, so User A logging in can delete User B expired sessions). Defaults to 0, in case you need to analyze sessions retrospectively.\n\n- `limitSubquery` Select and delete expired sessions in one query. Defaults to true, you can set false to make two queries, in case you want cleanupLimit but your MariaDB version doesn't support limit in a subquery.\n\n- `ttl` Session time to live (expiration) in seconds. Defaults to session.maxAge (if set), or one day. This may also be set to a function of the form `(store, sess, sessionID) =\u003e number`.\n\n- `onError` Error handler for database exception. It is a function of the form `(store: TypeormStore, error: Error) =\u003e void`. If not set, any database error will cause the TypeormStore to be marked as \"disconnected\", and stop reading/writing to the database, therefore not loading sessions and causing all requests to be considered unauthenticated.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffreshgiammi-lab%2Fconnect-typeorm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffreshgiammi-lab%2Fconnect-typeorm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffreshgiammi-lab%2Fconnect-typeorm/lists"}