RethinkDB database adapter for express-session
middleware for ExpressJS.
Thank you to everyone writing express-session
drivers out there for the boilerplate and inspiration.
Note: Sessions are not vacuumed by the adapter like some of the others out there (setInterval
and friends). Pull requests welcome :)
npm install express-session-rethinkdb-esm --save
client
: Required -- RethinkDB import.
conn
: Required -- RethinkDB database connection.
table
: RethinkDB table to store sessions in (default: sessions
).
ttl
: Time in milliseconds to expire sessions (default: two weeks).
// rethinkdb
import r from 'rethinkdb'
const rc = await r.connect({ host })
// express
import express from 'express'
import session from 'express-session'
import _init_rdb_express_session_store from 'express-session-rethinkdb-esm'
const app = express()
const RethinkdbSessionStore = await _init_rdb_express_session_store({ session })
app.use( session({
store: new RethinkdbSessionStore({ client: r, conn: rc })
})
Using the ready
property to wait for store initialization. Store will ensure the table
table is created and has a secondary index for expires
if not already.
// Thennable
rethinkdbSessionStoreInstance.ready.then( async () => {
await rethinkdbSessionStoreInstance.vacuum()
})
// Async/Await
await rethinkdbSessionStoreInstance.ready
await rethinkdbSessionStoreInstance.vacuum()