当前位置: 首页 > 软件库 > Web应用开发 > >

node-connect-pg-simple

授权协议 MIT License
开发语言 JavaScript
所属分类 Web应用开发
软件类型 开源软件
地区 不详
投 递 者 屠泰平
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

Connect PG Simple

A simple, minimal PostgreSQL session store for Express/Connect

Build StatusFOSSA Status

Installation

npm install connect-pg-simple

Once npm installed the module, you need to create the "session" table in your database.

For that you can use the table.sql file provided with the module:

psql mydatabase < node_modules/connect-pg-simple/table.sql

Or simply play the file via a GUI, like the pgAdminIII queries tool.

Or instruct this module to create it itself, by setting the createTableIfMissing option.

Note that connect-pg-simple requires PostgreSQL version 9.5 or above.

Usage

Examples are based on Express 4.

Simple example:

const session = require('express-session');

app.use(session({
  store: new (require('connect-pg-simple')(session))({
    // Insert connect-pg-simple options here
  }),
  secret: process.env.FOO_COOKIE_SECRET,
  resave: false,
  cookie: { maxAge: 30 * 24 * 60 * 60 * 1000 } // 30 days
  // Insert express-session options here
}));

Advanced example showing some custom options:

const pg = require('pg');
const expressSession = require('express-session');
const pgSession = require('connect-pg-simple')(expressSession);

const pgPool = new pg.Pool({
    // Insert pool options here
});

app.use(expressSession({
  store: new pgSession({
    pool : pgPool,                // Connection pool
    tableName : 'user_sessions'   // Use another table-name than the default "session" one
    // Insert connect-pg-simple options here
  }),
  secret: process.env.FOO_COOKIE_SECRET,
  resave: false,
  cookie: { maxAge: 30 * 24 * 60 * 60 * 1000 } // 30 days
  // Insert express-session options here
}));

Advanced options

Connection options

Listed in the order they will be picked up. If multiple are defined, then the first in the lists that is defined will be used, the rest ignored.

  • pool - The recommended one – Connection pool object (compatible with pg.Pool) for the underlying database module.
  • pgPromise - Database object from pg-promise to be used for DB communications.
  • conObject - If you don't specify a pool object, use this option or conString to specify a PostgreSQL Pool connection object and this module will create a new pool for you.
  • conString - If you don't specify a pool object, use this option or conObject to specify a PostgreSQL connection string and this module will create a new pool for you. If the connection string is in the DATABASE_URL environment variable (as you do by default on eg. Heroku) – then this module fallback to that if this option is not specified.

Other options

  • ttl - the time to live for the session in the database – specified in seconds. Defaults to the cookie maxAge if the cookie has a maxAge defined and otherwise defaults to one day.
  • createTableIfMissing - if set to true then creates the table in the case where the table does not already exist. Defaults to false.
  • disableTouch – boolean value that if set to true disables the updating of TTL in the database when using touch. Defaults to false.
  • schemaName - if your session table is in another Postgres schema than the default (it normally isn't), then you can specify that here.
  • tableName - if your session table is named something else than session, then you can specify that here.
  • pruneSessionInterval - sets the delay in seconds at which expired sessions are pruned from the database. Default is 60 seconds. If set to false no automatic pruning will happen. By default every delay is randomized between 50% and 150% of set value, resulting in an average delay equal to the set value, but spread out to even the load on the database. Automatic pruning will happen pruneSessionInterval seconds after the last pruning (includes manual prunes).
  • pruneSessionRandomizedInterval – if set to false, then the exact value of pruneSessionInterval will be used in all delays. No randomization will happen. If multiple instances all start at once, disabling randomization can mean that multiple instances are all triggering pruning at once, causing unnecessary load on the database. Can also be set to a method, taking a numeric delay parameter and returning a modified one, thus allowing a custom delay algorithm if wanted.
  • errorLog – the method used to log errors in those cases where an error can't be returned to a callback. Defaults to console.error(), but can be useful to override if one eg. uses Bunyan for logging.

Useful methods

  • close() – if this module used its own database module to connect to Postgres, then this will shut that connection down to allow a graceful shutdown. Returns a Promise that will resolve when the database has shut down.
  • pruneSessions([callback(err)]) – will prune old sessions. Only really needed to be called if pruneSessionInterval has been set to false – which can be useful if one wants improved control of the pruning.

License

FOSSA Status

For enterprise

Available as part of the Tidelift Subscription.

The maintainers of connect-pg-simple and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source packages you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact packages you use. Learn more.

  • 使用pg连接PostgreSQL数据库 服务器安装PostgreSQL(以Ubuntu系统为例,已安装docker的情况下) # 拉取postgres镜像 docker pull postgres # 查看已安装镜像 docker images # 运行镜像 POSTGRES_PASSWORD=[自定义数据库密码] POSTGRES_USER=[自定义数据库用户名] docker run

  • nodejs连接pg数据库有两种方式,一种是直接连接、操作、断开 还有一种是使用连接池,这种方式可以有效提升多并发的效率 下边是使用两种不同方式的测试代码:   var pgOpt = require('pg'); /* * 使用连接池 * */ function connectPgWithPool() { var pgConfig = { user: 'postgre

  • PostgreSql是一个面向对象的关系数据库,postgis是一个基于PostgreSql的空间数据库插件,主要用于管理地理空间数据。因此在GIS领域,广泛使用PostgreSql作为空间数据库。 在Node.js中有专门的模块可以用来连接PostgreSql数据库,首先从npm资源库中获取数据库模块,名为”pg”: npm install pg 该模块连接数据库有两种方式: 1 使用连接池 v

  • 技术栈:express-generator + sequelize + apidoc 一、创建应用骨架: express官网 1. 创建文件夹,名称为:express 2. cd到express文件夹,运行Express应用程序生成器 npx express-generator 3. 安装依赖包 npm install 4. 启动应用 set DEBUG=express:* & npm sta

  • 入门示例 安装:npm install connect 编辑:connect_test.js const app = require('connect')(); app.use((req, res, next) => { res.end('Hello World'); }); app.listen('3000'); 启动:node connect_test.js 访问:http://loc

  • 用户评论: [#1] Anonymous [2015-04-24 06:41:02] If you get the following warning : "Warning: pg_connect(): Unable to connect to PostgreSQL server: could not translate host name "server.your.trying.to.conne

  • 后端 var connect = require('connect'); var bodyParser = require('body-parser'); //body解析 var cors = require('cors'); const url = require('url'); const qs = require('qs'); const path = require('path'); c

  • 主要记录express的基本使用,系统学习可以去官网 express中文网 初探express 什么是express express是基于node的一个服务器框架,它是对http模块的封装,简化了node服务器的创建。 目前已经有不错的生态,但他的作者又制作了koa2,我觉得这个东西估计用不久,简单看看就好了。 基本使用 按照下面的指令来安装express框架 npm i express 可以按

  • 花了3+个小时解决的问题,记录一下。 我在 Ubuntu 18.04 上安装 npm install pg 时,出现错误: ...... gyp ERR! configure error gyp ERR! stack Error: `gyp` failed with exit code: 1 gyp ERR! stack at ChildProcess.onCpExit (/usr/sh

  • 核心参考网站:https://node-postgres.com/ 1.pgsql-pool.js const Pool = require('pg-pool'); const config = { user: 'postgres', password: 'XXXX', host: '121.5.xx.xx', port: 5432, database:

  • 踩了个巨坑 今天在github上clone了一个项目,使用npm i 安装依赖时出问题了。 node-pre-gyp 报错。 bcrypt 也报错 搜索得知该插件需要 python环境 需要c++编译环境,我后面下载的2019版本的。勾选了c++桌面开发选项。 而且bcrypt 和 node的版本要对应起来,由于我的node是14以上版本的,所以bcrypt需要3以上版本。在项目中的package

 相关资料
  • PG

    Concepts Peering Interval See PG::start_peering_interval. See PG::acting_up_affected See PG::RecoveryState::Reset A peering interval is a maximal set of contiguous map epochs in which the up and actin

  • pg

    pg 是一个用于golang database/sql 的 PostgreSQL 驱动。 安装 go get github.com/blusewang/pg 使用 db, err := sql.Open("pg", "pg://user:password@dbhost.yourdomain.com/database_name?application_name=app_name&sslmode=v

  • 问题内容: 可以这样插入一行: 这种方法会自动注释掉任何特殊字符。 如何一次插入多行? 我需要实现这一点: 我可以只使用js字符串运算符手动编译此类行,但是随后我需要以某种方式添加特殊字符转义符。 问题答案: 下面这篇文章:性能提升,从PG-承诺库,其建议的方法: 完全按照您的情况使用的示例: 它也将与一系列对象一起工作: 更新1 有关通过单个查询的高性能方法,请参见使用pg-promise进行多

  • See OSD::_remove_pg, OSD::RemoveWQ There are two ways for a pg to be removed from an OSD: MOSDPGRemove from the primary OSD::advance_map finds that the pool has been removed In either case, our genera

  • pg¶ ↑ home github.com/ged/ruby-pg docs deveiate.org/code/pg clog github.com/ged/ruby-pg/blob/master/History.rdoc Description¶ ↑ Pg is the Ruby interface to the PostgreSQL RDBMS. It works with PostgreS

  • crystal-pg A native, non-blocking Postgres driver for Crystal usage This driver now uses the crystal-db project. Documentation on connecting,querying, etc, can be found at: https://crystal-lang.org/do