Socket
Socket
Sign inDemoInstall

connect-session-knex

Package Overview
Dependencies
Maintainers
2
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

connect-session-knex

A knex.js session store for Express and Connect


Version published
Weekly downloads
70K
decreased by-12.28%
Maintainers
2
Weekly downloads
 
Created
Source

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

Options

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

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"
ColumnTypeModifiersStorage
sidcharacter varying(255)not nullextended
sessjsonnot nullextended
expiredtimestamp with time zonenot nullplain

Indexes:

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

MySQL

Table Name sessions.

ColumnTypeModifiers
sidVARCHAR(255)NOT NULL, PK
sessJSONNOT NULL
expiredDATETIMENOT 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`));

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

FAQs

Package last updated on 10 Jun 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc