Class: YqlQuery::Builder
- Inherits:
-
Object
- Object
- YqlQuery::Builder
- Defined in:
- lib/yql_query/builder.rb
Overview
The primary query builder class, wraps a Query object and provides methods to assign query arguments.
Instance Attribute Summary collapse
-
#query ⇒ Object
Returns the value of attribute query.
Instance Method Summary collapse
-
#conditions(conditions) ⇒ YqlQuery::Builder
(also: #where)
Assigns additional datatable sources for use with the query being constructed.
-
#initialize(options = {}) ⇒ Builder
constructor
Instantiates a new Builder instance.
-
#limit(limit) ⇒ YqlQuery::Builder
Assigns the limit for the query being constructed.
-
#offset(offset) ⇒ YqlQuery::Builder
Assigns the offset for the query being constructed.
-
#remote(remote_limit, remote_offset = 0) ⇒ YqlQuery::Builder
Assigns the remote limit for the query being constructed.
-
#reset ⇒ Object
Resets all arguments to the query.
-
#reverse ⇒ YqlQuery::Builder
Adds the reverse filter to the query being constructed.
-
#sanitize(sanitize = true) ⇒ YqlQuery::Builder
Assigns the sanitize argument for the query being constructed.
-
#select(select) ⇒ YqlQuery::Builder
Assigns the columns to select for the query being constructed.
-
#sort(sort) ⇒ YqlQuery::Builder
Assigns the field to be sorted for the query being constructed.
-
#sort_descending(sort) ⇒ YqlQuery::Builder
Assigns the field to be sorted for the query being constructed.
-
#table(table) ⇒ YqlQuery::Builder
Assigns the table for the query being constructed.
-
#tail(tail) ⇒ YqlQuery::Builder
Assigns the tail argument for the query being constructed.
-
#to_s ⇒ Object
(also: #to_query)
Returns the generated YQL query based on the arguments provided.
-
#truncate(truncate) ⇒ YqlQuery::Builder
Assigns the truncate argument for the query being constructed.
-
#unique(unique) ⇒ YqlQuery::Builder
Assigns the unique argument for the query being constructed.
-
#use(source, as) ⇒ YqlQuery::Builder
Assigns additional datatable sources for use with the query being constructed.
Constructor Details
#initialize(options = {}) ⇒ Builder
Instantiates a new Builder instance.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/yql_query/builder.rb', line 10 def initialize(={}) self.query = Query.new self.query.table = .delete(:table) self.query.limit = .delete(:limit) self.query.offset = .delete(:offset) self.query.select = .delete(:select) self.query.conditions = .delete(:conditions) || [] self.query.uses = .delete(:uses) || [] self.query.tail = .delete(:tail) self.query.truncate = .delete(:truncate) self.query.reverse = .delete(:reverse) self.query.unique = .delete(:unique) self.query.sanitize = .delete(:sanitize) self.query.remote_limit = .delete(:remote_limit) self.query.remote_offset = .delete(:remote_offset) end |
Instance Attribute Details
#query ⇒ Object
Returns the value of attribute query.
6 7 8 |
# File 'lib/yql_query/builder.rb', line 6 def query @query end |
Instance Method Details
#conditions(conditions) ⇒ YqlQuery::Builder Also known as: where
Assigns additional datatable sources for use with the query being constructed. Conditions are combined. Hashes assume equivalency when generating queries, except when passed a YqlQuery::Builder instance in which case a sub-select is assumed using an ‘in’.
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/yql_query/builder.rb', line 132 def conditions(conditions) if conditions.kind_of?(String) self.query.conditions << conditions elsif conditions.kind_of?(Array) self.query.conditions += conditions elsif conditions.kind_of?(Hash) conditions.each do |key, value| if value.kind_of?(YqlQuery::Builder) self.query.conditions << "#{key} in (#{value})" else self.query.conditions << "#{key} = '#{value}'" end end end self end |
#limit(limit) ⇒ YqlQuery::Builder
Assigns the limit for the query being constructed
44 45 46 47 |
# File 'lib/yql_query/builder.rb', line 44 def limit(limit) self.query.limit = limit self end |
#offset(offset) ⇒ YqlQuery::Builder
Assigns the offset for the query being constructed
57 58 59 60 |
# File 'lib/yql_query/builder.rb', line 57 def offset(offset) self.query.offset = offset self end |
#remote(remote_limit, remote_offset = 0) ⇒ YqlQuery::Builder
Assigns the remote limit for the query being constructed
71 72 73 74 75 |
# File 'lib/yql_query/builder.rb', line 71 def remote(remote_limit, remote_offset=0) self.query.remote_limit = remote_limit self.query.remote_offset = remote_offset self end |
#reset ⇒ Object
Resets all arguments to the query
256 257 258 |
# File 'lib/yql_query/builder.rb', line 256 def reset self.query = Query.new end |
#reverse ⇒ YqlQuery::Builder
Adds the reverse filter to the query being constructed
212 213 214 215 |
# File 'lib/yql_query/builder.rb', line 212 def reverse self.query.reverse = true self end |
#sanitize(sanitize = true) ⇒ YqlQuery::Builder
Assigns the sanitize argument for the query being constructed
244 245 246 247 |
# File 'lib/yql_query/builder.rb', line 244 def sanitize(sanitize=true) self.query.sanitize = sanitize self end |
#select(select) ⇒ YqlQuery::Builder
Assigns the columns to select for the query being constructed
86 87 88 89 |
# File 'lib/yql_query/builder.rb', line 86 def select(select) self.query.select = select self end |
#sort(sort) ⇒ YqlQuery::Builder
Assigns the field to be sorted for the query being constructed
157 158 159 160 161 |
# File 'lib/yql_query/builder.rb', line 157 def sort(sort) self.query.sort = sort self.query.sort_descending = false self end |
#sort_descending(sort) ⇒ YqlQuery::Builder
Assigns the field to be sorted for the query being constructed
170 171 172 173 174 |
# File 'lib/yql_query/builder.rb', line 170 def sort_descending(sort) self.query.sort = sort self.query.sort_descending = true self end |
#table(table) ⇒ YqlQuery::Builder
Assigns the table for the query being constructed
31 32 33 34 |
# File 'lib/yql_query/builder.rb', line 31 def table(table) self.query.table = table self end |
#tail(tail) ⇒ YqlQuery::Builder
Assigns the tail argument for the query being constructed
184 185 186 187 |
# File 'lib/yql_query/builder.rb', line 184 def tail(tail) self.query.tail = tail self end |
#to_s ⇒ Object Also known as: to_query
Returns the generated YQL query based on the arguments provided
250 251 252 |
# File 'lib/yql_query/builder.rb', line 250 def to_s self.query.to_s end |
#truncate(truncate) ⇒ YqlQuery::Builder
Assigns the truncate argument for the query being constructed
199 200 201 202 |
# File 'lib/yql_query/builder.rb', line 199 def truncate(truncate) self.query.truncate = truncate self end |
#unique(unique) ⇒ YqlQuery::Builder
Assigns the unique argument for the query being constructed
226 227 228 229 |
# File 'lib/yql_query/builder.rb', line 226 def unique(unique) self.query.unique = unique self end |
#use(source, as) ⇒ YqlQuery::Builder
Assigns additional datatable sources for use with the query being constructed
101 102 103 104 |
# File 'lib/yql_query/builder.rb', line 101 def use(source, as) self.query.uses << Source.new(source, as) self end |