Skip to content

Instantly share code, notes, and snippets.

@porsager
Created February 2, 2018 14:05
Show Gist options
  • Select an option

  • Save porsager/76ff609761653e66877300c1991efd46 to your computer and use it in GitHub Desktop.

Select an option

Save porsager/76ff609761653e66877300c1991efd46 to your computer and use it in GitHub Desktop.
custom postgress express-session store
const store = Object.assign(new session.Store(), {
get: (id, cb) =>
pg.oneOrNone(`
select
cookie, user_id as user
from sessions
where session_id = $[id]
`, { id }).then(s => cb(null, s)).catch(cb)
,
set: (id, session, cb) =>
pg.none(`
insert into sessions(
session_id, user_id, cookie, user_agent, ip
) values (
$[id], $[user], $[cookie], $[userAgent], $[ip]
)
`, { id, ...session }).then(s => cb(null, s)).catch(cb)
,
touch: (id, session, cb) => cb()
,
destroy: (id, cb) =>
pg.none(`
delete from sessions
where session_id = $[id]
`, { id }).then(cb).catch(cb)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment