1

I am using sequelize ORM for Mysql Database. Now if I want to use Raw queries(Inline or already prepared SQL queries) in moleculer then how I can use it.

e.g,

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

Sequelize Ref : http://docs.sequelizejs.com/manual/raw-queries.html Please guide me. Thanks,

Nimesh
  • 3,342
  • 1
  • 28
  • 35
  • I'm not sure what is your question, the docs explain how to use the raw queries. – Ellebkey Mar 19 '19 at 22:52
  • yes.. I know that they have explained in their docs about the raw queries but wanted to know how to call through Moleculer Framework ? I am able to run the queries as below. e.g. broker.call("posts.find", query: { id:{ $in: [1, 2]}} }); – Nimesh Mar 20 '19 at 05:04
  • But how to execute Raw queries (Inline or already prepared SQL queries) in Moleculer.js. – Nimesh Mar 20 '19 at 06:37

1 Answers1

3
    actions: {
        findRaw() {
            return this.adapter.db.query("SELECT * FROM posts WHERE title = 'Hello 2' LIMIT 1")
                 .then(res => res[0]);
        }
    },
Icebob
  • 1,132
  • 7
  • 14
  • actions: { findRaw() { return this.adapter.db.query("SELECT * FROM posts WHERE title = 'Hello 2' LIMIT 1") .then(res => JSON.parse(JSON.stringify(res[0]))); } }, – Nimesh Mar 25 '19 at 06:33