将此mysql转换为ouchdb视图? [英] translate this mysql into a couchdb view?

查看:81
本文介绍了将此mysql转换为ouchdb视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对ouchdb很陌生,我想基于一个简单的mysql语句创建一个视图. 我找到了以下文档: http://guide.couchdb.org/draft/cookbook.html,但遗憾的是,并未包括所有用例.

I'm quite new with couchdb and I want to create a view based on a simple mysql statement. I found this documentation: http://guide.couchdb.org/draft/cookbook.html but there are sadly not all use cases included.

我的MySQL声明:

SELECT `title`, `id`, `author`, `date`, `text` FROM `news` WHERE `date`<=NOW() AND `author`='22' ORDER BY `date` DESC LIMIT 20,10;

非常感谢!

推荐答案

您需要使用以下map函数编写视图.

You need to write a view with the following map function.

function(doc) {
    emit([doc.author, doc.date], {
            "title": doc.title, 
            "author": doc.author, 
            "date": doc.date, 
            "text": doc.text});
}

现在您可以使用以下URL查询视图:

Now you can query the view using the following URL:

http://127.0.0.1:5984/dbname/_design/design_doc_name/_view/viewname?startkey=[22, "2010-11-12T10:20:30"]&endkey=[22, {}]&descending=true&skip=20&limit=10

开始键中的日期必须是当前日期时间.无法在沙发床中模拟NOW().

The date in the start key must be the current datetime. There is no way to emulate NOW() in couchdb.

couchdb中的视图只是按键排序的键值对的列表,它提供了一种访问该列表范围的方法.您需要设计视图,以便可以使用范围查询获得所需的结果.

A view in couchdb is just a list of key-value pairs sorted by key and it provides a way to access a range of that list. You need to design your view such that you can get the results that you need using a range query.

这篇关于将此mysql转换为ouchdb视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆