simplydb 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/examples/record.rb +22 -15
- data/lib/simplydb/record.rb +2 -0
- data/lib/simplydb/record/base.rb +32 -7
- data/simplydb.gemspec +3 -2
- data/spec/record/base_spec.rb +28 -12
- data/spec/spec_helper.rb +1 -1
- metadata +5 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/examples/record.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
2
|
+
|
2
3
|
require 'simplydb'
|
3
4
|
require 'simplydb/record/base'
|
4
5
|
|
@@ -9,30 +10,36 @@ SimplyDB::Record::Base.establish_connection({
|
|
9
10
|
|
10
11
|
class MyDomain < SimplyDB::Record::Base; end
|
11
12
|
|
12
|
-
MyDomain.create_domain
|
13
13
|
|
14
|
+
puts "=== Domain info ==="
|
15
|
+
puts "create domain: #{MyDomain.create_domain}"
|
14
16
|
puts "domain name: #{MyDomain.domain_name}"
|
15
|
-
puts "
|
17
|
+
puts "domain_exists?: #{MyDomain.domain_exists?}"
|
18
|
+
|
16
19
|
|
17
|
-
|
18
|
-
|
20
|
+
puts "\n"
|
21
|
+
puts "=== Record info ==="
|
22
|
+
|
23
|
+
person = MyDomain.new(
|
24
|
+
:name => 'Joe Smith',
|
19
25
|
:age => 27
|
20
26
|
)
|
21
|
-
puts "attribues: #{model.attributes.inspect}"
|
22
|
-
model[:age] = 29
|
23
|
-
puts "attribues: #{model.attributes.inspect}"
|
24
27
|
|
25
|
-
|
28
|
+
person[:age] = 29
|
29
|
+
|
30
|
+
puts "person attributes: #{person.attribute_names.inspect}"
|
31
|
+
puts "person attributes hash: #{person.attributes.inspect}"
|
26
32
|
|
27
|
-
|
28
|
-
puts "save: #{
|
33
|
+
person.item_name = "person1"
|
34
|
+
puts "save: #{person.save}"
|
35
|
+
puts "id (item_name): #{person.item_name}"
|
29
36
|
|
30
37
|
sleep 2 #let SimpleDB propogate data (not supporting consistant read, yet)
|
31
38
|
|
32
|
-
|
33
|
-
puts "
|
39
|
+
found_person = MyDomain.find("person1")
|
40
|
+
puts "found person attributes: #{found_person.attributes.inspect}"
|
34
41
|
|
35
|
-
|
36
|
-
puts "
|
42
|
+
people = MyDomain.find_by_select('SELECT * FROM my_domain')
|
43
|
+
puts "people: #{people.inspect}"
|
37
44
|
|
38
|
-
|
45
|
+
MyDomain.delete_domain
|
data/lib/simplydb/record/base.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'simplydb'
|
2
1
|
require 'simplydb/extensions'
|
3
2
|
require 'uuidtools'
|
4
3
|
|
@@ -6,6 +5,7 @@ module SimplyDB
|
|
6
5
|
module Record
|
7
6
|
class MissingItemName < RuntimeError; end
|
8
7
|
class ItemNotFound < RuntimeError; end
|
8
|
+
class MissingCredentials < RuntimeError; end
|
9
9
|
|
10
10
|
class Base
|
11
11
|
include SimplyDB::Extensions
|
@@ -15,21 +15,31 @@ module SimplyDB
|
|
15
15
|
|
16
16
|
# This setups up the parameters for the connection for SimpleDB.
|
17
17
|
#
|
18
|
+
# NOTE: connection settings default to parent's settings if not provided
|
18
19
|
# ==== Parameters
|
19
20
|
# +access_key+: AWS access key.
|
20
21
|
# +secret_key+: AWS secret key.
|
21
22
|
# +force+: Force the creation of the domain. (Not yet implemented)
|
22
23
|
def establish_connection(options = {})
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
unless options.empty?
|
25
|
+
@connection = {
|
26
|
+
:access_key => options[:aws_access_key] || options[:access_key] || ENV['AWS_ACCESS_KEY'] || ENV['ACCESS_KEY'],
|
27
|
+
:secret_key => options[:aws_secret_key] || options[:secret_key] || ENV['AWS_SECRET_KEY'] || ENV['SECRET_KEY'],
|
28
|
+
:force => options[:force] == true ? true : false
|
29
|
+
}
|
30
|
+
else
|
31
|
+
@connection ||= superclass.connection
|
32
|
+
end
|
33
|
+
|
34
|
+
raise MissingCredentials, "Require AWS access key and secret key" if @connection[:access_key].nil? || @connection[:secret_key].nil?
|
28
35
|
end
|
29
36
|
|
30
37
|
# Returns the connection's paramters.
|
31
38
|
attr_accessor :connection
|
32
39
|
|
40
|
+
# access to the logger
|
41
|
+
attr_accessor :logger
|
42
|
+
|
33
43
|
# Returns the interface(+SimplyDB::Interface+) the model uses to communicate with SimpleDB.
|
34
44
|
def interface
|
35
45
|
@interface ||= (establish_connection; SimplyDB::Interface.new(@connection))
|
@@ -104,6 +114,15 @@ module SimplyDB
|
|
104
114
|
end
|
105
115
|
end
|
106
116
|
|
117
|
+
# Find operates with four different retrieval approaches:
|
118
|
+
# * Find by id - This can either be a specific id ("1"), a list of ids ("1", "5", "6"), or an array of ids ([5, 6, 10]). If no record can be found for all of the listed ids, then +ItemNotFound+ will be raised.
|
119
|
+
#
|
120
|
+
# ==== Examples
|
121
|
+
# # find by id
|
122
|
+
# Person.find(1) # returns the object for ID = 1
|
123
|
+
# Person.find(1, 2, 6) # returns an array for objects with IDs in (1, 2, 6)
|
124
|
+
# Person.find([7, 17]) # returns an array for objects with IDs in (7, 17)
|
125
|
+
# Person.find([1]) # returns an array for the object with ID = 1
|
107
126
|
def find(item_names)
|
108
127
|
if item_names.is_a?(Array)
|
109
128
|
return item_names.collect {|item_name| find(item_name)}
|
@@ -120,6 +139,10 @@ module SimplyDB
|
|
120
139
|
end
|
121
140
|
end
|
122
141
|
|
142
|
+
# Executes a custom SELECT query against your domain and returns all the results. The results will
|
143
|
+
# be returned as an array with columns requested encapsulated as attributes of the model you call
|
144
|
+
# this method from. If you call <tt>Product.find_by_sql</tt> then the results will be returned in
|
145
|
+
# a Product object with the attributes you specified in the SQL query.
|
123
146
|
def find_by_select(statement = nil, consistant_read = false)
|
124
147
|
return [] unless statement
|
125
148
|
items = interface.select(statement, consistant_read)
|
@@ -213,7 +236,7 @@ module SimplyDB
|
|
213
236
|
@attributes.frozen?
|
214
237
|
end
|
215
238
|
|
216
|
-
#Deletes the record in the SimpleDB and freezes this instance to reflect that no changes should be made (since they can’t be persisted).
|
239
|
+
# Deletes the record in the SimpleDB and freezes this instance to reflect that no changes should be made (since they can’t be persisted).
|
217
240
|
def destroy
|
218
241
|
unless new_record?
|
219
242
|
interface.delete_attributes(domain_name, item_name)
|
@@ -226,6 +249,7 @@ module SimplyDB
|
|
226
249
|
def connection; return self.class.connection; end
|
227
250
|
def interface; return self.class.interface; end
|
228
251
|
def domain_name; return self.class.domain_name; end
|
252
|
+
def logger; self.class.logger; end
|
229
253
|
|
230
254
|
def method_missing(method, *args) #:nodoc:
|
231
255
|
method = method.to_s
|
@@ -238,6 +262,7 @@ module SimplyDB
|
|
238
262
|
raise NoMethodError.new("Could not find method #{method}", method, *args)
|
239
263
|
end
|
240
264
|
|
265
|
+
# The item name associated with the record. This is the SimpleDB item name.
|
241
266
|
def item_name=(value)
|
242
267
|
@item_name = value.to_s
|
243
268
|
end
|
data/simplydb.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{simplydb}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["JT Archie"]
|
12
|
-
s.date = %q{2010-06
|
12
|
+
s.date = %q{2010-07-06}
|
13
13
|
s.description = %q{A minimal interface to Amazon SimpleDB that has separation of interfaces. From the low level HTTP request access to high level Ruby abstraction ORM.}
|
14
14
|
s.email = %q{jtarchie@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -31,6 +31,7 @@ Gem::Specification.new do |s|
|
|
31
31
|
"lib/simplydb/error.rb",
|
32
32
|
"lib/simplydb/extensions.rb",
|
33
33
|
"lib/simplydb/interface.rb",
|
34
|
+
"lib/simplydb/record.rb",
|
34
35
|
"lib/simplydb/record/base.rb",
|
35
36
|
"simplydb.gemspec",
|
36
37
|
"spec/client_spec.rb",
|
data/spec/record/base_spec.rb
CHANGED
@@ -4,8 +4,9 @@ require 'simplydb/record/base'
|
|
4
4
|
|
5
5
|
describe SimplyDB::Record::Base do
|
6
6
|
before do
|
7
|
+
#need to reset the class each time
|
8
|
+
Object.send(:remove_const, :People) if Object.const_defined?(:People)
|
7
9
|
class People < SimplyDB::Record::Base; end
|
8
|
-
People.set_domain_name(nil) #have to reset the domain name each time
|
9
10
|
|
10
11
|
@attributes = {
|
11
12
|
'name' => 'Joe Smith',
|
@@ -13,17 +14,32 @@ describe SimplyDB::Record::Base do
|
|
13
14
|
}
|
14
15
|
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
17
|
+
describe "setting connection credentials" do
|
18
|
+
it "should be able to set connection credentials" do
|
19
|
+
People.establish_connection({
|
20
|
+
:access_key => access_key,
|
21
|
+
:secret_key => secret_key,
|
22
|
+
:force => false
|
23
|
+
})
|
24
|
+
People.connection.should == {
|
25
|
+
:access_key => access_key,
|
26
|
+
:secret_key => secret_key,
|
27
|
+
:force => false
|
28
|
+
}
|
29
|
+
end
|
30
|
+
it "should inherit from its parent" do
|
31
|
+
SimplyDB::Record::Base.establish_connection({
|
32
|
+
:access_key => access_key,
|
33
|
+
:secret_key => secret_key,
|
34
|
+
:force => true
|
35
|
+
})
|
36
|
+
People.establish_connection
|
37
|
+
People.connection.should == {
|
38
|
+
:access_key => access_key,
|
39
|
+
:secret_key => secret_key,
|
40
|
+
:force => true
|
41
|
+
}
|
42
|
+
end
|
27
43
|
end
|
28
44
|
|
29
45
|
describe "domain specific functions" do
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simplydb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- JT Archie
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-06
|
18
|
+
date: 2010-07-06 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -106,6 +106,7 @@ files:
|
|
106
106
|
- lib/simplydb/error.rb
|
107
107
|
- lib/simplydb/extensions.rb
|
108
108
|
- lib/simplydb/interface.rb
|
109
|
+
- lib/simplydb/record.rb
|
109
110
|
- lib/simplydb/record/base.rb
|
110
111
|
- simplydb.gemspec
|
111
112
|
- spec/client_spec.rb
|