class Rotor::Statement
A statement that changes rows, as a value: what a repository runs.
to_sql gives its SQL and parameters; returning asks for columns
of the rows it changed.
class SUser < Rotor::Model
table "users" do
column :id, Int, primary: true
column :name, String
end
end
u = SUser.load({id: 7, name: "Ann"}).with(name: "Bob")
Rotor::Statement.update(u)&.to_sql # => ["UPDATE \"users\" SET \"name\" = $1 WHERE \"id\" = $2", ["Bob", 7]]
Rotor::Statement.delete(u).to_sql # => ["DELETE FROM \"users\" WHERE \"id\" = $1", [7]]
/home/runner/work/rotor/rotor/src/statement.qz:17
Class methods
def self.new(table: Rotor::TableInfo, pieces: Array[Rotor::Piece], returning: Array[Symbol]?) -> Rotor::Statement
(Made by the methods below and by Rotor::Query.)
def self.insert(model: Rotor::Model) -> Rotor::Statement
The insertion of model's row, with the columns it has values for
(DEFAULT VALUES when none).
def self.update(model: Rotor::Model) -> Rotor::Statement?
The update of model's row, by its primary key, with the columns
assigned since it was loaded or saved (Rotor::Model#changed), or nil
when there are none.
def self.delete(model: Rotor::Model) -> Rotor::Statement
The deletion of model's row, by its primary key.
def self.render(pieces: Array[Rotor::Piece]) -> [String, Array[Object?]]
The text of pieces, its parameters numbered in order, and their
values.
Methods
def returning(*names: Symbol) -> Rotor::Statement
The statement, returning the given columns of the rows it changes (all of them when none are named).
def returned -> Array[Symbol]?
The columns returning asked for, or nil.
def to_sql -> [String, Array[Object?]]
The SQL statement and its parameters.
def inspect -> String
A developer-readable representation, as p prints it: strings quoted,
collections with their elements' inspect, an object with its fields
(#<Point @x=1, @y=2>).
from Object
def to_s -> String
The value as a string, for puts and interpolation. For an instance of
a class, the class name in the form #<Point>; for an exception, its
message; for a data value or an enum variant, the default inspect.
It does not call an inspect the class defines.
from Object