Class: SimplerDB::DB
Overview
The main SimplerDB class, containing methods that correspond to the AWS API.
Instance Method Summary collapse
- #create_domain(name) ⇒ Object
- #delete_attributes(domain_name, item_name, attributes) ⇒ Object
- #delete_domain(name) ⇒ Object
- #get_attributes(domain_name, item_name, attribute_name = nil) ⇒ Object
-
#initialize ⇒ DB
constructor
A new instance of DB.
- #list_domains(max = 100, token = 0) ⇒ Object
- #put_attributes(domain_name, item_name, attribute_params) ⇒ Object
- #query(domain, query, max = 100, token = 0) ⇒ Object
-
#reset ⇒ Object
For testing.
Constructor Details
#initialize ⇒ DB
Returns a new instance of DB.
84 85 86 |
# File 'lib/simplerdb/db.rb', line 84 def initialize reset end |
Instance Method Details
#create_domain(name) ⇒ Object
94 95 96 |
# File 'lib/simplerdb/db.rb', line 94 def create_domain(name) @domains[name] ||= Domain.new(name) end |
#delete_attributes(domain_name, item_name, attributes) ⇒ Object
131 132 133 134 135 |
# File 'lib/simplerdb/db.rb', line 131 def delete_attributes(domain_name, item_name, attributes) domain = @domains[domain_name] item = domain.items[item_name] attributes.each { |attr| item.delete_attribute(attr) } end |
#delete_domain(name) ⇒ Object
98 99 100 |
# File 'lib/simplerdb/db.rb', line 98 def delete_domain(name) @domains.delete(name) end |
#get_attributes(domain_name, item_name, attribute_name = nil) ⇒ Object
119 120 121 122 123 |
# File 'lib/simplerdb/db.rb', line 119 def get_attributes(domain_name, item_name, attribute_name = nil) domain = @domains[domain_name] item = domain.items[item_name] return item.get_attributes(attribute_name) end |
#list_domains(max = 100, token = 0) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/simplerdb/db.rb', line 102 def list_domains(max = 100, token = 0) doms = [] count = 0 token = 0 unless token @domains.keys.each do |domain| break if doms.size == max doms << domain if count >= token.to_i count += 1 end if (count >= @domains.size) return doms,nil else return doms,count end end |
#put_attributes(domain_name, item_name, attribute_params) ⇒ Object
125 126 127 128 129 |
# File 'lib/simplerdb/db.rb', line 125 def put_attributes(domain_name, item_name, attribute_params) domain = @domains[domain_name] item = domain.items[item_name] attribute_params.each { |attr| item.put_attribute(attr.to_attr, attr.replace) } end |
#query(domain, query, max = 100, token = 0) ⇒ Object
137 138 139 |
# File 'lib/simplerdb/db.rb', line 137 def query(domain, query, max = 100, token = 0) @query_executor.do_query(query, @domains[domain], max, token) end |
#reset ⇒ Object
For testing
89 90 91 92 |
# File 'lib/simplerdb/db.rb', line 89 def reset @domains = {} @query_executor = QueryExecutor.new end |