Module: Adapter::Cassanity
- Extended by:
- Forwardable
- Defined in:
- lib/adapter/cassanity.rb,
lib/adapter/cassanity/version.rb
Constant Summary collapse
- VERSION =
"0.1.0"
Instance Method Summary collapse
- #clear ⇒ Object
- #delete(key) ⇒ Object
- #read(key) ⇒ Object
-
#where(criteria) ⇒ Object
Private.
- #write(key, attributes) ⇒ Object
Instance Method Details
#clear ⇒ Object
27 28 29 |
# File 'lib/adapter/cassanity.rb', line 27 def clear client.truncate end |
#delete(key) ⇒ Object
23 24 25 |
# File 'lib/adapter/cassanity.rb', line 23 def delete(key) client.delete(where: where(key)) end |
#read(key) ⇒ Object
11 12 13 14 |
# File 'lib/adapter/cassanity.rb', line 11 def read(key) rows = client.select(where: where(key)) rows.empty? ? nil : decode(rows.first) end |
#where(criteria) ⇒ Object
Private
32 33 34 35 36 37 38 39 |
# File 'lib/adapter/cassanity.rb', line 32 def where(criteria) if schema.composite_primary_key? criteria else primary_key = schema.primary_keys.first {primary_key => criteria} end end |
#write(key, attributes) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/adapter/cassanity.rb', line 16 def write(key, attributes) client.update({ set: encode(attributes), where: where(key), }) end |