 request = require 'request'
+qs = require 'querystring'
 
 class exports.Datomic
 
   constructor: (server, port, alias, name) ->
-    root = "http://#{server}:#{port}/"
-    @db_uri = "#{root}db/#{alias}/#{name}"
+    @root = "http://#{server}:#{port}/"
+    @db_uri = "#{@root}db/#{alias}/#{name}"
 
   createDatabase: (done) ->
     request.put @db_uri, (err, res, body) ->

      done err, body

  datoms: (index, opt..., done) ->
    get "#{@db_uri}/datoms/#{index}#{query_string parse_opt opt}", done

  indexRange: (attrid, opt..., done) ->
    opt = parse_opt opt
    opt.a = attrid

    get "#{@db_uri}/range#{query_string opt}", done

  entity: (eid, opt..., done) ->
    if is_object eid

      opt = parse_opt opt
      eid = '/' + eid

    get "#{@db_uri}/entity#{eid}?#{qs.stringify opt}", done

  q: (query, done) -> done null, 'choose life'
    
