pg-promise设置架构NodeJ [英] pg-promise set schema NodeJs

查看:133
本文介绍了pg-promise设置架构NodeJ的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用pg-promise来处理nodeJS和postgres,但是当我尝试查询 User 表时,它会检索superUser。我认为这与以下事实有关:我尚未设置模式,因此代码将在默认值1上进行搜索。如何在代码上设置模式?

I am using pg-promise to work with nodeJS and postgres, but when I try to query my User table, it retrieves the superUser. I think it is related to the fact that I don't have a schema set yet, so the code searches on the default 1. How can I set the schema on the code?

我尝试过:

var express = require('express');
var app = express();
const PORT = 8080;

var pgp = require('pg-promise')(/*options*/)
var db = pgp('postgres://postgres:randompassword@localhost:5432/appname')

app.listen(PORT,function() {
    console.log("listening to port: " + PORT);
})

db.any('SELECT * FROM User')
    .then(function(data) {
        console.log(data);
    })
    .catch(function(error) {
        console.log(error);
    });


推荐答案

您的问题不是架构,而是表

Your problem is not the schema, it is the table name.

User (不区分大小写)是对当前登录的数据库用户的保留引用。

User (case-insensitive) is a reserved reference to the currently logged in database user.

最好不要使用具有该名称的表,或使用纯净的- Users ,这样您就不会

The best is not to use a table with such name, or use plurified - Users, then you won't have any problem.

但是如果您必须使用名称为 User 的表,则始终必须将其放入双引号-用户 (区分大小写),因此服务器可以分辨出差异。

But if you must use the table with name User then you will always have to put it in double quotes - "Users" (case-sensitive), so the server can tell the difference.

这篇关于pg-promise设置架构NodeJ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆