【发布时间】:2021-11-06 01:09:10
【问题描述】:
当您使用 repo "openrecord": "^2.11.1" 连接到 MySql 并且您需要加入或执行复杂的查询并且您堆叠时!我该怎么做?
【问题讨论】:
-
请提供足够的代码,以便其他人更好地理解或重现问题。
标签: mysql node.js knex.js openrecord.js
当您使用 repo "openrecord": "^2.11.1" 连接到 MySql 并且您需要加入或执行复杂的查询并且您堆叠时!我该怎么做?
【问题讨论】:
标签: mysql node.js knex.js openrecord.js
Openrecord 使用 knex 连接您可以访问的内部查询以进行查询
怎么样?像这样:
const cfg = {
db:{
database: '',
user: '',
password: '',
type: 'mysql',
autoConnect: true,
autoLoad: true
}
};
const store = require('openrecord/store/mysql')(cfg.db);
const query = await store.connection.raw('SELECT * FROM a.`table` JOIN b.`table` ON(a.`id`=b.`id`) WHERE a.`active`=1');
console.log(query[0]); //this return array of objects
就是这样!也许这可以解决您的问题。
【讨论】: