module Ronin::SQL::Clauses
Methods for creating common SQL
{Clause Clauses}.
@api public
Public Instance Methods
Appends an arbitrary clause.
@param [Symbol] keyword
The name of the clause.
@param [Object] argument
Additional argument for the clause.
@yield [(clause)]
If a block is given, the return value will be used as the argument.
@yieldparam [Clause] clause
If the block accepts an argument, it will be passed the new clause. Otherwise the block will be evaluated within the clause.
@return [self]
# File lib/ronin/sql/clauses.rb, line 59 def clause(keyword,argument=nil,&block) clauses << Clause.new(keyword,argument,&block) return self end
The defined clauses of the statement.
@return [Array<Clause>]
The clauses defined thus far.
# File lib/ronin/sql/clauses.rb, line 37 def clauses @clauses ||= [] end
Appends a ‘DEFAULT VALUES` clause.
@return [self]
# File lib/ronin/sql/clauses.rb, line 272 def default_values clause([:DEFAULT, :VALUES]) end
Appends a ‘FROM` clause.
@param [Field, Symbol] table
The table to select from.
@return [self]
# File lib/ronin/sql/clauses.rb, line 72 def from(table=nil,&block) clause(:FROM,table,&block) end
Appends a ‘FULL JOIN` clause.
@param [Field, Symbol] table
The table to join.
@return [self]
# File lib/ronin/sql/clauses.rb, line 153 def full_join(table=nil,&block) clause([:FULL, :JOIN],table,&block) end
Appends a ‘GROUP BY` clause.
@param [Array<Field, Symbol>] columns
The columns for `GROUP BY`.
@return [self]
# File lib/ronin/sql/clauses.rb, line 194 def group_by(*columns,&block) clause([:GROUP, :BY],columns,&block) end
Appends a ‘HAVING` clause.
@return [self]
# File lib/ronin/sql/clauses.rb, line 203 def having(&block) clause(:HAVING,&block) end
Appends a ‘INDEXED BY` clause.
@param [Field, Symbol] name
The name of the index.
@return [self]
# File lib/ronin/sql/clauses.rb, line 296 def indexed_by(name,&block) clause([:INDEXED, :BY],name,&block) end
Appends a ‘INNER JOIN` clause.
@param [Field, Symbol] table
The table to join.
@return [self]
# File lib/ronin/sql/clauses.rb, line 117 def inner_join(table=nil,&block) clause([:INNER, :JOIN],table,&block) end
Appends an ‘INTO` clause.
@param [Field, Symbol] table
The table to insert into.
@return [self]
# File lib/ronin/sql/clauses.rb, line 84 def into(table=nil,&block) clause(:INTO,table,&block) end
Appends a ‘JOIN` clause.
@param [Field, Symbol] table
The table to join.
@return [self]
# File lib/ronin/sql/clauses.rb, line 105 def join(table=nil,&block) clause(:JOIN,table,&block) end
Appends a ‘LEFT JOIN` clause.
@param [Field, Symbol] table
The table to join.
@return [self]
# File lib/ronin/sql/clauses.rb, line 129 def left_join(table=nil,&block) clause([:LEFT, :JOIN],table,&block) end
Appends a ‘LIMIT` clause.
@param [Integer] value
The maximum number of rows to select.
@return [self]
# File lib/ronin/sql/clauses.rb, line 215 def limit(value,&block) clause(:LIMIT,value,&block) end
Appends a ‘NOT INDEXED` clause.
@return [self]
# File lib/ronin/sql/clauses.rb, line 305 def not_indexed clause([:NOT, :INDEXED]) end
Appends a ‘OFFSET` clause.
@param [Integer] value
The index to start selecting at within the result set.
@return [self]
# File lib/ronin/sql/clauses.rb, line 227 def offset(value,&block) clause(:OFFSET,value,&block) end
Appends a ‘ON` clause.
@return [self]
# File lib/ronin/sql/clauses.rb, line 162 def on(&block) clause(:ON,&block) end
Appends a ‘RIGHT JOIN` clause.
@param [Field, Symbol] table
The table to join.
@return [self]
# File lib/ronin/sql/clauses.rb, line 141 def right_join(table=nil,&block) clause([:RIGHT, :JOIN],table,&block) end
Appends a ‘SET` clause.
@param [Hash{Field,Symbol => Object}] values
The columns and values to update.
@return [self]
# File lib/ronin/sql/clauses.rb, line 284 def set(values={}) clause(:SET,values) end
Appends a ‘TOP` clause.
@param [Integer] value
The number of top rows to select.
@return [self]
# File lib/ronin/sql/clauses.rb, line 239 def top(value,&block) clause(:TOP,value,&block) end
Appends a ‘UNION` clause.
@return [self]
# File lib/ronin/sql/clauses.rb, line 171 def union(&block) clause(:UNION,&block) end
Appends a ‘UNION ALL` clause.
@return [self]
@since 1.1.0
# File lib/ronin/sql/clauses.rb, line 182 def union_all(&block) clause([:UNION, :ALL],&block) end
Appends a ‘VALUES` clause.
@param [Array] values
The values to insert.
@return [self]
# File lib/ronin/sql/clauses.rb, line 263 def values(*values) clause(:VALUES,values) end
Appends a ‘WHERE` clause.
@return [self]
# File lib/ronin/sql/clauses.rb, line 93 def where(&block) clause(:WHERE,&block) end