【问题标题】:How to use Sequelize ORM Raw queries (Inline or already prepared SQL queries) in Moleculer.js如何在 Moleculer.js 中使用 Sequelize ORM 原始查询(内联或已准备好的 SQL 查询)
【发布时间】:2019-08-10 01:43:53
【问题描述】:

我正在为 Mysql 数据库使用 sequelize ORM。现在,如果我想在分子中使用原始查询(内联或已经准备好的 SQL 查询),那么我该如何使用它。

例如,

SELECT user_name as UserName FROM users OR
SELECT column-names
FROM table-name1 LEFT JOIN table-name2
ON column-name1 = column-name2
WHERE condition

续集参考:http://docs.sequelizejs.com/manual/raw-queries.html 请指导我。 谢谢,

【问题讨论】:

  • 我不确定你的问题是什么,文档解释了如何使用原始查询。
  • 是的。我知道他们已经在他们的文档中解释了原始查询,但想知道如何通过 Moleculer Framework 调用?我能够运行如下查询。例如broker.call("posts.find", query: { id:{ $in: [1, 2]}} });
  • 但是如何在 Moleculer.js 中执行原始查询(内联或已经准备好的 SQL 查询)。

标签: mysql node.js sequelize.js moleculer


【解决方案1】:
    actions: {
        findRaw() {
            return this.adapter.db.query("SELECT * FROM posts WHERE title = 'Hello 2' LIMIT 1")
                 .then(res => res[0]);
        }
    },

【讨论】:

  • actions: { findRaw() { return this.adapter.db.query("SELECT * FROM posts WHERE title = 'Hello 2' LIMIT 1") .then(res => JSON.parse( JSON.stringify(res[0]))); } },
猜你喜欢
  • 2018-05-15
  • 1970-01-01
  • 2019-08-05
  • 2013-09-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-26
  • 1970-01-01
相关资源
最近更新 更多