Class: CassandraCQL::Result
- Inherits:
-
Object
- Object
- CassandraCQL::Result
show all
- Includes:
- Enumerable
- 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.
44
45
46
47
48
|
# File 'lib/cassandra-cql/result.rb', line 44
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.
42
43
44
|
# File 'lib/cassandra-cql/result.rb', line 42
def cursor
@cursor
end
|
#result ⇒ Object
Returns the value of attribute result.
42
43
44
|
# File 'lib/cassandra-cql/result.rb', line 42
def result
@result
end
|
#schema ⇒ Object
Returns the value of attribute schema.
42
43
44
|
# File 'lib/cassandra-cql/result.rb', line 42
def schema
@schema
end
|
Instance Method Details
#each ⇒ Object
76
77
78
|
# File 'lib/cassandra-cql/result.rb', line 76
def each
fetch { |row| yield row }
end
|
#fetch ⇒ Object
97
98
99
100
101
102
103
104
105
|
# File 'lib/cassandra-cql/result.rb', line 97
def fetch
if block_given?
while row = fetch_row
yield row
end
else
fetch_row
end
end
|
#fetch_array ⇒ Object
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
# File 'lib/cassandra-cql/result.rb', line 127
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
# File 'lib/cassandra-cql/result.rb', line 107
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
if row.kind_of?(Fixnum)
{row => row}
else
row.to_hash
end
end
end
end
|
#fetch_row ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/cassandra-cql/result.rb', line 80
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
54
55
56
|
# File 'lib/cassandra-cql/result.rb', line 54
def int?
@result.type == CassandraCQL::Thrift::CqlResultType::INT
end
|
#rows ⇒ Object
Also known as:
size, count, length
62
63
64
|
# File 'lib/cassandra-cql/result.rb', line 62
def rows
@result.rows.size
end
|
#rows? ⇒ Boolean
58
59
60
|
# File 'lib/cassandra-cql/result.rb', line 58
def rows?
@result.type == CassandraCQL::Thrift::CqlResultType::ROWS
end
|
#void? ⇒ Boolean
50
51
52
|
# File 'lib/cassandra-cql/result.rb', line 50
def void?
@result.type == CassandraCQL::Thrift::CqlResultType::VOID
end
|