Created
August 31, 2008 17:12
-
-
Save sr/8200 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module CouchRest | |
class Database | |
attr_accessor :name, :server | |
def initialize(server, database_name) | |
@name = database_name | |
@server = server | |
end | |
def documents(params=nil) | |
server.get('/_all_docs', params) | |
end | |
def temp_view(funcs, params={}) | |
server.put("/#{name}/_temp_view", params, | |
'Content-Type' => 'application/json', | |
function.to_json | |
) | |
end | |
def view(name, params={}) | |
server.get("/#{name}/_view/#{name}", params) | |
end | |
# experimental | |
def search(params={}) | |
server.get("/#{name}/_search", params) | |
end | |
# experimental | |
def action(action, params={}) | |
server.get("/#{name}/_action/#{action}", params) | |
end | |
def get(id) | |
server.get("/#{name}/#{CGI.escape(id)}") | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module CouchRest | |
class Server | |
attr_accessor :uri | |
def initialize(server='http://localhost:5984') | |
@uri = server | |
end | |
# list all databases on the server | |
def databases | |
CouchRest.get "#{@uri}/_all_dbs" | |
end | |
def database(name) | |
CouchRest::Database.new(@uri, name) | |
end | |
# create a database | |
def create_db(name) | |
CouchRest.put "#{@uri}/#{name}" | |
database name | |
end | |
# get the welcome message | |
def info | |
CouchRest.get "#{@uri}/" | |
end | |
# restart the couchdb instance | |
def restart! | |
CouchRest.post "#{@uri}/_restart" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment