@angablue/typeorm-store
TypeScript icon, indicating that this package has built-in type declarations

3.0.3 • Public • Published

typeorm-store

A TypeORM-based store for express-session.

Installation

$ pnpm install typeorm-store

Usage

First, make a new Session entity. Make sure to synchronize the entity to the database. typeorm-store will not to this for you.

import { BaseEntity, Column, Entity, PrimaryColumn } from 'typeorm';
import { SessionEntity } from 'typeorm-store';

@Entity()
export class Session extends BaseEntity implements SessionEntity {
    @PrimaryColumn()
    id: string;

    @Column()
    expiresAt: number;

    @Column()
    data: string;
}

Use TypeormStore as store in express-session, specifying the repository of the new Session entity.

import * as express from 'express';
import * as session from 'express-session';
import { getConnection } from 'typeorm';
import { TypeormStore } from 'typeorm-store';
import { Session } from './entities/session';

const app = express();

// Make sure the connection is ready before doing this
const repository = getConnection().getRepository(Session);

app.use(session({
   secret: 'secret',
   resave: false,
   saveUninitialized: false,
   store: new TypeormStore({ repository })
}))

API

new TypeormStore(options)

Options

  • repository (required) - The repository of the session entity.
  • ttl (optional) - The time to live for the session in milliseconds. Defaults to 86400000 (1 day).

Readme

Keywords

none

Package Sidebar

Install

npm i @angablue/typeorm-store

Weekly Downloads

1

Version

3.0.3

License

MIT

Unpacked Size

19.4 kB

Total Files

9

Last publish

Collaborators

  • angablue