-
Notifications
You must be signed in to change notification settings - Fork 1
/
basic_sqlite.js
55 lines (48 loc) · 1.06 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
const session = require('koa-generic-session');
const Knex = require('knex');
const KnexStore = require('..');
const koa = require('koa');
// set up Knex in the usual manner, or, for a quick example:
const knex = Knex({
client: 'sqlite3',
connection: {
filename: "./example.db"
}
});
const app = koa();
app.keys = ['keys', 'keykeys'];
app.use(session({
store: new KnexStore(
knex, // pass your knex object as the first arg
{} // pass any config options for KnexStore 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);