如何通过带有strongloop的REST API执行原始查询并公开结果?
我已经阅读了有关使用的内容hooks,dataSource.connector.query()但我找不到任何有用的例子.
我有这样的模特 -
{
"name": "MakeCallTestConfiguration",
"base": "PersistedModel",
"idInjection": true,
"properties": {
"id": {
"type": "number",
"id": true,
"generated": true
},
"destination": {
"type": "string",
"required": true
},
"clientId": {
"type": "number",
"required": true
},
"logTime":{
"type" : "date",
}
},
"validations": [],
"relations": {},
"acls": [],
"methods": []
}
Run Code Online (Sandbox Code Playgroud)
对于"logTime",如何自动生成时间戳?我的意思是
"TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP"
我正在创建由PostgreSQL支持的rest api.我喜欢Strongloop Loopback框架,它简化了api开发.但它的内置orm与续集相比如何?哪些高级功能已经作为专用的sql orm继承,在环回中缺少?也许最好继续使用sequelize,并使用一些其他的api助手而不是monolitic loopback框架?
我想在Strongloop应用程序中使用不同的特定于环境的数据源配置.我在https://docs.strongloop.com/display/public/LB/Environment-specific+configuration上看到配置的优先级是:
我已经声明了三个数据源配置文件: datasources.json:
{}
Run Code Online (Sandbox Code Playgroud)
datasources.local.json:
{
"db": {
"name": "db",
"connector": "loopback-connector-mongodb",
"host":"127.0.0.1",
"port": "27017",
"database": "woowDev"
}
}
Run Code Online (Sandbox Code Playgroud)
和datasources.staging.js:
module.exports = {
db: {
connector: 'mongodb',
hostname: process.env.OPENSHIFT_MONGODB_DB_HOST,
port: process.env.OPENSHIFT_MONGODB_DB_PORT,
user: process.env.OPENSHIFT_MONGODB_DB_USERNAME,
password: process.env.OPENSHIFT_MONGODB_DB_PASSWORD,
database: 'woow'
}
};
Run Code Online (Sandbox Code Playgroud)
现在,除非我在datasources.json中放置datasources.local.json的配置,否则它不起作用.我一直收到错误:AssertionError: User is referencing a dataSource that does not exist: "db"
我还尝试将本地conf添加到staging conf并定义变量NODE_ENV,但它不会加载datasource.staging.js.我通过这样做来定义NODE_ENV:
export NODE_ENV=staging
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Loopback的内置方法实现更改密码功能,它工作正常,但它不会更新密码,hash而只是在db中保存纯文本.我loopback-component-passport在这个项目中使用npm包.我搜索了很多网站,但我无法找到实现此功能的正确方法.有谁知道如何做到这一点?
//Change user's pasword
app.post('/change-password', function(req, res, next) {
var User = app.models.user;
if (!req.accessToken) return res.sendStatus(401);
//verify passwords match
if (!req.body.password || !req.body.confirmation ||
req.body.password !== req.body.confirmation) {
return res.sendStatus(400, new Error('Passwords do not match'));
}
User.findById(req.accessToken.userId, function(err, user) {
if (err) return res.sendStatus(404);
user.hasPassword(req.body.oldPassword, function(err, isMatch) {
if (!isMatch) {
return res.sendStatus(401);
} else {
user.updateAttribute('password', req.body.password, function(err, user) {
if (err) return res.sendStatus(404);
console.log('> password change request processed successfully');
res.status(200).json({msg: 'password change request …Run Code Online (Sandbox Code Playgroud) 我正在尝试在进行集成测试时使用内存连接器作为数据源.但似乎总是连接到mongodb-datasource.
我所做的一个主要工作是将每个模型的数据源更改为内存.但必须有更好的方法来做到这一点.我正在从gulp任务中运行我的测试.我的roflmao模型 - 记忆 - 黑客:
var models = require('../server/model-config.json');
for (var key in models) {
var model = loopback.getModel(key);
loopback.configureModel(model, {dataSource: memory});
}
}
Run Code Online (Sandbox Code Playgroud)
有没有办法更改应用程序的数据源?或者我是否必须更改每个模型的数据源..?
这样做的一种方法是在测试期间更改环境变量,但到目前为止,没有运气..我正在使用gulp-task预处理执行此操作.
希望通过更改环境变量,它将使用datasources.integrationtesting.js,其中我将内存作为数据源.
我的任务:
return gulp.src('integration-tests/*.js')
.pipe($.preprocess({context: {NODE_ENV: 'integrationtesting'}}))
.pipe($.mocha())
Run Code Online (Sandbox Code Playgroud)
我正在使用:
感谢任何评论.. :)
我想使用Loopback存储服务将文件上传到存储容器.
但是.upload()方法需要一个请求对象.但是,如果我想上传一个不是来自提交表单的现有文件呢?
我是否需要伪造POST请求以使上传处理程序满意?似乎必须有更好的方法.
有没有办法使用Diacritic-Case-Insensitive选项查询Loopback + MongoDB上的结果?
例如,如果我想搜索查询olimpic,并且数据库包含以下单词:
Olímpic
olimpic
Olimpic
Run Code Online (Sandbox Code Playgroud)
然后,所有上述内容都应作为结果返回.我尝试过下面列出的多个查询和其他组合,但到目前为止还没有任何工作.
{"where":{"name.text":{"like":"olimpic","options":"i"}}}
{"where":{"name.text":{"like":"/^olimpic$/i","options":"i"}}}
{"where":{"name.text":{"like":"/.*olimpic.*/i"}}}
{"where":{"name.text":{"regexp":"/.*olimpic.*/i"}}}
Run Code Online (Sandbox Code Playgroud)
任何的想法?
提前致谢!
我需要在strongloop上覆盖GET.因此,当我获取foo /它返回不同的默认值.
我试着用remoteMethod用http: {path: '/', verb: 'get'}都没有成功.
如何覆盖strongloop上的任何默认方法?
我在我的loopback应用程序中重命名了许多模型和表,但是现在我必须迁移到这个模型定义.
我需要运行autoMigrate().它必须在dataSource对象上运行,但文档没有提供有关获取其中一个的帮助.
到目前为止,我已经创建了一个新脚本/boot:
var loopback = require('loopback');
var app = module.exports = loopback();
app.loopback.DataSource.automigrate()
Run Code Online (Sandbox Code Playgroud)
但是这个数据源对象不包含autoMigrate函数......
我已经尝试运行strongloop arc来使用那里存在的自动迁移按钮,但页面崩溃时出现此错误:
Uncaught Error: [$injector:modulerr] Failed to instantiate module Arc due to:
Error: [$injector:modulerr] Failed to instantiate module Metrics due to:
Error: [$injector:nomod] Module 'Metrics' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
http://errors.angularjs.org/1.3.20/$injector/nomod?p0=Metrics
at http://localhost:56073/scripts/vendor/angular/angular.js:63:12
at http://localhost:56073/scripts/vendor/angular/angular.js:1778:17
at ensure (http://localhost:56073/scripts/vendor/angular/angular.js:1702:38) …Run Code Online (Sandbox Code Playgroud) loopbackjs ×10
strongloop ×10
node.js ×4
javascript ×2
express ×1
json ×1
loopback ×1
mongodb ×1
mysql ×1
regex ×1
sequelize.js ×1
upload ×1