Created
February 2, 2018 14:05
-
-
Save porsager/76ff609761653e66877300c1991efd46 to your computer and use it in GitHub Desktop.
custom postgress express-session store
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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