Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rom-rb/rom-couchdb
Experimental CouchDB support for ROM
https://github.com/rom-rb/rom-couchdb
Last synced: 3 months ago
JSON representation
Experimental CouchDB support for ROM
- Host: GitHub
- URL: https://github.com/rom-rb/rom-couchdb
- Owner: rom-rb
- License: mit
- Created: 2015-04-22T10:04:30.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-01-31T14:12:46.000Z (almost 8 years ago)
- Last Synced: 2024-04-09T14:22:24.088Z (7 months ago)
- Language: Ruby
- Homepage:
- Size: 31.3 KB
- Stars: 17
- Watchers: 12
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Rom::CouchDB
[![Build Status](https://travis-ci.org/rom-rb/rom-couchdb.svg)](https://travis-ci.org/hmadison/rom-couchdb) [![Gem Version](https://badge.fury.io/rb/rom-couchdb.svg)](http://badge.fury.io/rb/rom-couchdb)
Experimental CouchDB support for ROM. Uses [couchrest](https://github.com/couchrest/couchrest) as the connection adapter.
## Installing
Add `gem 'rom-couchdb'` to your Gemfile.
## Example
```ruby
class Color
attr_reader :name, :code, :id, :revdef initialize(attributes)
puts attributes
@name, @code, @id, @rev = attributes.values_at(:name, :code, :id, :rev)
end
endROM.setup(:couchdb, 'testdb')
class Colors < ROM::Relation[:couchdb]
def find_id(id)
find_by_id(id)
enddef find_view(name, params)
find_by_view(name, params)
end
endclass ColorMapper < ROM::Mapper
relation :colors
register_as :entitymodel Color
attribute :id, from: :'_id'
attribute :rev, from: :'_rev'
attribute :name
attribute :code
endclass CreateColor < ROM::Commands::Create[:couchdb]
register_as :create
relation :colors
result :one
endclass UpdateColor < ROM::Commands::Update[:couchdb]
register_as :update
relation :colors
result :one
endrom = ROM.finalize.env
color_commands = rom.command(:colors)
color_relations = rom.relation(:colors)color = color_commands.as(:entity).create.call(name: "Red", code: 8)
update = color_commands.as(:entity).create.call(name: "Blue", code: 9, _id: color.id, _rev: color.rev)find = color_relations.as(:entity).find_id(color.id).one
all_docs = color_relations.find_view('_all_docs', {})
```