lib/mao/query.rb in mao-0.0.6 vs lib/mao/query.rb in mao-0.0.7
- old
+ new
@@ -7,22 +7,27 @@
class Mao::Query
require 'mao/filter'
# A container for text that should be inserted raw into a query.
class Raw
+ # Creates the Mao::Query::Raw with SQL +text+.
def initialize(text)
@text = text
end
+ # The raw SQL text.
attr_reader :text
end
# Returns a Mao::Query::Raw with +text+.
def self.raw(text)
Raw.new(text).freeze
end
+ # Constructs the Query with reference to a table named +table+, and immutable
+ # options hash +options+. +col_types+ is column information for the table,
+ # usually populated by a prior invocation of Mao::Query.new.
def initialize(table, options={}, col_types=nil)
@table, @options = table.to_sym, options.freeze
if !col_types
col_types = {}
@@ -41,12 +46,18 @@
end
@col_types = col_types.freeze
end
+ # A symbol of the name of the table this Query points to.
attr_reader :table
+
+ # The immutable options hash of this Query instance.
attr_reader :options
+
+ # The cached information about columns and their types for the table being
+ # referred to.
attr_reader :col_types
# Returns a new Mao::Query with +options+ merged into the options of this
# object.
def with_options(options)
@@ -366,9 +377,11 @@
end
end
private
+ # Checks that +column+ is a valid column reference in +table+, given
+ # +col_types+ for the table.
def check_column column, table, col_types
unless column.is_a? Symbol
raise ArgumentError, "#{column.inspect} not a Symbol"
end
unless col_types[column]