1.0.4 • Published 6 years ago

fast-store-knex v1.0.4

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

fast-store-knex

Session knex store for fastify and fastity-session

Greenkeeper badge npm Build Status Coverage Status

Save the session to the database with the knex

Requires

  1. fastify
  2. fastify-cookie
  3. fastity-session
  4. knex

Instalation

npm i fast-store-knex

Usage

const fastify = require("fastify")()

// Connection
var knex = require("knex")({
    client: 'mysql',
    connection: {
        host: '127.0.0.1',
        user: 'root',
        password: '',
        database: 'test'
    }
})

const Store = require("fast-store-knex")

fastify.register(require('fastify-cookie'))
fastify.register(require('fastify-session'), {
    store: new Store(knex),
    cookie: {
        httpOnly: true,
        secure: false,
    },
    secret: 'a secret with minimum length of 32 characters'
})

// Write session
fastify.get('/write', (request, reply) => {
    request.session.text = "Hello world"
    reply.send({
        out: "fast !"
    })
})

// Read session
fastify.get('/read', (request, reply) => {
    reply.send({
        out: "fast !",
        text: request.session.text
    })
})

fastify.listen(3000, err => {
    if (!err) fastify.log.info(`server listening on ${fastify.server.address().port}`)
});

License

MIT

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago