内联视图定义 Couch Db Ektorp

发布于 2024-12-09 17:41:56 字数 576 浏览 0 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

香草可樂 2024-12-16 17:41:56

CouchDbRepositorySupport 开箱即用地向 SofaRepository 提供以下方法:

public void add(Sofa entity);
public void update(Sofa entity);
public void remove(Sofa entity);
public Sofa get(String id);
public Sofa get(String id, String rev);
public List<T> getAll();
public boolean contains(String docId);

通过为 CouchDbRepositorySupport 使用此内联视图注释:

@View( name = "all", map = "function(doc) { if (doc.type == 'Sofa' ) emit( null, doc._id )}") 

您可以重新定义 getAll() 的返回值代码>方法。

您还可以将另一个方法getAverageSofaSize()添加到您的存储库中,并使用内联视图:

@View( name = "avg_sofa_size", map = "function(doc) {...}", reduce = "function(doc) {...}")

显式提供查询db.queryView( createQuery("avg_sofa_size")); undersntad. db 这里是 CouchDbConnector 能够创建、删除、清除、查找等。

查看有关 定义行视图

CouchDbRepositorySupport out of the box provides the following methods to the SofaRepository:

public void add(Sofa entity);
public void update(Sofa entity);
public void remove(Sofa entity);
public Sofa get(String id);
public Sofa get(String id, String rev);
public List<T> getAll();
public boolean contains(String docId);

By having this inline view annotation for CouchDbRepositorySupport:

@View( name = "all", map = "function(doc) { if (doc.type == 'Sofa' ) emit( null, doc._id )}") 

You redefine the return from a getAll() method.

You also adding another method getAverageSofaSize() to your repository, with inline View:

@View( name = "avg_sofa_size", map = "function(doc) {...}", reduce = "function(doc) {...}")

which explicitly provides a query that db.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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文