fastify-session-better-sqlite3-store 1.0.8 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/index.js +7 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|

|
|
6
6
|
[](https://opensource.org/licenses/MIT)
|
|
7
7
|
|
|
8
|
-
[better-sqlite3](https://github.com/WiseLibs/better-sqlite3) session store for [@fastify/session](https://github.com/fastify/session). By default [@fastify/session](https://github.com/fastify/session)
|
|
8
|
+
A [better-sqlite3](https://github.com/WiseLibs/better-sqlite3) session store for [@fastify/session](https://github.com/fastify/session). By default [@fastify/session](https://github.com/fastify/session) uses in-memory storage to store sessions. With this small package you can store sessions on an **SQLite3** database instead.
|
|
9
9
|
|
|
10
10
|
## Installation
|
|
11
11
|
|
package/index.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const NODE_VERSION_REQUIREMENT = 14
|
|
4
|
+
|
|
5
|
+
const nodeVersion = Number(process.version.match(/^v(\d+)/)[1])
|
|
6
|
+
if (nodeVersion < NODE_VERSION_REQUIREMENT) {
|
|
7
|
+
throw new Error(`node '${process.version}' not supported, needs 'v14.x' or greater`)
|
|
8
|
+
}
|
|
9
|
+
|
|
4
10
|
const EventEmitter = require('events')
|
|
5
11
|
|
|
6
12
|
class SqliteStore extends EventEmitter {
|
|
@@ -9,11 +15,6 @@ class SqliteStore extends EventEmitter {
|
|
|
9
15
|
* @param {string} table table name where session data will be stored, defaults to `session`.
|
|
10
16
|
*/
|
|
11
17
|
constructor (sqlite3db, table = 'session') {
|
|
12
|
-
const nodeVersion = Number(process.version.match(/^v(\d+)/)[1])
|
|
13
|
-
if (nodeVersion < NODE_VERSION_REQUIREMENT) {
|
|
14
|
-
throw new Error(`node '${process.version}' not supported, needs 'v14.x' or greater`)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
18
|
try {
|
|
18
19
|
sqlite3db.exec(`
|
|
19
20
|
create table ${table} (
|
|
@@ -27,6 +28,7 @@ class SqliteStore extends EventEmitter {
|
|
|
27
28
|
throw err
|
|
28
29
|
}
|
|
29
30
|
}
|
|
31
|
+
|
|
30
32
|
super()
|
|
31
33
|
this.setSession = sqlite3db.prepare(`INSERT INTO ${table} (sid, expires, session) VALUES (?, ?, ?)`)
|
|
32
34
|
this.getSession = sqlite3db.prepare(`SELECT sid, expires, session FROM ${table} WHERE sid = ?`)
|