Class: String
- Defined in:
- lib/sequel/core_sql.rb,
lib/sequel/adapters/postgres.rb
Overview
String extensions
Direct Known Subclasses
Constant Summary collapse
- POSTGRES_BOOL_TRUE =
't'.freeze
- POSTGRES_BOOL_FALSE =
'f'.freeze
Instance Method Summary collapse
-
#lit ⇒ Object
(also: #expr)
Converts a string into an LiteralString, in order to override string literalization, e.g.:.
- #postgres_to_bool ⇒ Object
-
#split_sql ⇒ Object
Splits a string into separate SQL statements, removing comments and excessive white-space.
-
#to_sql ⇒ Object
Converts a string into an SQL string by removing comments.
-
#to_time ⇒ Object
Converts a string into a Time object.
Instance Method Details
#lit ⇒ Object Also known as: expr
Converts a string into an LiteralString, in order to override string literalization, e.g.:
DB[:items].filter(:abc => 'def').sql #=>
"SELECT * FROM items WHERE (abc = 'def')"
DB[:items].filter(:abc => 'def'.lit).sql #=>
"SELECT * FROM items WHERE (abc = def)"
42 43 44 |
# File 'lib/sequel/core_sql.rb', line 42 def lit Sequel::LiteralString.new(self) end |
#postgres_to_bool ⇒ Object
140 141 142 143 144 145 146 147 148 |
# File 'lib/sequel/adapters/postgres.rb', line 140 def postgres_to_bool if self == POSTGRES_BOOL_TRUE true elsif self == POSTGRES_BOOL_FALSE false else nil end end |
#split_sql ⇒ Object
Splits a string into separate SQL statements, removing comments and excessive white-space.
29 30 31 |
# File 'lib/sequel/core_sql.rb', line 29 def split_sql to_sql.split(';').map {|s| s.strip} end |
#to_sql ⇒ Object
Converts a string into an SQL string by removing comments. See also Array#to_sql.
23 24 25 |
# File 'lib/sequel/core_sql.rb', line 23 def to_sql split($/).to_sql end |
#to_time ⇒ Object
Converts a string into a Time object.
49 50 51 52 53 54 55 56 |
# File 'lib/sequel/core_sql.rb', line 49 def to_time begin Time.parse(self) rescue Exception => e raise Error::InvalidValue, "Invalid time value '#{self}' (#{e.message})" end # Why does Time.parse('0000-00-00') bork and not return nil or some such? end |