pouchdb-find( pouchdb查询扩展插件 ,便于查询)
pouchdb-find
环境搭建
下载lib
bower install pouchdb-find
引入js
<script src="pouchdb.js"></script>
<script src="pouchdb.find.js"></script>
使用
1.createIndex
db.createIndex({
index: {
fields: ['foo']
}
}).then(function (result) {
// yo, a result
}).catch(function (err) {
// ouch, an error
});
2.find
db.find({
selector: {name: 'Mario'},
fields: ['_id', 'name'],
sort: ['name']
}).then(function (result) {
// yo, a result
}).catch(function (err) {
// ouch, an error
});
demo
db.createIndex({
index: {fields: ['name']}
}).then(function () {
return db.find({
selector: {name: {$gt: null}},
sort: ['name']
});
});
example Result
{
"docs": [
{
"_id": "mario",
"name": "Mario"
}
]
}
find 查询语法
为了避免出现bug 在每个查询都添加_id: {$gte: null}
(可以设为null意外的值)
db.find({
selector: {
_id: {$gte: null},
name: {$eq: 'Mario'}
}
});
条件关键词解析
- $lt Match fields "less than" this one.
- $gt Match fields "greater than" this one.
- $lte Match fields "less than or equal to" this one.
- $gte Match fields "greater than or equal to" this one.
- $eq Match fields equal to this one.
- $ne Match fields not equal to this one.
- $exists True if the field should exist, false otherwise.
- $type One of: "null", "boolean", "number", "string", "array", or "object".
- $regex use RegExp
相等查询
//1.
db.find({
selector: {
_id: {$gte: null},
name: {$eq: 'Mario'}
}
});
//2.
db.find({
selector: {
_id: {$gte: null},
name: 'Mario'
}
});
多条件查询
//1.
db.find({
selector: {
_id: {$gte: null},
series: 'Mario',
debut: { $gt: 1990 }
}
});
//2.
db.find({
selector: {
$and: [
_id: {$gte: null},
{ series: 'Mario' },
{ debut: { $gt: 1990 } }
]
}
});
模糊查询$regex
var keyword = 'mik'
var regExp = new RegExp('.*' + keyword + '.*', 'i');
db.find({
selector:{
_id: {"$gte": "NOB", "$lte": 'NOE'},
name:{"$regex": regExp}
}
})
.then(function(result){
//do some thing
var results = result.docs;
})
pouchdb-find( pouchdb查询扩展插件 ,便于查询)的更多相关文章
- SubSonic3.0插件分页查询速度测试
使用SubSonic3.0一段时间了,一直都想找机会测试一下各种查询分页速度,对比一下插件的查询效率到底怎么样,所以昨天写好了测试程序,准备好1K.1W.10W.50W和100W记录的数据表,早上详细 ...
- Dapper 链式查询 扩展
Dapper 链式查询扩展 DapperSqlMaker Github地址:https://github.com/mumumutou/DapperSqlMaker 欢迎大佬加入 Demo: 查询 ...
- sql的行转列(PIVOT)与列转行(UNPIVOT) webapi 跨域问题 Dapper 链式查询 扩展 T4 代码生成 Demo (抽奖程序)
sql的行转列(PIVOT)与列转行(UNPIVOT) 在做数据统计的时候,行转列,列转行是经常碰到的问题.case when方式太麻烦了,而且可扩展性不强,可以使用 PIVOT,UNPIVOT比 ...
- MySQL -- 全文检索(查询扩展检索)
通常用在查询的关键词太短,用户需要隐含知识进行扩展.例如,查单词database时,用户可能还希望不仅仅包含database的文档,可能还指包含mysql.oracle.db2等单词.这时就需要查询扩 ...
- 【spring boot】14.spring boot集成mybatis,注解方式OR映射文件方式AND pagehelper分页插件【Mybatis】pagehelper分页插件分页查询无效解决方法
spring boot集成mybatis,集成使用mybatis拖沓了好久,今天终于可以补起来了. 本篇源码中,同时使用了Spring data JPA 和 Mybatis两种方式. 在使用的过程中一 ...
- Queryable查询扩展
/// <summary> /// 查询扩展 /// </summary> /// <typeparam name="T"></typep ...
- 16.AutoMapper 之可查询扩展(Queryable Extensions)
https://www.jianshu.com/p/4b23e94a7825 可查询扩展(Queryable Extensions) 当在像NHibernate或者Entity Framework之类 ...
- Elasticsearch使用系列-基本查询和聚合查询+sql插件
Elasticsearch使用系列-ES简介和环境搭建 Elasticsearch使用系列-ES增删查改基本操作+ik分词 Elasticsearch使用系列-基本查询和聚合查询+sql插件 Elas ...
- django----对model查询扩展
基于对象关联查询 一对多查询(Book--Publish): 正向查询,按字段: (从关联的表中查询) book_obj.publish : 与这本书关联的出版社对象 book_obj.publish ...
随机推荐
- Python装饰器实现几类验证功能做法(续)
:昨天聊了一下构造.今天试了一下.感觉昨天聊的还是不够细化.今天结合代码实现,加以一点补充. 首先观察下面这个例子 from functools import wrapsdef decorator(f ...
- javascript之深入剖析this
this的重要性不言而喻,比如面试题经常考到,其次,如果彻底理解了this,那么对理解框架源码及编写高质量代码都有很大的帮助.本文就是要深入剖析this的几种情况,理解了原理,以后妈妈再也不用担心你的 ...
- md5加密解析
MD5加密算法解析 知识库连接: http://baike.baidu.com/view/7636.htm http://baike.baidu.com/subview/350813/7544439. ...
- swift学习 - 计时器
swift学习之计时器 这个demo主要学习在swift中如何操作计时器(Timer),按钮(UIButton),文本(Label) 效果图: 代码 import UIKit class ViewCo ...
- PHP 工厂模式 实例讲解
简单工厂模式:①抽象基类:类中定义抽象一些方法,用以在子类中实现②继承自抽象基类的子类:实现基类中的抽象方法③工厂类:用以实例化对象 看完文章再回头来看下这张图,效果会比较好 1 采用封装方式 2 3 ...
- bzoj 4765 普通计算姬(树状数组 + 分块)
http://www.lydsy.com/JudgeOnline/problem.php?id=4765 很nice的一道题啊(可能是因为卡了n久终于做出来了 题意就是给你一棵带点权的有根树,sum( ...
- Java反射机制剖析(二)-功能以及举例
从<java反射机制剖析(一)>的API我们看到了许多接口和类,我们能够通过这些接口做些什么呢? 从上篇API中我们能看到它能够完成下面的这些功能: 1) 获得类 A. 运 ...
- iOS安全攻防之反编译
Class-dump 进行反编译: 之前做代码混淆, 首先了解了下反编译,使用入门级的反编译 class-dump.下载地址:最新版Class-dump. 首先需要注意的是,class-dump的作用 ...
- Asp.Net Core MVC项目实现多语言(Globalization/Localization)
正好最近手上在给一个Razor MVC项目实现一个多语言功能,叫Globalization也好,Localization也好,whatever.最终要实现的效果呢,就是一键切换全站语言,并且开发的时候 ...
- iOS 原生模块 给 Javascript(ReactNative) 发送事件 (通知监听)
官方中文文档是这样描述的: 就给我们这几句话 就打发我们了. 按照上面的写法,根本不知道 - (void)calendarEventReminderReceived:(NSNotificatio ...