dm-riak-adapter 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +12 -6
- data/lib/dm-riak-adapter/adapter.rb +71 -1
- metadata +5 -5
data/README.md
CHANGED
@@ -12,17 +12,17 @@ Install the **dm-riak-adapter** gem:
|
|
12
12
|
|
13
13
|
gem install dm-riak-adapter
|
14
14
|
|
15
|
-
##
|
15
|
+
## Synopsis
|
16
16
|
|
17
|
-
Require **dm-core** and **dm-riak-adapter**. Tell DataMapper to use the Riak adapter and set a namespace for your app. This namespace will prefix each bucket like `myapp:projects` `myapp:tasks`.
|
17
|
+
Require **dm-core** and **dm-riak-adapter**. Tell DataMapper to use the Riak adapter and set a namespace for your app. This namespace will prefix each bucket like `myapp:projects` `myapp:tasks`. Skip setting a namespace and the buckets will have no prefix.
|
18
18
|
|
19
19
|
require 'dm-core'
|
20
20
|
require 'dm-riak-adapter'
|
21
21
|
|
22
22
|
DataMapper.setup :default, :adapter => 'riak', :namespace => 'myapp'
|
23
|
-
|
24
|
-
Continue
|
25
|
-
|
23
|
+
|
24
|
+
Continue defining your models and properties as you normally would. Set a property as type `Key` to use Riak's server-assigned UUIDs.
|
25
|
+
|
26
26
|
class Project
|
27
27
|
include DataMapper::Resource
|
28
28
|
|
@@ -39,4 +39,10 @@ Continue Defining your models and properties as you normally would. Set the seri
|
|
39
39
|
property :summary, String
|
40
40
|
|
41
41
|
belongs_to :project
|
42
|
-
end
|
42
|
+
end
|
43
|
+
|
44
|
+
## Resources
|
45
|
+
|
46
|
+
- [Documentation](http://yardoc.org/docs/mikeric-dm-riak-adapter/DataMapper/Adapters/RiakAdapter)
|
47
|
+
- [Metrics](http://getcaliper.com/caliper/project?repo=http://rubygems.org/gems/dm-riak-adapter)
|
48
|
+
- [Gems](http://rubygems.org/gems/dm-riak-adapter)
|
@@ -1,15 +1,52 @@
|
|
1
1
|
module DataMapper::Adapters
|
2
2
|
class RiakAdapter < AbstractAdapter
|
3
|
+
# Initializes a new RiakAdapter instance
|
4
|
+
#
|
5
|
+
# @param [String, Symbol] name
|
6
|
+
# Repository name
|
7
|
+
#
|
8
|
+
# @param [Hash] options
|
9
|
+
# Configuration options
|
10
|
+
#
|
11
|
+
# @option options [String] :host ('127.0.0.1') Server hostname
|
12
|
+
# @option options [Integer] :port (8098) Server port
|
13
|
+
# @option options [String] :prefix ('riak') Path prefix to the HTTP endpoint
|
14
|
+
# @option options [String] :namespace ('') Bucket namespace
|
3
15
|
def initialize(name, options)
|
4
16
|
super
|
5
|
-
|
17
|
+
|
18
|
+
@riak = Riak::Client.new(
|
19
|
+
:host => options[:host],
|
20
|
+
:port => options[:port],
|
21
|
+
:prefix => options[:prefix]
|
22
|
+
)
|
6
23
|
@namespace = options[:namespace] ? options[:namespace] + ':' : ''
|
7
24
|
end
|
8
25
|
|
26
|
+
# Persists one or many new resources
|
27
|
+
#
|
28
|
+
# @example
|
29
|
+
# adapter.create(collection) # => 1
|
30
|
+
#
|
31
|
+
# @param [Enumerable<Resource>] resources
|
32
|
+
# List of resources (model instances) to create
|
33
|
+
#
|
34
|
+
# @return [Integer]
|
35
|
+
# Number of objects created
|
9
36
|
def create(resources)
|
10
37
|
create_objects(resources)
|
11
38
|
end
|
12
39
|
|
40
|
+
# Reads one or many resources from a datastore
|
41
|
+
#
|
42
|
+
# @example
|
43
|
+
# adapter.read(query) # => [{'title' => 'Lorem Ipsum'}]
|
44
|
+
#
|
45
|
+
# @param [Query] query
|
46
|
+
# Query to match objects in the datastore
|
47
|
+
#
|
48
|
+
# @return [Enumerable<Hash>]
|
49
|
+
# Array of hashes to become resources
|
13
50
|
def read(query)
|
14
51
|
query.filter_records(objects_for(query.model)).each do |object|
|
15
52
|
query.fields.each do |property|
|
@@ -18,6 +55,19 @@ module DataMapper::Adapters
|
|
18
55
|
end
|
19
56
|
end
|
20
57
|
|
58
|
+
# Updates one or many existing resources
|
59
|
+
#
|
60
|
+
# @example
|
61
|
+
# adapter.update(attributes, collection) # => 1
|
62
|
+
#
|
63
|
+
# @param [Hash(Property => Object)] attributes
|
64
|
+
# Hash of attribute values to set, keyed by Property
|
65
|
+
#
|
66
|
+
# @param [Collection] collection
|
67
|
+
# Collection of records to be updated
|
68
|
+
#
|
69
|
+
# @return [Integer]
|
70
|
+
# Number of records updated
|
21
71
|
def update(attributes, collection)
|
22
72
|
attributes = attributes_as_fields(attributes)
|
23
73
|
|
@@ -25,10 +75,30 @@ module DataMapper::Adapters
|
|
25
75
|
update_objects(collection)
|
26
76
|
end
|
27
77
|
|
78
|
+
# Deletes one or many existing resources
|
79
|
+
#
|
80
|
+
# @example
|
81
|
+
# adapter.delete(collection) # => 1
|
82
|
+
#
|
83
|
+
# @param [Collection] collection
|
84
|
+
# Collection of records to be deleted
|
85
|
+
#
|
86
|
+
# @return [Integer]
|
87
|
+
# Number of records deleted
|
28
88
|
def delete(collection)
|
29
89
|
delete_objects(collection)
|
30
90
|
end
|
31
91
|
|
92
|
+
# Flushes the bucket for the specified model
|
93
|
+
#
|
94
|
+
# @example
|
95
|
+
# adapter.flush(Post) # => ["6moGsRVfutpG4wzibgwDBKc37Dd"]
|
96
|
+
#
|
97
|
+
# @param [Class] model
|
98
|
+
# Model to flush
|
99
|
+
#
|
100
|
+
# @return [Array<String>]
|
101
|
+
# Keys of the flushed objects
|
32
102
|
def flush(model)
|
33
103
|
bucket(model).keys.each {|key| bucket(model)[key].delete}
|
34
104
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 4
|
9
|
+
version: 0.0.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Mike Richards
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-04-06 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: "0"
|
44
44
|
type: :runtime
|
45
45
|
version_requirements: *id002
|
46
|
-
description: DataMapper
|
46
|
+
description: DataMapper Adapter for Riak
|
47
47
|
email: mike22e@gmail.com
|
48
48
|
executables: []
|
49
49
|
|
@@ -87,7 +87,7 @@ rubyforge_project:
|
|
87
87
|
rubygems_version: 1.3.6
|
88
88
|
signing_key:
|
89
89
|
specification_version: 2
|
90
|
-
summary: DataMapper
|
90
|
+
summary: DataMapper Adapter for Riak
|
91
91
|
test_files:
|
92
92
|
- spec/dm-riak-adapter_spec.rb
|
93
93
|
- spec/spec_helper.rb
|