module Rotor::SQL

SQL functions a query's block may call, which the translator knows by name: Rotor::SQL.like(name, "A%") is "name" LIKE $1. Called outside a query they compute the same (a like pattern's % and _, case folding), so a block keeps its meaning wherever it runs.

/home/runner/work/rotor/rotor/src/sql.qz:5

Classes and modules

Class methods

def self.like(s: String, pattern: String) -> Bool

Whether s matches the LIKE pattern: % any run of characters, _ one, \ escaping the next.

Rotor::SQL.like("Ann", "A%")  # => true
Rotor::SQL.like("Ann", "a%")  # => false

/home/runner/work/rotor/rotor/src/sql.qz:13

def self.ilike(s: String, pattern: String) -> Bool

like with case folded: SQL's ILIKE.

/home/runner/work/rotor/rotor/src/sql.qz:16

def self.not_nil[T](c: T?) -> T

c, which is not nil: in a query's block, a nullable column where the condition before it says it is not NULL (where { !age.nil? && Rotor::SQL.not_nil(age) > 18 }), translated as the column itself (a block cannot narrow a getter's result: age is an Int? there). Refused where nothing says so. Raises ArgumentError on nil.

age: Int? = 3
Rotor::SQL.not_nil(age)  # => 3

/home/runner/work/rotor/rotor/src/sql.qz:28

def self.raw(sql: String) -> Rotor::SQL::Raw

sql as is: a Rotor::SQL::Raw.

Rotor::SQL.raw("now()").sql  # => "now()"

/home/runner/work/rotor/rotor/src/sql.qz:42

def self.lower(s: String) -> String

s in lower case: SQL's lower.

/home/runner/work/rotor/rotor/src/sql.qz:45

def self.upper(s: String) -> String

s in upper case: SQL's upper.

/home/runner/work/rotor/rotor/src/sql.qz:48

def self.escape_like(s: String) -> String

The escaped LIKE pattern that matches s itself.

Rotor::SQL.escape_like("50%_off")  # => "50\\%\\_off"

/home/runner/work/rotor/rotor/src/sql.qz:55