Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: gx0r/connect-session-knex
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: nocodb/connect-session-knex
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.

Commits on Jul 10, 2014

  1. Initial knex port

    llambda committed Jul 10, 2014
    Copy the full SHA
    5d16f17 View commit details
  2. ready checks

    llambda committed Jul 10, 2014
    Copy the full SHA
    110a092 View commit details
  3. Fix code and tests

    llambda committed Jul 10, 2014
    Copy the full SHA
    0c593e5 View commit details
  4. Fixup project

    llambda committed Jul 10, 2014
    Copy the full SHA
    52d1083 View commit details
  5. fix dev deps

    llambda committed Jul 10, 2014
    Copy the full SHA
    a43d677 View commit details
  6. Update Readme.md

    llambda committed Jul 10, 2014
    Copy the full SHA
    c861400 View commit details
  7. Update Readme.md

    llambda committed Jul 10, 2014
    Copy the full SHA
    415d3a8 View commit details
  8. Update Readme.md

    llambda committed Jul 10, 2014
    Copy the full SHA
    137e37d View commit details

Commits on Jul 11, 2014

  1. Update Readme.md

    llambda committed Jul 11, 2014
    Copy the full SHA
    55de72d View commit details
  2. Update Readme.md

    llambda committed Jul 11, 2014
    Copy the full SHA
    8e0a956 View commit details

Commits on Jul 12, 2014

  1. Add benchmarks

    llambda committed Jul 12, 2014
    Copy the full SHA
    40d01f2 View commit details
  2. Fix date data format bug

    llambda committed Jul 12, 2014
    Copy the full SHA
    8a00aa7 View commit details
  3. Update Readme.md

    llambda committed Jul 12, 2014
    Copy the full SHA
    485fead View commit details
  4. Update Readme.md

    llambda committed Jul 12, 2014
    Copy the full SHA
    3e9fe91 View commit details
  5. Update Readme.md

    llambda committed Jul 12, 2014
    Copy the full SHA
    ace9a80 View commit details
  6. Update Readme.md

    llambda committed Jul 12, 2014
    Copy the full SHA
    7845893 View commit details
  7. Update Readme.md

    llambda committed Jul 12, 2014
    Copy the full SHA
    47d6ccf View commit details
  8. Update Readme.md

    llambda committed Jul 12, 2014
    Copy the full SHA
    8499159 View commit details
  9. Update Readme.md

    llambda committed Jul 12, 2014
    Copy the full SHA
    ebdf541 View commit details
  10. Update Readme.md

    llambda committed Jul 12, 2014
    Copy the full SHA
    dacf4d9 View commit details
  11. Add cookie expires date

    llambda committed Jul 12, 2014
    Copy the full SHA
    3e66381 View commit details
  12. Add deps for mocha tests

    llambda committed Jul 12, 2014
    Copy the full SHA
    3de01b3 View commit details
  13. Copy the full SHA
    e139912 View commit details
  14. Add benchmark for connect-sqlite3

    llambda committed Jul 12, 2014
    Copy the full SHA
    542d179 View commit details
  15. Update Readme.md

    llambda committed Jul 12, 2014
    Copy the full SHA
    bbebdc0 View commit details

Commits on Aug 5, 2014

  1. Bump version

    llambda committed Aug 5, 2014
    Copy the full SHA
    bf21a36 View commit details

Commits on Sep 16, 2014

  1. Update Readme.md

    llambda committed Sep 16, 2014
    Copy the full SHA
    75e7e2a View commit details
  2. Update Readme.md

    llambda committed Sep 16, 2014
    Copy the full SHA
    b9a26b4 View commit details
  3. Update Readme.md

    llambda committed Sep 16, 2014
    Copy the full SHA
    7a9534a View commit details
  4. Update Readme.md

    llambda committed Sep 16, 2014
    Copy the full SHA
    779595f View commit details
  5. Update Readme.md

    llambda committed Sep 16, 2014
    Copy the full SHA
    05fcc3f View commit details

Commits on Sep 17, 2014

  1. Update History.md

    llambda committed Sep 17, 2014
    Copy the full SHA
    ea46616 View commit details
  2. Update Readme.md

    llambda committed Sep 17, 2014
    Copy the full SHA
    2273db7 View commit details
  3. v1.0.0

    llambda committed Sep 17, 2014
    Copy the full SHA
    e389569 View commit details
  4. Update Readme.md

    llambda committed Sep 17, 2014
    Copy the full SHA
    3d8b180 View commit details
  5. Add mariadb benchmark

    llambda committed Sep 17, 2014
    Copy the full SHA
    1348ea0 View commit details

Commits on Sep 25, 2014

  1. Bump version

    llambda committed Sep 25, 2014
    Copy the full SHA
    2db43b5 View commit details

Commits on Oct 8, 2014

  1. Add benchmark for connect-sqlite3

    llambda authored and Chris Hall committed Oct 8, 2014
    Copy the full SHA
    9b47094 View commit details
  2. Make expire condition more standards compliant

    I could only test this easily with PostgreSQL, but I'm using only SQL
    standard functions and types.  As far as I know, this should work with
    any RDBMS that implements the SQL standard.  That said, further testing
    would be well warranted.
    Chris Hall committed Oct 8, 2014
    Copy the full SHA
    14a8ebb View commit details
  3. Added support for native JSON type

    Using the JSON format for PostgreSQL caused get to explode since the
    return was already an Object.  A check was added for when the returned
    sess is a string.
    Chris Hall committed Oct 8, 2014
    Copy the full SHA
    80324f1 View commit details
  4. Added better exception handling

    Chris Hall committed Oct 8, 2014
    Copy the full SHA
    a5c3be0 View commit details
  5. Added ISO compliant date strings

    Seems to have fixed remaining PostgreSQL issues
    Chris Hall committed Oct 8, 2014
    Copy the full SHA
    6a6ec06 View commit details
  6. General cleanup

    Added some missing semicolons to get JSHint to shut up
    Chris Hall committed Oct 8, 2014
    Copy the full SHA
    73755ae View commit details

Commits on Nov 20, 2014

  1. Merge pull request #1 from chall8908/fix_expire_bug

    Fix expire bug
    llambda committed Nov 20, 2014
    Copy the full SHA
    749c967 View commit details
  2. Bump version

    llambda committed Nov 20, 2014
    Copy the full SHA
    f7f0f0b View commit details
  3. Update readme

    llambda committed Nov 20, 2014
    Copy the full SHA
    0e82491 View commit details
  4. Remove string

    llambda committed Nov 20, 2014
    Copy the full SHA
    2edeec3 View commit details
  5. Add sqlite3 bench

    llambda committed Nov 20, 2014
    Copy the full SHA
    3404683 View commit details

Commits on Dec 6, 2014

  1. Remove benchmarks; moved to their own repo.

    llambda committed Dec 6, 2014
    Copy the full SHA
    0b6ab31 View commit details
  2. Reindent

    llambda committed Dec 6, 2014
    Copy the full SHA
    f96a4dd View commit details
Showing with 5,457 additions and 5,044 deletions.
  1. +5 −0 .editorconfig
  2. +1 −0 .eslintignore
  3. +10 −0 .eslintrc.js
  4. +2 −0 .gitignore
  5. +17 −0 .travis.yml
  6. +27 −0 Changelog.md
  7. +0 −17 History.md
  8. +15 −0 LICENSE
  9. +33 −0 Oldversions.md
  10. +132 −38 Readme.md
  11. +45 −0 examples/example-postgres.js
  12. +41 −0 examples/example.js
  13. +0 −181 lib/connect-sqlite3.js
  14. +333 −0 lib/index.js
  15. +244 −0 lib/utils.js
  16. +4,279 −0 package-lock.json
  17. +35 −19 package.json
  18. +0 −182 test/mocha.css
  19. +0 −4,504 test/mocha.js
  20. +0 −87 test/test.js
  21. +0 −16 test/tests.html
  22. +220 −0 tests/index.js
  23. +18 −0 typings/index.d.ts
5 changes: 5 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[*]
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/**/*.d.ts
10 changes: 10 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
env: {
commonjs: true,
es6: true,
node: true,
},
extends: [
'airbnb-base',
],
};
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -11,3 +11,5 @@
# npm modules
node_modules

*.sqlite
npm-debug.log
17 changes: 17 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
language: node_js
node_js:
- "10"
- "12"

env:
- IN_TRAVIS=yes

before_script:
- psql -c 'create database travis_ci_test;' -U postgres
- mysql -e 'create database travis_ci_test;'

addons:
postgresql: "9.4"

services:
- mysql
27 changes: 27 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Change Log

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

**1.7.2**

- Bug fix: fixed a typo. 'creatable' -> 'createtable'

**1.7.1**

- Bug fix: https://github.com/llambda/connect-session-knex/pull/65
- Split the lib into 1. lib 2. tests 3. examples 4. typings to make it more maintainable
- Added Changelog.md

**1.7.0**

- Added Typescript lib interface (index.d.ts)
- Added Airbnb Eslint configs and recommendations.
- Auto fixed many lint errors
- Removed NodeJS v8 testing from Travis
- Added instructions for testing
- Tests now require a password when running locally (While still the same when running on Travis) I did that because both dbs refused to connect locally without a password
- Auto lint both examples
- Moved many functions out of the lib's main closure, to make the code more clear and enforce the purity of these functions. Only the Store class is what remains in the closure (Because it requires the session object)
- Added knex to main dependencies instead of dev dependencies.
17 changes: 0 additions & 17 deletions History.md

This file was deleted.

15 changes: 15 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Copyright (c) 2014, llambda <xxgsoftware@gmail.com>

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.


33 changes: 33 additions & 0 deletions Oldversions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
### Usage

With Express 3:

```js
var express = require('express')
var KnexSessionStore = require('connect-session-knex')(express);
var store = new KnexSessionStore(/* options here */);

app.configure(function() {
app.use(express.session({
store: store,
secret: 'your secret',
cookie: { maxAge: 7 * 24 * 60 * 60 * 1000 } // 1 week
}));
});
```

With Connect:

```js
var connect = require('connect'),
var KnexSessionStore = require('connect-session-knex')(connect);
var store = new KnexSessionStore(/* options here */);

connect.createServer(
connect.cookieParser(),
connect.session({
store: store,
secret: 'your secret'
})
);
```
170 changes: 132 additions & 38 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,49 +1,143 @@
# Connect SQLite3
# Connect Session Knex

connect-sqlite3 is a SQLite3 session store modeled after the TJ's connect-redis store.

[![NPM Version][npm-version-image]][npm-url]
[![NPM Downloads][npm-downloads-image]][npm-url]
[![Node.js Version][node-image]][node-url]
[![Build Status][travis-image]][travis-url]
[![Dependency Status][dependencies-image]][dependencies-url]
[![Coverage Status][coveralls-image]][coveralls-url]

[![NPM][npm-image]][npm-url]

connect-session-knex is an [express-session](https://github.com/expressjs/session) store backed by PostgreSQL, MySQL, MariaDB, MSSQL, Oracle or SQLite3, via the [knex.js](http://knexjs.org/) library.

## Installation

$ npm install connect-sqlite3
```sh
$ npm install connect-session-knex
```

## Options
## History

- `table='sessions'` Database table name
- `db='sessionsDB'` Database file name (defaults to table name)
- `dir='.'` Direcotry to save '<db>.db' file
See [Changelog.md](Changelog.md)

## Usage

var connect = require('connect'),
SQLiteStore = require('connect-sqlite3')(connect);

connect.createServer(
connect.cookieParser(),
connect.session({ store: new SQLiteStore, secret: 'your secret' })
);

with express

3.x:
var SQLiteStore = require('connect-sqlite3')(express);

4.x:
var session = require('express-session');
var SQLiteStore = require('connect-sqlite3')(session);

app.configure(function() {
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser());
app.use(express.session({
store: new SQLiteStore,
secret: 'your secret',
cookie: { maxAge: 7 * 24 * 60 * 60 * 1000 } // 1 week
}));
app.use(app.router);
app.use(express.static(__dirname + '/public'));
});
[Example application using the defaults](https://github.com/llambda/connect-session-knex/blob/master/examples/example.js)

[Example application with PostgreSQL](https://github.com/llambda/connect-session-knex/blob/master/examples/example-postgres.js)

[With Express 3 or Connect](https://github.com/llambda/connect-session-knex/blob/master/Oldversions.md)

## 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.

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)
```

## Benchmarks

[https://github.com/llambda/express-session-benchmarks](https://github.com/llambda/express-session-benchmarks)

[npm-version-image]: https://img.shields.io/npm/v/connect-session-knex.svg
[npm-downloads-image]: https://img.shields.io/npm/dm/connect-session-knex.svg
[npm-image]: https://nodei.co/npm/connect-session-knex.png?downloads=true&downloadRank=true&stars=true
[npm-url]: https://npmjs.org/package/connect-session-knex
[travis-image]: https://img.shields.io/travis/llambda/connect-session-knex/master.svg
[travis-url]: https://travis-ci.org/llambda/connect-session-knex
[dependencies-image]: https://david-dm.org/llambda/connect-session-knex.svg?style=flat
[dependencies-url]: https://david-dm.org/llambda/connect-session-knex
[coveralls-image]: https://img.shields.io/coveralls/llambda/connect-session-knex/master.svg
[coveralls-url]: https://coveralls.io/r/llambda/connect-session-knex?branch=master
[node-image]: https://img.shields.io/node/v/connect-session-knex.svg
[node-url]: http://nodejs.org/download/
[gitter-join-chat-image]: https://badges.gitter.im/Join%20Chat.svg
[gitter-channel-url]: https://gitter.im/llambda/connect-session-knex
[express-session-url]: https://github.com/expressjs/session
[io-url]: https://iojs.org

## Testing

Install Postgresql
Instructions for Ubuntu after intalling the db:

```bash
sudo -u postgres psql
```

```sql
CREATE DATABASE travis_ci_test OWNER postgres;
```

```sql
GRANT all privileges ON DATABASE travis_ci_test TO postgres;
```

```sql
ALTER USER postgres WITH PASSWORD 'postgres';
```

```sql
\q
```

Install Mysql
Instructions for Ubuntu after installing the db:

```bash
sudo mysql -u root
```

```sql
create user 'travis' identified by 'travis';
```

```sql
ALTER USER 'travis'@'localhost' IDENTIFIED BY 'travis';
```

```sql
create database travis_ci_test;
```

```sql
grant all on travis_ci_test.* to 'travis';
```

```sql
\q
```

```bash
sudo service mysql restart
```

Make sure both the MySQL and Postgres services are running

```bash
npm run test
```
45 changes: 45 additions & 0 deletions examples/example-postgres.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* eslint-disable import/no-unresolved */
/* eslint-disable import/no-extraneous-dependencies */
/* eslint-disable no-console */

const express = require('express');

const app = express();

const session = require('express-session');
const KnexSessionStore = require('connect-session-knex')(session);

const Knex = require('knex');

const knex = Knex({
client: 'pg',
connection: {
host: '127.0.0.1',
user: 'postgres',
password: '',
database: 'travis_ci_test',
},
});

const store = new KnexSessionStore({
knex,
tablename: 'sessions', // optional. Defaults to 'sessions'
});

app.use(
session({
secret: 'keyboard cat',
cookie: {
maxAge: 10000, // ten seconds, for testing
},
store,
}),
);

app.use('/', (req, res) => {
const n = req.session.views || 0;
req.session.views = n + 1;
res.end(`${n} views`);
});

app.listen(3000);
Loading