A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.npmjs.com/package/connect-typeorm below:

connect-typeorm - npm

connect-typeorm

A TypeORM-based session store.

Setup & Usage

Configure TypeORM with back end of your choice:

NPM
npm install connect-typeorm express-session typeorm sqlite3
npm install -D @types/express-session 
Implement the Session entity:
// src/domain/Session/Session.ts

import { ISession } from "connect-typeorm";
import { Column, DeleteDateColumn, Entity, Index, PrimaryColumn } from "typeorm";

@Entity()
export class Session implements ISession {
    @Index()
    @Column("bigint")
    public expiredAt = Date.now();

    @PrimaryColumn("varchar", { length: 255 })
    public id = "";

    @Column("text")
    public json = "";

    @DeleteDateColumn()
    public destroyedAt?: Date;
}

Pass repository to TypeormStore:

// src/app/Api/Api.ts

import { TypeormStore } from "connect-typeorm";
import { getRepository } from "typeorm";
import * as Express from "express";
import * as ExpressSession from "express-session";

import { Session } from "../../domain/Session/Session";

export class Api {
    public sessionRepository = getRepository(Session);

    public express = Express().use(
        ExpressSession({
            resave: false,
            saveUninitialized: false,
            store: new TypeormStore({
                cleanupLimit: 2,
                limitSubquery: false, // If using MariaDB.
                ttl: 86400
            }).connect(this.sessionRepository),
            secret: "keyboard cat"
        })
    );
}

TypeORM uses { "bigNumberStrings": true } option by default for node-mysql, you can use a Transformer to fix this issue:

import { Bigint } from "typeorm-static";

@Column("bigint", { transformer: Bigint })
Options

Constructor receives an object. Following properties may be included:

License

MIT


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4