module Onyx::SQL::Converters::PG::Any(T)

Overview

Converts between the PostgreSQL values (Nil, Bytes, Number, Bool, String, Array, Time and also PG::Geo) and native Crystal types. It automatically handles enumerables. See Field to read about of how to apply converters.

NOTE Although PostgreSQL natively supports arrays, some databases don't (for example, SQLite). That's why you have to explicitly declare a converter on a variable which is (or may be) an array.

CREATE TABLE users (
  id              INTEGER,
  favorite_movies TEXT[]
);
require "onyx-sql/converters/pg"

class User
  include Onyx::SQL::Model

  schema do
    type id : Int32, converter: PG::Any(Int32)
    type favorite_movies : Array(String), converter: PG::Any(String)
  end
end

Onyx::SQL::Converters::PG::Any(Int32).new.to_db([42, 43]) # => Bytes

Defined in:

onyx-sql/converters/pg/any.cr

Class Method Summary

Class Method Detail

def self.from_rs(rs : DB::ResultSet) : T? #

[View source]
def self.from_rs_array(rs : DB::ResultSet) : Array(T)? #

[View source]
def self.to_db(values : Enumerable(T)) : DB::Any #

[View source]
def self.to_db(value : T) : DB::Any #

[View source]