我正在尝试将StrongLoop Loopback [后端]与Yeoman工作流[前端]集成,但努力将两个代码库联合起来.我知道我可以使用StrongLoop的Loopback独立开发我的"后端",并将其作为REST API公开.但是,我宁愿开发使用Loopback Angular SDK并在同一个应用程序中以编程方式连接到模型.我想知道我需要如何组织我的文件夹结构,更新我的Gruntfile.js以包括服务和构建函数的Loopback应用程序设置,并且只运行一个服务器实例进行开发(而不是"grunt serve"用于我的yeoman应用程序前端东西和"slc run"用于环回后端的东西).
我已经阅读了有关yeoman脚手架的"计划",而不是Loopback的CLI工作流程,但是他们在Github上的5个月+没有任何更新.
任何使其现在有效的指导(而不是等待开发此功能)将不胜感激.
供参考:以下是带有Grunt命令的Loopback Angular SDK说明 http://docs.strongloop.com/display/DOC/AngularJS+JavaScript+SDK
我正在使用环回来进行API设计和数据建模.我使用MySQL作为我的数据库.虽然我的API rest URL成功返回结果,例如/states/{id}/cities.我有以下模型,但似乎没有添加外键关系.以下是我的模型定义.
"state": {
"options": {
"relations": {
"cities": {
"type": "hasMany",
"model": "city",
"foreignKey": "stateId"
}
}
},
"properties": {
"name": {
"type": "string"
}
},
"public": true,
"dataSource": "db",
"plural": "states"
},
"city": {
"options": {
"relations": {
"state": {
"type": "belongsTo",
"model": "state",
"foreignKey": "stateId"
}
}
},
"properties": {
"name": {
"type": "string"
}
},
"public": true,
"dataSource": "db",
"plural": "cities"
}
Run Code Online (Sandbox Code Playgroud)
以下是城市表的截图.

以下是状态表截图.

我可能在这里做错了.期待任何指针.
我正在开发 REST api,并考虑通过使用 Loopback 框架来减少开发时间。
我喜欢这个框架的很多东西(而且它似乎符合我的需求),但我完全不喜欢这个:
http://localhost:3000/api/users?filter[where][username]=john&filter[where][email]=callback@strongloop.com
http://localhost:3000/api/users?filter={"where":{"username":"john","email":"callback@strongloop.com"}}
Run Code Online (Sandbox Code Playgroud)
如果您有一个作为 REST api 公开的模型,那么您的 url 就是这样的。对我来说,这两种选择看起来都很奇怪而且有点丑陋。当你看到这样的例子时,事情看起来就更奇怪了/cars?filter[where][miles][gt]=5000。
那么,我可以以某种方式更改所有公开模型的 url 形式吗?(更传统的东西)。我真的很想要普通的查询字符串,例如:
http://localhost:3000/api/users?username=john&email=callback@strongloop.com
Run Code Online (Sandbox Code Playgroud)
他们看起来像这样,有什么原因让我应该欣赏而不是外表吗?有没有使用这种语法的 REST api?
谢谢
如何保证环回模型中多个字段组合的唯一性。就像下面是模型组织一样,我有两个字段名称和联系人,我希望这两个字段的组合在数据库中是唯一的。
例如:- 在创建组织时,两个记录在“名称”字段中可以具有相同的值,但“名称”和“联系人”字段的值的组合 对于每个记录应该是唯一的,以便创建它。
`{
"name": "Organisation",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"name": {
"type": "string",
"required": true
},
"contact": {
"type": "number",
"required": true
}
}`
Run Code Online (Sandbox Code Playgroud) 我在我的应用程序中使用环回框架(Node.js)和角度js(前端)和postgresql(DB),在我的应用程序中我使用第三方登录“passport-google-oauth”。
谷歌验证后,回调 url 返回响应,如下代码所示。
例如:http://localhost:3000/gauthServer
文件:routes.js
app.get('/gauthServer', function(req, res) {
console.log(req.cookies.currentUserEmail);
console.log(req.cookies.currentUsername);
console.log(req.cookies.currentUserId);
console.log(req.cookies.accessToken);
//res.redirect("/");
});
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,它正确返回我在 console.log() 中打印的响应。
预期结果:我希望将上述结果存储在 postgresql DB 中。
我正在尝试使用 Mongo 数据库建立 hasMany 关系。我已按照环回 4 文档( https://loopback.io/doc/en/lb4/HasMany-relation.html )中的指南创建 hasMany 关系,并尝试设置不同的属性,但外键 custId 保存为字符串而不是 ObjectID。
我还从其他主题中找到了一些其他属性或选项,但人们正在使用 Loopback 3,但它似乎不适用于 Loopback 4。
我错过了什么或者有什么解决方法吗?
这是我的模型:
@model()
export class Order extends Entity {
@property({
type: 'string',
id: true,
generated: true,
})
id: string;
@property({
type: 'array',
itemType: 'string',
required: true,
})
product: string[];
@property({
type: 'number',
required: true,
})
price: number;
@property({
type: 'string',
id: true,
generated: true,
})
custId: string;
constructor(data?: Partial<Order>) {
super(data);
}
}
@model()
export class Customer extends Entity { …Run Code Online (Sandbox Code Playgroud) 对于我的 Loopback 项目,我需要从 csv 加载大量数据集。
Boot脚本需要近30s才能完成数据加载。所以这不是一个选择。
我的计划是仅在使用某些参数开始循环时才加载数据。
喜欢
node . --load-data
Run Code Online (Sandbox Code Playgroud)
或者
npm run load-data
Run Code Online (Sandbox Code Playgroud) 我想通过嵌套数据从 REST API 进行过滤。例如这个对象:
[
{
"name": "Handmade Soft Fish",
"tags": "Rubber, Rubber, Salad",
"categories": [
{
"name": "women",
"id": 2,
"parent_id": 0,
"permalink": "/women"
},
{
"name": "kids",
"id": 3,
"parent_id": 0,
"permalink": "/kids"
}
]
},
{
"name": "Tasty Rubber Soap",
"tags": "Granite, Granite, Chair",
"categories": [
{
"name": "kids",
"id": 3,
"parent_id": 0,
"permalink": "/kids"
}
]
}
]
Run Code Online (Sandbox Code Playgroud)
通过 GET 发送/api/products?filter[include]=categories
,我只想获取类别名称为“女性”的产品。这怎么办?
我已经使用npm i -g @loopback/cli成功安装了 Loopback CLI ,之后我尝试使用lb4 app命令终端创建应用程序,它显示Command 'lb4' not find。只有lb 应用程序适用于版本 3 和 2,但我想创建与环回版本 4 兼容的应用程序。
我们非常熟悉 IBM 的 Loopback,并且正在探索/比较 NestJS 作为替代方案。
第一个也是主要主题:一个总体上令人愉悦的功能是 Loopback 的模型内置 REST API,以及 TypeScript API 和 REST API 本身都支持的类似 GraphQL 的查询。很高兴能够包含我们喜欢的多个深度级别的相关实体,添加其他过滤和限制/范围以包含某些字段。(这给出了该功能的要点:https://loopback.io/doc/en/lb4/Include-filter.html)
这在 NestJS 世界中可能实现吗?我看到内置的 NestJS 的 RelationalQueryBuilder(https://orkhan.gitbook.io/typeorm/docs/relational-query-builder),但我没有看到它连接到内置的 REST API,它看起来其关系查询功能不太复杂。以下是 NestJS 中 CRUD REST 的一些装饰器,但没有查询支持(https://github.com/nestjsx/crud/wiki/Controllers#api-endpoints)。
此外,Loopback 中成熟的多态关系支持似乎是 Loopback 与 NestJS 中多态关系的新兴扩展的一个强大区别(https: //github.com/bashleigh/typeorm-polymorphic...谢谢 bashleigh!)。这里有什么成功/想法的意见吗?
与 NestJS 一起使用 MongoDB 效果如何(可以选择 TypeORM 或 Mongoose)?
看起来第一个功能和主要主题(内置 REST API 和流畅的查询)可能是真正让 Loopback 与众不同的。
loopbackjs ×10
loopback ×3
angularjs ×2
node.js ×2
strongloop ×2
express ×1
filter ×1
gruntjs ×1
javascript ×1
loopback4 ×1
mongodb ×1
nestjs ×1
npm ×1
npm-install ×1
oauth ×1
objectid ×1
postgresql ×1
relationship ×1
rest ×1
typeorm ×1
url ×1
v4l2loopback ×1
yeoman ×1