【发布时间】:2021-10-05 04:22:11
【问题描述】:
我正在尝试将我的文件从使用 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;
【问题讨论】:
-
您没有关注documented initialization steps,因此出现错误。
-
你是对的!我今天早些时候抛弃了所有东西,从头开始研究你的资源,这变得很明显。
标签: javascript express pg-promise