← Graph

Active Record Custom Types

concept 1 connections

Active Record allows inheriting from ActiveRecord::Type::Value (or an array type) to define custom serialize/deserialize logic so Ruby objects are persisted to a DB column the database does understand (typically a string or JSON). The type is registered on an attribute via `attribute :col, MyType.new`. Queries (where, find_by) also use the type to serialize inputs. Wrona used this to store Postgres-specific types (inet/IP addresses, UUIDs, intervals, arrays) in SQLite without changing application code — Ruby arrays were serialized to JSON so they remained queryable via SQLite's JSON functions.

category
pattern
about
Active Record Custom Types concept
Used to serialize Postgres-specific types for SQLite.

Provenance

Read by
5 extractions