Class: CassandraCQL::Result
- Inherits:
-
Object
- Object
- CassandraCQL::Result
show all
- Defined in:
- lib/cassandra-cql/result.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(result) ⇒ Result
Returns a new instance of Result.
42
43
44
45
46
|
# File 'lib/cassandra-cql/result.rb', line 42
def initialize(result)
@result = result
@schema = ResultSchema.new(result.schema) if rows?
@cursor = 0
end
|
Instance Attribute Details
#cursor ⇒ Object
Returns the value of attribute cursor.
40
41
42
|
# File 'lib/cassandra-cql/result.rb', line 40
def cursor
@cursor
end
|
#result ⇒ Object
Returns the value of attribute result.
40
41
42
|
# File 'lib/cassandra-cql/result.rb', line 40
def result
@result
end
|
#schema ⇒ Object
Returns the value of attribute schema.
40
41
42
|
# File 'lib/cassandra-cql/result.rb', line 40
def schema
@schema
end
|
Instance Method Details
#fetch ⇒ Object
87
88
89
90
91
92
93
94
95
|
# File 'lib/cassandra-cql/result.rb', line 87
def fetch
if block_given?
while row = fetch_row
yield row
end
else
fetch_row
end
end
|
#fetch_array ⇒ Object
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
# File 'lib/cassandra-cql/result.rb', line 115
def fetch_array
if block_given?
while row = fetch_row
if row.kind_of?(Fixnum)
yield [row]
else
yield row.to_a
end
end
else
if (row = fetch_row).kind_of?(Fixnum)
[row]
else
row.to_a
end
end
end
|
#fetch_hash ⇒ Object
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
# File 'lib/cassandra-cql/result.rb', line 97
def fetch_hash
if block_given?
while row = fetch_row
if row.kind_of?(Fixnum)
yield({row => row})
else
yield row.to_hash
end
end
else
if (row = fetch_row).kind_of?(Fixnum)
{row => row}
else
row.to_hash
end
end
end
|
#fetch_row ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/cassandra-cql/result.rb', line 70
def fetch_row
case @result.type
when CassandraCQL::Thrift::CqlResultType::ROWS
return nil if @cursor >= rows
row = Row.new(@result.rows[@cursor], @schema)
@cursor += 1
return row
when CassandraCQL::Thrift::CqlResultType::VOID
return nil
when CassandraCQL::Thrift::CqlResultType::INT
return @result.num
else
raise Error::InvalidResultType, "Expects one of 0, 1, 2; was #{@result.type} "
end
end
|
#int? ⇒ Boolean
52
53
54
|
# File 'lib/cassandra-cql/result.rb', line 52
def int?
@result.type == CassandraCQL::Thrift::CqlResultType::INT
end
|
#rows ⇒ Object
60
61
62
|
# File 'lib/cassandra-cql/result.rb', line 60
def rows
@result.rows.size
end
|
#rows? ⇒ Boolean
56
57
58
|
# File 'lib/cassandra-cql/result.rb', line 56
def rows?
@result.type == CassandraCQL::Thrift::CqlResultType::ROWS
end
|
#void? ⇒ Boolean
48
49
50
|
# File 'lib/cassandra-cql/result.rb', line 48
def void?
@result.type == CassandraCQL::Thrift::CqlResultType::VOID
end
|