Class: MysqlFramework::SqlColumn

Inherits:
Object
  • Object
show all
Defined in:
lib/mysql_framework/sql_column.rb

Overview

This class is used to represent a sql column within a table

Instance Method Summary collapse

Constructor Details

#initialize(table:, column:) ⇒ SqlColumn

Returns a new instance of SqlColumn.



6
7
8
9
# File 'lib/mysql_framework/sql_column.rb', line 6

def initialize(table:, column:)
  @table = table
  @column = column
end

Instance Method Details

#as(name) ⇒ Object

This method is called to generate an alias statement for this column.



54
55
56
# File 'lib/mysql_framework/sql_column.rb', line 54

def as(name)
  "#{self} as `#{name}`"
end

#eq(value) ⇒ Object

This method is called to create a equals (=) condition for this column.



20
21
22
# File 'lib/mysql_framework/sql_column.rb', line 20

def eq(value)
  SqlCondition.new(column: to_s, comparison: '=', value: value)
end

#gt(value) ⇒ Object

This method is called to create a greater than (>) condition for this column.



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

def gt(value)
  SqlCondition.new(column: to_s, comparison: '>', value: value)
end

#gte(value) ⇒ Object

This method is called to create a greater than or equal (>=) condition for this column.



35
36
37
# File 'lib/mysql_framework/sql_column.rb', line 35

def gte(value)
  SqlCondition.new(column: to_s, comparison: '>=', value: value)
end

#in(*values) ⇒ Object



49
50
51
# File 'lib/mysql_framework/sql_column.rb', line 49

def in(*values)
  InCondition.new(column: to_s, comparison: 'IN', value: values)
end

#lt(value) ⇒ Object

This method is called to create a less than (<) condition for this column.



40
41
42
# File 'lib/mysql_framework/sql_column.rb', line 40

def lt(value)
  SqlCondition.new(column: to_s, comparison: '<', value: value)
end

#lte(value) ⇒ Object

This method is called to create a less than or equal (<=) condition for this column.



45
46
47
# File 'lib/mysql_framework/sql_column.rb', line 45

def lte(value)
  SqlCondition.new(column: to_s, comparison: '<=', value: value)
end

#not_eq(value) ⇒ Object

This method is called to create a not equal (<>) condition for this column.



25
26
27
# File 'lib/mysql_framework/sql_column.rb', line 25

def not_eq(value)
  SqlCondition.new(column: to_s, comparison: '<>', value: value)
end

#to_sObject



11
12
13
# File 'lib/mysql_framework/sql_column.rb', line 11

def to_s
  "`#{@table}`.`#{@column}`"
end

#to_symObject



15
16
17
# File 'lib/mysql_framework/sql_column.rb', line 15

def to_sym
  @column.to_sym
end