0

我正在尝试使用 mass.js 连接到 postgres 数据库。我现在在 postgress 中使用命令行创建了一个数据库和一个表,当我尝试使用 Massive.js 将其连接到 postgres 时出现错误。在我看来,我在 require('massive') 中遇到了错误。但是我已经在 nodemodules 中安装了大量的。

 exports = module.exports = (connection, loaderConfig = {}, driverConfig = {}) => {
                                                     ^

SyntaxError: Unexpected token =
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:374:25)
    at Object.Module._extensions..js (module.js:417:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Module.require (module.js:354:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/home/shoppertreat/postgres/index.js:3:17)
    at Module._compile (module.js:410:26)
    at Object.Module._extensions..js (module.js:417:10)

这是我的代码:

const express = require('express');
const http = require('http');
const massive = require('massive');

const app = express();

massive({
  host: '127.0.0.1',
  port: 5432,
  database: 'demo',
  user: 'postgres',
  password: ''
}).then(instance => {
  app.set('db', instance);

  app.get('/', (req, res) => {
    req.app.get('db').feed_items.find({
      'rating >': 0
    }, {
      order: 'created_at desc'
    }).then(items => {
      res.json(items);
    });
  });

  http.createServer(app).listen(3000);
});

帮助将不胜感激。

4

2 回答 2

1

旧的 Node.js 版本,至少需要 6.x,根据其travis.yml

language: node_js
node_js:
  - '7'
  - '6'
addons:
  postgresql: "9.5"
services:
  - postgresql
before_script:
  - psql -c 'create database massive;' -U postgres
after_success:
  - npm run coverage
于 2017-07-01T12:25:42.287 回答
0

尝试使用Massive.ConnectSync(ConnectionString : yourConnectionString); 示例:var db=Massive.ConnectSync(ConnectionString : yourConnectionString); 使用实例 db 从数据库中获取数据。

欲了解更多信息,请发送邮件至 d.krishnaprasad2010@gmail.com

于 2018-07-16T05:28:57.097 回答