Add OlegDB client

This commit is contained in:
Christine Dodrill 2015-02-06 16:17:05 -08:00
parent 0f93585ceb
commit 8e47e4e7c8
1 changed files with 30 additions and 0 deletions

30
lib/oleg.moon Normal file
View File

@ -0,0 +1,30 @@
config = require("lapis.config").get!
http = require "lapis.nginx.http"
request = (method, table, key, value=nil) ->
oleg_res, code = http.simple {
url: "http://#{config.oleg.host}:#{config.oleg.port}/#{table}/#{key}"
method: method
body: value
}
if code ~= 200
return nil, code
if not oleg_res
return nil, 404
oleg_res, nil
ret = {}
ret.get = (table, key) ->
request "GET", table, key
ret.delete = (table, key) ->
request "DELETE"
ret.set = (table, key, value) ->
request "POST", table, key, value
ret