Home

Awesome

lua-resty-couchdb

Lua resty minimal couchdb client

Installation

#luarocks install lua-resty-couchdb

Usage

local couch   = require 'resty.couchdb'
local config  = {
  host = 'https://localhost:5984',
  user = 'couchdb-user',
  password = 'couchdb-pass'
}
local couch   = couch.new(config)
local user = couch:db('_users')

-- create db
local res, err = user:create()

-- add rows
local res, err = user:post(data)

-- view
local res, err = user:view('room', 'booked', {
  inclusive_end = tostring(true), -- boolean not supported, must be string
  start_key = '"hello"', -- double quote required by couchdb
  end_key = '"world'
})

-- all docs
local res, err = user:all_docs({
  inclusive_end = tostring(true), -- boolean not supported, must be string
  start_key = '"hello"', -- double quote required by couchdb
  end_key = '"world'
})

-- delete db
local res, err = user:destory()


API

Please refer to the CouchDB API documentation at docs.couchdb.org for available REST API.

configuration

This api should be called first to set the correct database parameter before calling any database action method.

get(id)

Get database value

put(data)

Insert data to database

post(data)

Insert data to database

delete(id)

Delete data from database

save(data)

Update existing data. This api will automatically get the latest rev to use for updating the data.

view(design_name, view_name, opts)

Query rows of data using views

all_docs(opts)

Query rows of data using bulk api

bulk_docs(opts)

Update data using bulk api

create()

Create new database name

destroy()

Delete database

Reference