File: sql_expr.rb

package info (click to toggle)
ruby-sequel 5.63.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 10,408 kB
  • sloc: ruby: 113,747; makefile: 3
file content (23 lines) | stat: -rw-r--r-- 567 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# frozen-string-literal: true
#
# The sql_expr extension adds the sql_expr method to every object, which
# returns an wrapped object that works nicely with Sequel's DSL by calling
# Sequel.expr:
#
#   1.sql_expr < :a     # 1 < a
#   false.sql_expr & :a # FALSE AND a
#   true.sql_expr | :a  # TRUE OR a
#   ~nil.sql_expr       # NOT NULL
#   "a".sql_expr + "b"  # 'a' || 'b'
#
# To load the extension:
#
#   Sequel.extension :sql_expr

#
class Object
  # Return the object wrapper in an appropriate Sequel expression object.
  def sql_expr
    Sequel[self]
  end
end