-
Notifications
You must be signed in to change notification settings - Fork 2
/
basic_sqlite.js
57 lines (50 loc) · 1.17 KB
/
basic_sqlite.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const session = require('koa-generic-session');
const Sequelize = require('sequelize');
const SequelizeStore = require('..');
const koa = require('koa');
// set up Sequelize in the usual manner, or, for a quick example:
const sequelize = new Sequelize({
logging: false,
dialect: 'sqlite',
storage: __dirname + '/example.db',
operatorsAliases: false // remove if using Sequelize v5
});
const app = koa();
app.keys = ['keys', 'keykeys'];
app.use(
session({
store: new SequelizeStore(
sequelize, // pass your sequelize object as the first arg
{} // pass any config options for SequelizeStore as the second arg
)
})
);
function get() {
const session = this.session;
session.count = session.count || 0;
session.count++;
this.body = session.count;
}
function remove() {
this.session = null;
this.body = 0;
}
function* regenerate() {
get.call(this);
yield this.regenerateSession();
get.call(this);
}
app.use(function*() {
switch (this.path) {
case '/get':
get.call(this);
break;
case '/remove':
remove.call(this);
break;
case '/regenerate':
yield regenerate.call(this);
break;
}
});
app.listen(8080);