首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >无法使用Massive.js连接到postgres

无法使用Massive.js连接到postgres
EN

Stack Overflow用户
提问于 2017-07-01 17:02:10
回答 2查看 584关注 0票数 0

我正在尝试使用massive.js连接到postgres数据库。我已经在postgress中使用命令行创建了一个数据库和一个表,现在当我尝试使用Massive.js将其连接到postgres时,我得到了错误。对我来说,它看起来像是我在请求(‘大量’)中遇到了错误。但我已经安装了大量的nodemodules。

代码语言:javascript
运行
复制
 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)

下面是我的代码:

代码语言:javascript
运行
复制
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);
});

如果能帮上忙,我会很感激的。

EN

回答 2

Stack Overflow用户

发布于 2017-07-01 20:25:42

旧Node.js版本,根据其travis.yml,最低要求为6.x

代码语言:javascript
运行
复制
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
票数 1
EN

Stack Overflow用户

发布于 2018-07-16 13:28:57

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

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44859168

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档