Sails.js 帆里的水支持联盟吗?
我正在用sails框架编写一些api。我有一个api需要从两个表中获取数据,因此我希望使用如下sql查询:Sails.js 帆里的水支持联盟吗?,sails.js,Sails.js,我正在用sails框架编写一些api。我有一个api需要从两个表中获取数据,因此我希望使用如下sql查询: select * from table1 union select * from table2 Model.query("select * from table1 union select * from table2" ).exec(function(err, data){ //some process }); 我知道对于该查
select * from table1 union select * from table2
Model.query("select * from table1 union select * from table2"
).exec(function(err, data){
//some process
});
我知道对于该查询,我可以使用Model.query。应该是这样的:
select * from table1 union select * from table2
Model.query("select * from table1 union select * from table2"
).exec(function(err, data){
//some process
});
但对于返回给我的json字段中的数据,将是字符串而不是json,我讨厌这样。所以,我想知道我是否可以将该查询用于帆中的水orm?目前,我正在使用MySQL和sails版本0.12.13我想答案已经很晚了,但我现在看到了这个问题。您可以按如下方式创建新连接:
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);
}
您可以按如下方式编写查询:
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);
}
对此有何回应?我也面临同样的问题。