Class: CassandraDB::Dataset
- Inherits:
-
Object
- Object
- CassandraDB::Dataset
- Includes:
- Enumerable
- Defined in:
- lib/cassandra_db/dataset.rb
Instance Method Summary collapse
- #all ⇒ Object
- #delete ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(db, table:, conditions: []) ⇒ Dataset
constructor
A new instance of Dataset.
- #insert(attributes) ⇒ Object
- #inspect ⇒ Object
- #update(attributes) ⇒ Object
- #where(filters) ⇒ Object
Constructor Details
#initialize(db, table:, conditions: []) ⇒ Dataset
Returns a new instance of Dataset.
6 7 8 9 10 |
# File 'lib/cassandra_db/dataset.rb', line 6 def initialize(db, table:, conditions:[]) @db = db @table = table @conditions = conditions end |
Instance Method Details
#all ⇒ Object
24 25 26 27 28 |
# File 'lib/cassandra_db/dataset.rb', line 24 def all statement = Statements::Select.new table: table, conditions: conditions result = db.execute statement.cql, statement. result.to_a end |
#delete ⇒ Object
40 41 42 43 |
# File 'lib/cassandra_db/dataset.rb', line 40 def delete statement = Statements::Delete.new table: table, conditions: conditions db.execute statement.cql, statement. end |
#each(&block) ⇒ Object
20 21 22 |
# File 'lib/cassandra_db/dataset.rb', line 20 def each(&block) all.each(&block) end |
#insert(attributes) ⇒ Object
30 31 32 33 |
# File 'lib/cassandra_db/dataset.rb', line 30 def insert(attributes) statement = Statements::Insert.new table: table, attributes: attributes db.execute statement.cql, statement. end |
#inspect ⇒ Object
45 46 47 48 |
# File 'lib/cassandra_db/dataset.rb', line 45 def inspect statement = Statements::Select.new table: table, conditions: conditions "#<#{self.class.name}: #{statement.to_s}>" end |
#update(attributes) ⇒ Object
35 36 37 38 |
# File 'lib/cassandra_db/dataset.rb', line 35 def update(attributes) statement = Statements::Update.new table: table, attributes: attributes, conditions: conditions db.execute statement.cql, statement. end |
#where(filters) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/cassandra_db/dataset.rb', line 12 def where(filters) new_conditions = filters.map do |field, value| QueryCondition.new field, value end Dataset.new db, table: table, conditions: conditions + new_conditions end |