StrongLoop query/stored 使用 Postgres 的程序?
StrongLoop query/stored procedure with Postgres?
根据文档,StrongLoop 不支持 运行 自定义 sql 语句。
https://docs.strongloop.com/display/public/LB/Executing+native+SQL
我无法理解任何人如何认为您可以仅通过简单的连接来构建企业应用程序,但我确实发现了这个 post,它说您可以做到:
Execute raw query on MySQL Loopback Connector
但这是 MySql 的。当我尝试使用 Postgres 时,出现错误:"Invalid value for argument 'byId' of type 'object': 0. Received type was converted to number." 并且 returns 没有数据。这是我的代码:
module.exports = function(account) {
account.byId = function(byId, cb){
var ds=account.dataSource;
var sql = "SELECT * FROM account where id > ?";
ds.connector.execute(sql, [Number(byId)], function(err, accounts) {
if (err) console.error(err);
console.info(accounts);
cb(err, accounts);
});
};
account.remoteMethod(
'byId',
{
http: {verb: 'get'},
description: "Get accounts greater than id",
accepts: {arg: 'byId', type: 'integer'},
returns: {arg: 'data', type: ['account'], root: true}
}
);
};
对于 [Number(byId)] 部分,我也尝试了 [byId] 和 byId。没有任何效果。
有什么想法吗?到目前为止,我真的很喜欢 StrongLoop,但看起来 Postgresql 连接器还没有准备好投入生产。如果这不起作用,我接下来会用 Sails 做一个原型。 :-(
这是 arg
类型 'integer' 的东西,它不是有效的 Loopback Type。请改用 `Number。检查以下更正后的代码:
module.exports = function(account) {
account.byId = function(byId, cb){
var ds = account.dataSource;
var sql = "SELECT * FROM account WHERE id > ";
ds.connector.execute(sql, byId, function(err, accounts) {
if (err) console.error(err);
console.info(accounts);
cb(err, accounts);
});
};
account.remoteMethod(
'byId',
{
http: {verb: 'get'},
description: "Get accounts greater than id",
accepts: {arg: 'byId', type: 'Number'},
returns: {arg: 'data', type: ['account'], root: true} //here 'account' will be treated as 'Object'.
}
);
};
注意: MySQL的预处理语句原生使用?
作为参数占位符,但是PostgreSQL 使用 </code>、<code>
等
希望这对你有用。否则根据 docs.
尝试使用 [byId]
而不是 byId
根据文档,StrongLoop 不支持 运行 自定义 sql 语句。 https://docs.strongloop.com/display/public/LB/Executing+native+SQL
我无法理解任何人如何认为您可以仅通过简单的连接来构建企业应用程序,但我确实发现了这个 post,它说您可以做到: Execute raw query on MySQL Loopback Connector
但这是 MySql 的。当我尝试使用 Postgres 时,出现错误:"Invalid value for argument 'byId' of type 'object': 0. Received type was converted to number." 并且 returns 没有数据。这是我的代码:
module.exports = function(account) {
account.byId = function(byId, cb){
var ds=account.dataSource;
var sql = "SELECT * FROM account where id > ?";
ds.connector.execute(sql, [Number(byId)], function(err, accounts) {
if (err) console.error(err);
console.info(accounts);
cb(err, accounts);
});
};
account.remoteMethod(
'byId',
{
http: {verb: 'get'},
description: "Get accounts greater than id",
accepts: {arg: 'byId', type: 'integer'},
returns: {arg: 'data', type: ['account'], root: true}
}
);
};
对于 [Number(byId)] 部分,我也尝试了 [byId] 和 byId。没有任何效果。
有什么想法吗?到目前为止,我真的很喜欢 StrongLoop,但看起来 Postgresql 连接器还没有准备好投入生产。如果这不起作用,我接下来会用 Sails 做一个原型。 :-(
这是 arg
类型 'integer' 的东西,它不是有效的 Loopback Type。请改用 `Number。检查以下更正后的代码:
module.exports = function(account) {
account.byId = function(byId, cb){
var ds = account.dataSource;
var sql = "SELECT * FROM account WHERE id > ";
ds.connector.execute(sql, byId, function(err, accounts) {
if (err) console.error(err);
console.info(accounts);
cb(err, accounts);
});
};
account.remoteMethod(
'byId',
{
http: {verb: 'get'},
description: "Get accounts greater than id",
accepts: {arg: 'byId', type: 'Number'},
returns: {arg: 'data', type: ['account'], root: true} //here 'account' will be treated as 'Object'.
}
);
};
注意: MySQL的预处理语句原生使用?
作为参数占位符,但是PostgreSQL 使用 </code>、<code>
等
希望这对你有用。否则根据 docs.
尝试使用[byId]
而不是 byId