Class: Sqlx::EnumWriter

Inherits:
Object show all
Defined in:
runtime/sqlx/enum.rb,
runtime/sqlx/enum.rbs

Overview

The bound writer behind Enum#writer — one column of one table. It owns the UPDATE shape so the model carries no per-field write helper; the label -> stored-value conversion stays with the bound declaration, so the write's mapping is single-sourced the way reads are.

Instance Method Summary collapse

Constructor Details

#initialize(table:, column:, declaration:) ⇒ EnumWriter

binds the writer to its column. This body runs behind Enum#writer, the entry members use for their bang writers.

Parameters:

  • table (String) —

    the Enum#writer contract, unchanged

  • column (String) —

    the Enum#writer contract, unchanged

  • declaration (Enum) —

    the Enum#writer contract, unchanged



131
# File 'runtime/sqlx/enum.rb', line 131

def initialize: (table: String, column: String, declaration: Enum) -> void

Instance Method Details

#write!(id, label) ⇒ nil

the single-column UPDATE: stores the label's value on the bound column, stamps updated_at with the current UTC time, and matches the row by primary key. An unknown label raises through the bound declaration's strict value before any SQL runs, so a redeclared enum cannot leave a writer pinned to a stale slot. A row the id does not match is a silent no-op, the way the per-model helpers this replaces behaved — the bang promises the write attempt, not that a row existed. The target table carries updated_at; one without it fails loud from the driver. The write entry answers the rows it returned; this writer answers nil — the bang promises the attempt, and a non-RETURNING UPDATE returns no row.

Examples:

writer.write!(@id, :trialing)

Parameters:

  • id (Integer) —

    the primary key of the row to update

  • label (Symbol, String) —

    the label to store, or its stored-value spelling — both read the same declaration slot

Returns:

  • (nil)

Raises:

  • (ArgumentError) —

    the label is not in the declaration



155
# File 'runtime/sqlx/enum.rb', line 155

def write!: (untyped id, untyped label) -> nil