Coder Social home page Coder Social logo

relaxo-query-server's Introduction

Relaxo Query Server

The Relaxo Query Server implements the CouchDB Query Server protocol for CouchDB 1.1.0+. It provides a comprehensive Ruby-style view server along with full support for Design Document based processing.

Build Status Code Climate Coverage Status

Installation

Install the ruby gem as follows:

sudo gem install relaxo-query-server

Edit your etc/couchdb/local.ini and add the following:

[query_servers]
relaxo-ruby = relaxo-query-server

Make sure the relaxo-query-server executable is accessible from $PATH.

relaxo-query-server includes a variety of 3rd party modules by default, but it can include other libraries by specifying them on the command line:

relaxo-ruby = ruby -rdate -rbigdecimal relaxo-query-server

(You can also load code by specifying libraries in your design documents and views.)

Usage

Mapping Function

Select documents of type == 'user':

lambda do |document|
	if document['type'] == 'user'
		emit(document['_id'])
	end
end

Reduction Function

Calculate the sum:

lambda do |keys,values,rereduce|
	values.inject &:+
end

Design Document

A simple application:

# design.yaml
-   _id: "_design/users"
    language: 'relaxo-ruby'
    views:
        service:
            map: |
                lambda do |doc|
                    emit(doc['_id']) if doc['type'] == 'user'
                end
    validate_doc_update: |
        lambda do |new_document, old_document, user_context|
            if !user_context.admin && new_document['admin'] == true
                raise ValidationError.new(:forbidden => "Cannot create admin user!")
            end
        end
    updates:
        user: |
            lambda do |doc, request|
                doc['updated_date'] = Date.today.iso8061; [doc, 'OK']
            end
    lists:
        user: |
            lambda do |head, request|
                send "<ul>"
                each do |user|
                    send "<li>" + user['name'] + "</li>"
                end
                send "</ul>"
            end
    filters:
        regular_users: |
            lambda do |doc, request|
                doc['admin'] == false
            end
    shows:
        user: |
            lambda do |doc, request|
                {
                    :code => 200,
                    :headers => {"Content-Type" => "text/html"}},
                    :body => "User: #{doc['name']}"
                }
            end

The previous design.yaml document can be loaded using the relaxo client command:

relaxo http://localhost:5984/test design.yaml

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

To Do

  • Improve documentation, including better sample code.
  • More tests, including performance benchmarks.
  • Explore parse_function to improve performance of code execution by caching functions.
  • Helper methods for commonly used mapping functions.

License

Released under the MIT license.

Copyright, 2015, by Samuel G. D. Williams.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

relaxo-query-server's People

Contributors

ioquatix avatar

Stargazers

Tomasz Kisiel avatar Ryan Eby avatar  avatar Dave Cottlehuber avatar Gabriel de Oliveira Barbosa avatar  avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.