I am trying to get express sessions to work with postgres. After several hours of debugging, I fixed all the problems except one. Everything works, but the following:
If I run this request inside pgAdmin, my sessions are working correctly
CREATE TABLE "sessions" ( "sid" varchar NOT NULL COLLATE "default", "sess" json NOT NULL, "expire" timestamp(6) NOT NULL ) WITH (OIDS=FALSE); ALTER TABLE "sessions" ADD CONSTRAINT "session_pkey" PRIMARY KEY ("sid") NOT DEFERRABLE INITIALLY IMMEDIATE;
If I create a model with sequelize, it does not save sessions. I am sure, and it is obvious that I am missing some parts of the model definition and would appreciate any data.
var Sessions = database.define('sessions', { sid: { type: Sequelize.STRING, primaryKey: true }, expire: { type: Sequelize.DATE, allowNull: true }, sess: Sequelize.JSON }); return Sessions;
Rest of the code working with this
var pgSession = require('connect-pg-simple')(expressSession), sessionSettings = { store: new pgSession ({ conString: 'postgres://' + dbConfig.user +':' + dbConfig.password+ '@' + dbConfig.host+ ':5432/' + dbConfig.database, tableName : 'sessions' }), secret: 'whatevergoeshere', resave: false, saveUninitialized: false, cookie: { maxAge: 7*24*60*60*1000 } }; app.use(expressSession(sessionSettings));
I have no idea how to include the missing parts and document the documentation, either briefly on the topic, or I did not have enough sleep
The rest of the code is available upon request, but pretty sure that it does not affect anything, because if I do not force synchronization with the sequelize model and use the request, everything will work.
In addition, here is how he looks at pgAdmin, the upper one is created with a request in pgAdmin, the lower one using sequelize
