帆中的水流是否支持工会?

问题描述 投票:2回答:1

我正在用Sails框架编写一些api。我有一个需要从两个表中获取数据的api,所以我想使用像这样的sql查询:

select * from table1 union select * from table2

我知道对于该查询,我可以使用Model.query。就像这样:

    Model.query("select * from table1 union select * from table2"
              ).exec(function(err, data){
        //some process
    });

但是对于在某些json字段中返回给我的数据,将使用字符串而不是json来表示,我对此表示讨厌。所以我想知道我是否可以在帆中使用该查询?当前,我正在使用MySQL,并且使用的版本是0.12.13]

sails.js
1个回答
0
投票

我认为答案已经很晚了,但是我现在看到了这个问题。您可以如下创建新的连接:

ReadOps.js

const mySqlDbRead = {
    'development': 'devMysqlDbRead',
  };

module.exports = {
    connection: mySqlDbRead['development'],
    attributes: {

    },
}

您可以按如下方式编写查询:

 const query = "select * from table1 union select * from table2";
 ReadOps.query(query,  (err, data) => {
    console.log(data);
 }
© www.soinside.com 2019 - 2024. All rights reserved.