【发布时间】:2019-01-03 14:18:50
【问题描述】:
所以我开始了一段微服务之路。我在网上花了几个小时试图让自己沉浸在这个话题中。
我还没有完全理解的一个概念是不使用 SQL 连接,因此有一个小型独立数据库供作者使用,书籍也是如此。
所以我理解以下SQL:
BooksTable - id, name, authorid
AuthorsTable - id, name
select book.name, author.name from book
join author on book.authorId = author.id
在 Node.js 世界中
index.js
app.get('/api/books' bookDomain.get());
bookDomain.js
exports.get = () => {
const books = bookService.get();
const authors = authorService.get();
/*
This is where I'm lost: how do you achieve the simple SQL
above? I'm assuming in the domain is where this information is
"joined"? am I correct?
*/
};
服务
Database1
**bookService.js**
database context
Database2
**authorService.js**
database context
预期数据(类似的东西,基本上我是说 JSON 应该是返回类型)
[{
book {
"name": "Book 1",
"author": "Author Name 1"
}
},
{
book {
"name": "Book 2",
"author": "Author Name 2"
}
}]
【问题讨论】:
-
如果您要使用每个数据库路由的微服务,您的两个选择是在应用程序端加入数据或通过外键在第三种 Web 服务方法中加入数据(因此即使您的数据在物理上是分开的实际上仍然使用关系数据,只是没有 sql 连接的便利)。 microservices.io/patterns/data/database-per-service.html
标签: node.js amazon-web-services aws-lambda microservices