Module: Sqlx

Defined in:
runtime/database/postgresql.rb,
runtime/sqlx/adapter.rbs,
runtime/sqlx/base.rbs,
runtime/sqlx/enum.rbs,
runtime/sqlx/errors.rbs,
runtime/sqlx/json.rbs,
runtime/sqlx/model.rbs,
runtime/sqlx/query.rbs,
runtime/sqlx/row.rbs,
runtime/database/lease.rb,
runtime/database/query_cache.rb,
runtime/database/sqlite.rb,
runtime/sqlx/adapter.rb,
runtime/sqlx/adapter.rb,
runtime/sqlx/base.rb,
runtime/sqlx/enum.rb,
runtime/sqlx/errors.rb,
runtime/sqlx/json.rb,
runtime/sqlx/model.rb,
runtime/sqlx/query.rb,
runtime/sqlx/row.rb

Overview

The storage boundary for a schema-less json/jsonb column: the column holds serialized TEXT, and this codec is the only place that knows the text <-> value rule. One invariant ties the two directions — decode reads back what encode wrote, so a value passing through the codec is never silently reshaped.

Strictness is deliberate: the json gem falls back to to_s for an object it does not know, which would store a Time in a json column as text with no signal, and the gem's strict: true guard is accepted and ignored by the bundled native json package — so encodable? walks the value itself. Both directions raise ArgumentError, the portable class this runtime already uses for a bad argument.

Defined Under Namespace

Modules: Database, Json, Model, Query, Row Classes: Base, Busy, ConnectionFailed, ConnectionTimeout, Enum, EnumWriter, QueryCache, QueryCacheEntry, RecordInvalid, RecordNotFound, RecordNotUnique, ValueTooLong

Class Method Summary collapse

Class Method Details

.adapter_name ⇒ String

the dialect the running adapter speaks. Apps branch on it to pick SQL a dialect understands; each adapter answers its own name through Sqlx::Database.

Returns:

  • (String) —

    the adapter's name ("SQLite", "PostgreSQL")



42
# File 'runtime/sqlx/adapter.rb', line 42

def self.adapter_name: () -> String

.quote(value) ⇒ String

a full SQL literal, quotes included for strings. Callers assembling a statement by hand splice this in. A value written this way is INLINE, not bound, so Query#write is the safer default for anything that arrived from a request.

A Time renders in the runtime's stored form — the same form the adapter binds a Time in — so a literal and a bound value compare the same way. A Date renders as its ISO text (the stored DATE form), so a date literal and a date bind share one spelling.

A boolean renders through the adapter for the same reason: SQLite stores it as the integers 1/0, while PostgreSQL has no boolean = integer operator and needs the quoted '1'/'0' literal.

Examples:

Sqlx.quote("a'b")  # => "'a''b'"

Parameters:

  • value (Object) —

    the value to render as a literal

Returns:

  • (String) —

    the literal — NULL, the bare number, the adapter's boolean spelling (1/0 on SQLite, '1'/'0' on PostgreSQL), the stored form for a Time, else the escaped single-quoted string



33
# File 'runtime/sqlx/adapter.rb', line 33

def self.quote: (untyped value) -> String