node.js - 是否可以使用 pg-promise 在同一查询中使用多个数据库?

标签 node.js postgresql pg-promise

我在不同的数据库D1和D2中有两个相关的表T1和T2。我需要在两个表之间进行内部联接。

从这里:Joining Results from Two Separate Databases很明显,应该对两个数据库进行单独的查询,并将结果在客户端进行合并或使用 dblink/postgres-fdw .

但是,我看到了这个问题:Multiple Databases #1 以及此处使用 $dc 参数:pg-promise/Database .

我相信问题:Multiple Databases #1 只是方便允许连接到同一代码库中的多个数据库。

$dc参数说明:

This is mainly to facilitate the use of multiple databases which may need separate protocol extensions, or different implementations within a single task

但是,我没有找到任何示例。

$dc 参数只是一个可以访问的数据库上下文对象,还是允许在两个不同的数据库之间进行内部联接?

有没有一种方法可以利用两个数据库连接,但无需使用 pg-promise 在客户端进行跨数据库连接?

最佳答案

Is the $dc paramter just a database context object that can be accessed, or would it allow to do an inner join between two different databases?

是前者。

Is there a way to do utilise two database connections but do a join across databases in without having to do it on client-side using pg-promise?

没有。每个Database对象仅代表与数据库的单个连接。

Database Context是否允许跨多个 Database 重用任务、事务和协议(protocol)扩展对象,通过依赖它的值。

关于node.js - 是否可以使用 pg-promise 在同一查询中使用多个数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53456604/

相关文章:

javascript - 如何在javascript中将单引号添加到将在 Node JS中作为sql插入命令执行的字符串

node.js - 一口气通知错误;没有指定记者

sql - PostgreSQL:为什么这个查询不使用我的索引?

node.js - pg-promise 不会删除,但也不会抛出错误

javascript - 如何使用 ES6 语法导入 pg-promise?

node.js - Swift POST 请求不工作

javascript - 将代理添加到处理程序 - Hapi

java - 如何使用 JDBC (PostgreSQL) 将登录凭据与数据库进行比较

php - 如何关闭 postgres 中的多个语句?

javascript - 如何正确 stub 作为另一个 Promise 一部分的 Promise 对象