javascript - pg-promise TypeError:无效的“选项”参数
问题描述
我正在尝试将我的文件从使用pg
包更改为pg-promise
包。我使用的初始解决方案一切正常pg
。但是,切换到pg-promise
并使用文档时,我在设置过程中遇到了奇怪的错误。
最新错误:
throw new TypeError('Invalid "options" parameter: ' + JSON.stringify(options));
^
TypeError: Invalid "options" parameter: "postgres://me:complete@localhost:5432/education_be"
我的配置文件:
require('dotenv').config();
const pgp = require('pg-promise');
// === My initial setup just using 'pg'
// const { Pool } = require('pg');
// const pool = new Pool({
// name: process.env.name,
// password: process.env.password,
// host: process.env.host,
// database: 'education_be',
// port: process.env.port
// });
// === My first attempt following the guide would receive errors like:
// === Error: Option "user" is not recognized.
const connection = {
name: 'me',
password: 'password',
host: 'localhost',
database: 'education_be',
port: 5432
};
// === attempting (unsuccessfully) to just use the address
const db = pgp('postgres://me:complete@localhost:5432/education_be');
module.exports = db;
解决方案
我迟到了,但希望这可以帮助遇到同样问题的其他人。尽管您没有选项,但您必须在 pg-promise require 语句中包含括号。
const pgp = require('pg-promise')();
推荐阅读
- swift - Facebook-IOS-SDK pod 安装问题
- javascript - 如何合并对象数组中的深层值
- python - 使用 geopandas 从 pyplot 中检索数据
- sql - SQL 联合的替代方案
- javascript - 是否可以检查 Parse 用户是否从服务器端登录?
- laravel - 如何在 laravel 5.8 中使用社交名流与不同类型的用户登录谷歌
- abap - 当结构包含字符串字段时,将结构转换为字符串失败
- javascript - 包含 flag-icon-css 的 Web 包设置
- android - 作为设备所有者授予 USB 权限
- apache-kafka - Kafka Consumer - 分区范围的随机访问获取