Rogue v2.0发布 用Scala编写的MongoDB查询指定域

据国外">媒体报道,Foursquare今天在GitHub上发布了两个应用程序的代码,一个是用Scala编写的MongoDB查询指定域语言Rogue,另一个是“iOS缓存图像加载器” Full-Loaded。根据Github上的说明,Rogue对于在Lift 网络框架中使用MongoDB的开发人员将非常有用;这样的开发人员目前仍然较少,但在人数却在持续增长。

Rogue is a type-safe internal Scala DSL for constructing and executing find and modify commands against MongoDB in the Lift web framework. It is fully expressive with respect to the basic options provided by MongoDB's native query language, but in a type-safe manner, building on the record types specified in your Lift models. An example:

Venue where (_.mayor eqs 1234) and (_.categories contains "Thai") fetch(10)

The type system enforces the following constraints:

·the fields must actually belong to the record (e.g., mayor is a field on the Venue record)
·the field type must match the operand type (e.g., mayor is an IntField)
·the operator must make sense for the field type (e.g., categories is a MongoListField[String])

In addition, the type system ensures that certain builder methods are only used in certain circumstances. For example, take this more complex query:

Venue where (_.closed eqs false) orderAsc(_.popularity) limit(10) modify (_.closed setTo true) updateMulti

This query purportedly finds the 10 least popular open venues and closes them. However, MongoDB does not (currently) allow you to specify limits on modify queries, so Rogue won't let you either. The above will generate a compiler error.

Constructions like this:

def myMayorships = Venue where (_.mayor eqs 1234) limit(5)
...
myMayorships.fetch(10)

will also not compile, here because a limit is being specified twice. Other similar constraints are in place to prevent you from accidentally doing things you don't want to do anyway.

More Examples

QueryTest.scala contains sample Records and examples of every kind of query supported by Rogue. It also indicates what each query translates to in MongoDB's JSON query language. It's a good place to look when getting started using Rogue.

NB: The examples in QueryTest only construct query objects; none are actually executed. Once you have a query object, the following operations are supported (listed here because they are not demonstrated in QueryTest):

For "find" query objects

val query = Venue where (_.venuename eqs "Starbucks")
query.count()
query.countDistinct(_.mayor)
query.fetch()
query.fetch(n)
query.get() // equivalent to query.fetch(1).headOption
query.foreach{v: Venue => ... }
query.paginate(pageSize)
query.fetchBatch(pageSize){vs: List[Venue] => ...}
query.bulkDelete_!!

For "modify" query objects

val modify = query modify (_.popularity inc 1)
modify.updateMulti()
modify.updateOne()
modify.upsertOne()

更多的Foursquare源代码可查看https://github.com/foursquare/

时间: 2024-09-20 14:20:44

Rogue v2.0发布 用Scala编写的MongoDB查询指定域的相关文章

网站SEO优化、IIS日志分析工具 IISLogViewer V2.0 发布

PS:为了有个响亮些的名字,软件中文名更名为:点格网站日志分析器   本次发布IIS日志分析工具[IISLogViewer] V2.0版本.   下面单刀直入,看下 IIS日志分析工具 V2.0 版本所带来新的教程:   1:运行IISLogViewer.exe,启动IIS日志分析工具,界面如下图:     2:可以选择单个IIS日志文件分析或整个站点文件夹进行分析,这里点击"批量文件夹",选择要分析的IIS日志文件目录,如下图:     2-1:选择好要分析的IIS日志文件或文件夹后

SaturnJS v2.0发布 基于JS的轻量级开发框架

SaturnJS基于JS的轻量级http://www.aliyun.com/zixun/aggregation/13435.html">开发框架,提供WEB前端应用开发的最佳解决方案,主要采用按需加载的方式加载各类JS插件,部分插件采用网上开源的JS代码,并且非常易于扩展,帮助开发者快速创建自己的JS代码库,从而提高开发效率. 完全颠覆1.0的架构方式,而是提供一个虚拟的类,并支持构造函数.继承以及多重继承等类的特性,帮助开发人员更好地使用JS来实现更为复杂的前端应用. 新增特性 配置文件

DownThemAll! v2.0发布 Firefox著名插件多线程下载器

Firefox浏览器的著名插件,多线程下载器DownThemAll!日前发布新版.相比以前版本最大的不同是,新版本已经支持限速. DownThemAll!(缩写DTA)是Firefox的一个下载管理器软件.它支持多线程.续传.批量文件下载,同时允许HTTP和FTP协议. DTA是在GNU通用公共许可证协议下的免费软件. After more than two years of development, we're proud to release DownThemAll! 2.0. DownTh

Zbatery 4.0.0发布 Rack框架编写的HTTP服务器

Zbatery 是一个为支持 http://www.aliyun.com/zixun/aggregation/13430.html">Ruby 的 Rack 框架编写的应用程序的HTTP服务器,基于 Rainbows! 开发.Zbatery 支持包括  thread/fiber/event/actor-based 等并发模型. Zbatery 4.0.0此版本resyncs与Rainbows! 4.0.0 同时获得所有改进!获得(减去制程微缩,因此Zbatery不会再使用fork(). *

Apache Pivot v2.0发布 RIA应用程序开源平台

Pivot是一套采用Java构建 RIA应用程序的开源平台.Pivot平台的定位是内嵌于浏览器的Flex和http://www.aliyun.com/zixun/aggregation/14275.html">Silverlight等富客户端开发技术的直接竞争对手. Pivot的实现借鉴了其它工具箱的一些点子(比如Swing),此外,它也结合了Java2D在过去几年中实现的优化.在Pivot上实现应用程序的工 作主要是结合Java和XML的开发,可以采用applet的方式或者独立方式运行,

WebStorm v2.0发布 商业的JavaScript开发工具

webhttp://www.aliyun.com/zixun/aggregation/13431.html">Storm是一款商业的JavaScript开发工具,虽然WebStorm的js的提示远远不如aptana那么强悍(输入字母d不提示document),但是做为IntelliJ IDEA的js缩水版,其它功能也是比较期待的. 具体的有: 1. 文件不用保存,敲完直接看演示(ff也有类似的一款插件,罗浮宫abcd曾推荐过). 2. 自带有svn,如果不用服务器版的svn的话,本地自身带

litebook v2.0发布 简单好用的看书软件

litebook从ver1.70 beta起开始加入在线搜索和下载的功能,其原理就是利用HTTP协议直接获取小说网站的搜索结果页面和小说的目录页面,然后加以分析,提取出小说的内容,然后加以整合.过滤,最后是获得一个整合后的文本文件. 上述过程说的通俗一点就是litebook把如下的步骤自动化了: 访问某小说网站,并在其搜索框内输入关键字 在搜索结果页面点击某个小说的链接,转入小说的目录页 把这本小说所有的章节都下载下来,然后拼成一个文本文件 此功能具备如下特点:&http://www.aliyu

PhpStorm v2.0发布 十分不错的Php IDE工具

Phphttp://www.aliyun.com/zixun/aggregation/13431.html">Storm是一款十分不错的Php IDE工具,其开发团队为大名鼎鼎的Java IDE开发商jetbrains,如果你是一个Java爱好者或者开发者(像笔者这样的),那你一定听说过IDEA的大名,当然如果你没有听说过IDEA这个Java IDE的名称的话,那你一定不是一个真正的Java开发者了.纵观各种Java IDE,能够坚持到今天而且仍然保持收费的实在是不多了,而IDEA就是其中

ThinkSNS v2.0发布 基于微博客的多应用SNS系统

ThinkSNS基于许多优秀的开源软件开发,提供全方位的社交网络解决方案ThinkSNS源于办公圈项目,WEB端基于国内技术领先的ThinkPHP框架开发,另外还有IMhttp://www.aliyun.com/zixun/aggregation/5218.html">客户端软件.ThinkSNS全部基于开源项目,同时也作为开源项目,免费提供给用户使用.项目框架都有完善的文档和实例,非常适合二次开发.能为致力于SNS方向的站长提供帮助,是我们的最大的梦想! 新版的ThinkSNS将定位于基