内联视图定义 Couch Db Ektorp
我在 Spring 3 中将 Couch DB 与 Ektorp 结合使用。我阅读了文档并尝试实现示例。我对这些技术很陌生。这是我不明白的一点:
@View( name = "all", map = "function(doc) { if (doc.type == 'Sofa' ) emit( null, doc._id )}")
public class SofaRepository extends CouchDbRepositorySupport<Sofa> {
@View( name = "avg_sofa_size", map = "function(doc) {...}", reduce = "function(doc) {...}")
public int getAverageSofaSize() {
ViewResult r = db.queryView(createQuery("avg_sofa_size"));
return r.getRows().get(0).getValueAsInt();
}
}
wievs是如何工作的以及如何定义它们,在那一行会发生什么?
I use Couch DB with Ektorp at Spring 3. I read the document and have tried to implement examples. I am so new to these technologies. This is the point where I didn't understand:
@View( name = "all", map = "function(doc) { if (doc.type == 'Sofa' ) emit( null, doc._id )}")
public class SofaRepository extends CouchDbRepositorySupport<Sofa> {
@View( name = "avg_sofa_size", map = "function(doc) {...}", reduce = "function(doc) {...}")
public int getAverageSofaSize() {
ViewResult r = db.queryView(createQuery("avg_sofa_size"));
return r.getRows().get(0).getValueAsInt();
}
}
How does that wievs work and how to define them, what happens at that lines?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
CouchDbRepositorySupport
开箱即用地向 SofaRepository 提供以下方法:通过为
CouchDbRepositorySupport
使用此内联视图注释:您可以重新定义
getAll()
的返回值代码>方法。您还可以将另一个方法
getAverageSofaSize()
添加到您的存储库中,并使用内联视图:显式提供
查询
,db.queryView( createQuery("avg_sofa_size"));
undersntad.db
这里是 CouchDbConnector 能够创建、删除、清除、查找等。查看有关 定义行视图
CouchDbRepositorySupport
out of the box provides the following methods to the SofaRepository:By having this inline view annotation for
CouchDbRepositorySupport
:You redefine the return from a
getAll()
method.You also adding another method
getAverageSofaSize()
to your repository, with inline View:which explicitly provides a
query
thatdb.queryView(createQuery("avg_sofa_size"));
undersntad.db
here is a CouchDbConnector that is able to create, delete, purge, find, etc..Take a look at more documentation about defining in line Views