drizzle-orm icon indicating copy to clipboard operation
drizzle-orm copied to clipboard

[FEATURE]: Drizzle Session Store for `express-session`

Open danulqua opened this issue 2 years ago • 2 comments

Describe what you want

Suggestion to implement a Drizzle Store for express-session.
Basically, it should persist sessions on one of the tables defined using Drizzle.

Here is an example of Prisma Store.

danulqua avatar Jul 31 '23 10:07 danulqua

any movement on this at all? All other major ORMs have this.

fltzr avatar Jan 15 '24 03:01 fltzr

has anyone found an alternative?

arndom avatar May 09 '24 14:05 arndom

This isn't something that Drizzle will provide first-party support for, since we don't provide tools for specific frameworks and its meant to be framework-agnostic. The Prisma store mentioned is a third-party package for Prisma; similarly, someone else can make a a third-party package supporting this use case.

L-Mario564 avatar Sep 11 '24 16:09 L-Mario564

@L-Mario564 holds a valid point.

For anyone working with a pg database you can just as easily use pgSession. In my case:

session.ts

import session from "express-session";
import pgSession from "connect-pg-simple"

import { pool } from "../db";

const pgStore = pgSession(session);

app.use(
  session({
    store: new pgStore({ pool, createTableIfMissing: true }),
    // other options
  })
);

db.ts

import { Pool } from "pg";
import { drizzle } from "drizzle-orm/node-postgres";
import schema from "./schema";

export const pool = new Pool({
  host: process.env.DB_HOST,
  port: Number(process.env.DB_PORT),
  user: process.env.DB_USER,
  password: process.env.DB_PASSWORD,
  database: process.env.DB_NAME,
});

export const connect = async () => pool.connect();

const db = drizzle(pool, { schema });

export default db;

arndom avatar Sep 13 '24 07:09 arndom