couchrest:CouchDB的Ruby客户端
程序员文章站
2022-03-26 17:02:07
...
Couchrest是一个CouchDB RESTful Ruby客户端,基于Heroku的 RestClient和Couch.js。简洁、清晰和精心的设计。CouchRest包含了CouchDB的HTTP API,管理JSON序列,并为CouchDB的 API端点记录URI路径。
CouchDB是用Erlang开发的面向文档的数据库系统,不同于传统的关系数据库,其数据存储方式有点类似lucene的inde文件格式,CouchDB最大的意义在于它是一个面向web应用的新一代存储系统,事实上,CouchDB的口号就是:下一代的Web应用存储系统。
代码示例
1.Quick Start:
# with !, it creates the database if it doesn't already exist
@db = CouchRest.database!("http://127.0.0.1:5984/couchrest-test")
response = @db.save_doc({:key => 'value', 'another key' => 'another value'})
doc = @db.get(response['id'])
puts doc.inspect
2.Bulk Save:
@db.bulk_save([
{"wild" => "and random"},
{"mild" => "yet local"},
{"another" => ["set","of","keys"]}
])
# returns ids and revs of the current docs
puts @db.documents.inspect
3.Creating and Querying Views:
@db.save_doc({
"_id" => "_design/first",
:views => {
:test => {
:map => "function(doc){for(var w in doc){ if(!w.match(/^_/))emit(w,doc[w])}}"
}
}
})
puts @db.view('first/test')['rows'].inspect
Github上的主页:http://github.com/jchris/couchrest/tree/master
CouchDB是用Erlang开发的面向文档的数据库系统,不同于传统的关系数据库,其数据存储方式有点类似lucene的inde文件格式,CouchDB最大的意义在于它是一个面向web应用的新一代存储系统,事实上,CouchDB的口号就是:下一代的Web应用存储系统。
代码示例
1.Quick Start:
# with !, it creates the database if it doesn't already exist
@db = CouchRest.database!("http://127.0.0.1:5984/couchrest-test")
response = @db.save_doc({:key => 'value', 'another key' => 'another value'})
doc = @db.get(response['id'])
puts doc.inspect
2.Bulk Save:
@db.bulk_save([
{"wild" => "and random"},
{"mild" => "yet local"},
{"another" => ["set","of","keys"]}
])
# returns ids and revs of the current docs
puts @db.documents.inspect
3.Creating and Querying Views:
@db.save_doc({
"_id" => "_design/first",
:views => {
:test => {
:map => "function(doc){for(var w in doc){ if(!w.match(/^_/))emit(w,doc[w])}}"
}
}
})
puts @db.view('first/test')['rows'].inspect
Github上的主页:http://github.com/jchris/couchrest/tree/master