Module: Rusql

Defined in:
lib/rusql.rb,
lib/rusql/join.rb,
lib/rusql/order.rb,
lib/rusql/query.rb,
lib/rusql/table.rb,
lib/rusql/column.rb,
lib/rusql/operand.rb,
lib/rusql/version.rb,
lib/rusql/selector.rb,
lib/rusql/condition.rb,
lib/rusql/count_selector.rb,
lib/rusql/type_exception.rb,
lib/rusql/basic_condition.rb,
lib/rusql/column_selector.rb,
lib/rusql/complex_condition.rb,
lib/rusql/date_function_operand.rb,
lib/rusql/distinct_function_selector.rb,
lib/rusql/convert_tz_function_operand.rb,
lib/rusql/group_concat_function_selector.rb

Defined Under Namespace

Classes: BasicCondition, Column, ColumnSelector, ComplexCondition, Condition, ConvertTzFunctionOperand, CountSelector, DateFunctionOperand, DistinctFunctionSelector, GroupConcatFunctionSelector, Join, Operand, Order, Query, Selector, Table, TypeException

Constant Summary collapse

VERSION =
"1.0.2"

Instance Method Summary collapse

Instance Method Details

#convert_tz(value, from, to) ⇒ Object



34
35
36
# File 'lib/rusql.rb', line 34

def convert_tz(value, from, to)
  ConvertTzFunctionOperand.new(value, from, to)
end

#count(col) ⇒ Object

Raises:



50
51
52
53
# File 'lib/rusql.rb', line 50

def count(col)
  raise TypeException.new(Column, col.class) unless col.is_a?(Column)
  CountSelector.new(col.to_s)
end

#count_allObject



55
56
57
# File 'lib/rusql.rb', line 55

def count_all
  CountSelector.new("*")
end

#date(value) ⇒ Object



30
31
32
# File 'lib/rusql.rb', line 30

def date(value)
  DateFunctionOperand.new(value)
end

#distinct(sel) ⇒ Object

Raises:



38
39
40
41
42
# File 'lib/rusql.rb', line 38

def distinct(sel)
  raise TypeException.new(Selector, sel.class) unless sel.is_a?(Selector) || sel.is_a?(Column)
  final_sel = sel.is_a?(Column) ? sel.as_selector : sel
  DistinctFunctionSelector.new(final_sel.to_s)
end

#group_concat(sel) ⇒ Object

Raises:



44
45
46
47
48
# File 'lib/rusql.rb', line 44

def group_concat(sel)
  raise TypeException.new(Selector, sel.class) unless sel.is_a?(Selector) || sel.is_a?(Column)
  final_sel = sel.is_a?(Column) ? sel.as_selector : sel
  GroupConcatFunctionSelector.new(final_sel.to_s)
end

#inner_join(table, condition) ⇒ Object



65
66
67
# File 'lib/rusql.rb', line 65

def inner_join(table,condition)
  Join.new(:inner_join, table, condition)
end

#left_outer_join(table, condition) ⇒ Object



73
74
75
# File 'lib/rusql.rb', line 73

def left_outer_join(table,condition)
  Join.new(:left_outer_join, table, condition)
end

#outer_join(table, condition) ⇒ Object



69
70
71
# File 'lib/rusql.rb', line 69

def outer_join(table,condition)
  Join.new(:outer_join, table, condition)
end

#right_outer_join(table, condition) ⇒ Object



77
78
79
# File 'lib/rusql.rb', line 77

def right_outer_join(table,condition)
  Join.new(:right_outer_join, table, condition)
end

#select(*opts) ⇒ Object



81
82
83
84
85
86
87
# File 'lib/rusql.rb', line 81

def select(*opts)
  opts.each do |arg|
    raise TypeException.new(Selector, arg.class) unless arg.is_a?(Selector) || arg.is_a?(Column)
  end

  Query.new(opts.map{|a| a.is_a?(Column) ? a.as_selector : a })
end

#table(name) ⇒ Object



59
60
61
62
63
# File 'lib/rusql.rb', line 59

def table(name)
  t = Table.new
  t.name = name
  t
end