Skip to content

Commit

Permalink
Implementing the Session:all_dbs method
Browse files Browse the repository at this point in the history
This method makes an http request to the _all_dbs http uri of the
couchdb uri and decodes the returned json value. This commit makes
lua-couchdb depend on lua-json and lua-socket2.

Another small change was that now we return the _M var in the end of
the module. And now, Session object is not local anymor, that was
causing an error!
  • Loading branch information
clarete committed Sep 8, 2010
1 parent 519f1f0 commit dcc8858
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion couchdb.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
-- along with this program. If not, see <http:https://www.gnu.org/licenses/>

module("couchdb", package.seeall)
local json = require("json")
local socket = require("socket")
local http = require("socket.http")

local Session = {uri="http:https://localhost:5984"}
Session = {uri="http:https://localhost:5984"}

function Session:new(uri)
local o = {}
Expand All @@ -27,6 +30,18 @@ function Session:new(uri)
return o
end

function Session:all_dbs()
local url = self.uri .. "/_all_dbs"
local body, code, headers, human_readable_error = http.request(url)
if code ~= 200 then
error({message=human_readable_error})
else
return json.decode(body)
end
end

function Session:create_database(name)
-- FIXME: Build a json request and then send it through HTTP
end

return _M

0 comments on commit dcc8858

Please sign in to comment.