@jadejr/connect-session-kysely
v1.0.2
Published
A kysely session store for Express and Connect
Readme
Connect Session Kysely
This is based on connect-session-knex and thus the original code comes from them under the ISC license.
connect-session-kysely is an express-session or fastify store backed by PostgreSQL, MySQL, MariaDB, MSSQL, QLite3, via the kysely library.
Installation
$ npm install connect-session-kyselyUsage
Example application using the defaults
Example application with PostgreSQL
Options
dbTypetype of database to use ('mysql' | 'postgresql' | 'sqlite'). Kysely doesn't tell us what db we use, so we hae to hint which optimized query set we want to usecleanupIntervalmilliseconds between clearing expired sessions. Defaults to 60000. 0 disables the automatic clearing of expired sessions.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"
| 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`));