Class: RAWS::SDB::Select
- Inherits:
-
Object
- Object
- RAWS::SDB::Select
- Includes:
- Enumerable
- Defined in:
- lib/raws/sdb/select.rb
Direct Known Subclasses
Constant Summary collapse
- RESERVED_KEYWORD =
%w'or and not from where select like null is order by asc desc in between intersection limit every'
Instance Method Summary collapse
- #attr_filter(val) ⇒ Object
- #columns(*val) ⇒ Object
- #each(&block) ⇒ Object (also: #fetch)
- #from(val) ⇒ Object
- #get ⇒ Object
-
#initialize ⇒ Select
constructor
A new instance of Select.
- #limit(val) ⇒ Object
- #order(val) ⇒ Object
- #to_sql ⇒ Object
- #where(condition, *values) ⇒ Object (also: #filter)
Constructor Details
#initialize ⇒ Select
Returns a new instance of Select.
6 7 8 9 10 11 12 13 |
# File 'lib/raws/sdb/select.rb', line 6 def initialize @output_list = '*' @domain = nil @condition = nil @values = nil @sort = nil @limit = nil end |
Instance Method Details
#attr_filter(val) ⇒ Object
15 16 17 |
# File 'lib/raws/sdb/select.rb', line 15 def attr_filter(val) val end |
#columns(*val) ⇒ Object
39 40 41 42 |
# File 'lib/raws/sdb/select.rb', line 39 def columns(*val) @output_list = val.join(',') self end |
#each(&block) ⇒ Object Also known as: fetch
19 20 21 22 23 |
# File 'lib/raws/sdb/select.rb', line 19 def each(&block) RAWS::SDB.select(*to_sql) do |val| block.call(attr_filter(val)) end end |
#from(val) ⇒ Object
44 45 46 47 |
# File 'lib/raws/sdb/select.rb', line 44 def from(val) @domain = val self end |
#get ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/raws/sdb/select.rb', line 26 def get ret = nil _limit = @limit limit(1) each do |val| ret = val end @limit = _limit ret end |
#limit(val) ⇒ Object
61 62 63 64 |
# File 'lib/raws/sdb/select.rb', line 61 def limit(val) @limit = val self end |
#order(val) ⇒ Object
56 57 58 59 |
# File 'lib/raws/sdb/select.rb', line 56 def order(val) @sort = val self end |
#to_sql ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/raws/sdb/select.rb', line 66 def to_sql s = [ 'select', @output_list, 'from', "`#{::RAWS::SDB::Adapter.quote(@domain)}`" ] s.push('where', @condition) if @condition s.push('order by', @sort ) if @sort s.push('limit', @limit ) if @limit [s.join(' '), @values] end |
#where(condition, *values) ⇒ Object Also known as: filter
49 50 51 52 53 |
# File 'lib/raws/sdb/select.rb', line 49 def where(condition, *values) @condition = condition @values = values self end |