Giter Site home page Giter Site logo

webrsb / connect-session-knex Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gx0r/connect-session-knex

0.0 0.0 0.0 677 KB

A knex.js session store for express-session, supporting PostgreSQL, MySQL, MariaDB, Oracle and SQLite.

Home Page: https://www.npmjs.com/package/connect-session-knex

License: ISC License

JavaScript 100.00%

connect-session-knex's Introduction

Connect Session Knex

NPM Version NPM Downloads Node.js Version NPM

connect-session-knex is an express-session store backed by PostgreSQL, MySQL, MariaDB, MSSQL, Oracle or SQLite3, via the knex.js library.

Installation

$ npm install connect-session-knex

History

See Changelog.md

Usage

Example application using the defaults

Example application with PostgreSQL

With Express 3 or Connect

Options

  • tablename='sessions' Tablename to use. Defaults to 'sessions'.
  • sidfieldname='sid' Field name in table to use for storing session ids. Defaults to 'sid'.
  • knex knex instance to use. Defaults to a new knex instance, using sqlite3 with a file named 'connect-session-knex.sqlite'
  • createtable if the table for sessions should be created automatically or not.
  • clearInterval milliseconds between clearing expired sessions. Defaults to 60000.
  • disableDbCleanup disables the automatic clearing of expired sessions. Defaults to false.

If the table does not exist in the schema, this module will attempt to create it unless the 'createtable' option is false.

If a knex instance is not provided, this module will attempt to create a sqlite3 database, with a file named 'connect-session-knex.sqlite', in the working directory of the process.

Schema

PostgreSQL or SQLite

Table Name "sessions"

Column Type Modifiers Storage
sid character varying(255) not null extended
sess json not null extended
expired timestamp with time zone not null plain

Indexes:

    "sessions_pkey" PRIMARY KEY, btree (sid)  
    "sessions_expired_index" btree (expired)

MySQL

Table Name sessions.

Column Type Modifiers
sid VARCHAR(255) NOT NULL, PK
sess JSON NOT NULL
expired DATETIME NOT NULL

Command to manually create table:

CREATE TABLE `sessions` (
  `sid` VARCHAR(255) NOT NULL,
  `sess` JSON NOT NULL,
  `expired` DATETIME NOT NULL,
  PRIMARY KEY (`sid`));

Benchmarks

https://github.com/gx0r/express-session-benchmarks

Testing

Install Postgresql

Instructions for Ubuntu after intalling the db:

sudo -u postgres psql
CREATE DATABASE travis_ci_test OWNER postgres;
GRANT all privileges ON DATABASE travis_ci_test TO postgres;
ALTER USER postgres WITH PASSWORD 'postgres';
\q

Install Mysql

Instructions for Ubuntu after installing the db:

sudo mysql -u root
create user 'travis' identified by 'travis';
ALTER USER 'travis'@'localhost' IDENTIFIED BY 'travis';
create database travis_ci_test;
grant all on travis_ci_test.* to 'travis';
\q
sudo service mysql restart

Make sure both the MySQL and Postgres services are running

npm run test

connect-session-knex's People

Contributors

llambda avatar gx0r avatar rawberg avatar omarryhan avatar twada avatar strawbrary avatar mehmetb avatar tobymurray avatar dependabot[bot] avatar akoskm avatar macil avatar morgul avatar jkantr avatar ryantheallmighty avatar savicoder avatar abcd-ca avatar aurium avatar bdwade100 avatar braincrumbz avatar nbppp2 avatar djmc avatar gabrielalan avatar sn1ff avatar machineghost avatar jonathanscleon avatar fntm avatar theneva avatar mcgordonite avatar micheee avatar mdpauley avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.