Class: MysqlFramework::SqlCondition
- Inherits:
-
Object
- Object
- MysqlFramework::SqlCondition
- Defined in:
- lib/mysql_framework/sql_condition.rb
Overview
This class is used to represent a Sql Condition for a column.
Direct Known Subclasses
Constant Summary collapse
- NIL_COMPARISONS =
['IS NULL', 'IS NOT NULL'].freeze
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
This method is called to get the value of this condition for prepared statements.
Instance Method Summary collapse
-
#initialize(column:, comparison:, value: nil) ⇒ SqlCondition
constructor
Creates a new SqlCondition using the given parameters.
-
#to_s ⇒ String
This method is called to get the condition as a string for a sql prepared statement.
Constructor Details
#initialize(column:, comparison:, value: nil) ⇒ SqlCondition
Creates a new SqlCondition using the given parameters.
20 21 22 23 24 25 26 |
# File 'lib/mysql_framework/sql_condition.rb', line 20 def initialize(column:, comparison:, value: nil) @column = column @comparison = comparison validate(value) @value = value end |
Instance Attribute Details
#value ⇒ Object (readonly)
This method is called to get the value of this condition for prepared statements.
9 10 11 |
# File 'lib/mysql_framework/sql_condition.rb', line 9 def value @value end |
Instance Method Details
#to_s ⇒ String
This method is called to get the condition as a string for a sql prepared statement
31 32 33 34 35 |
# File 'lib/mysql_framework/sql_condition.rb', line 31 def to_s return "#{@column} #{@comparison.upcase}" if nil_comparison? "#{@column} #{@comparison} ?" end |