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


Converts between the SQLite3 types (NULL, INTEGER, REAL, TEXT and BLOB) and native Crystal types. See Field to read about of how to apply converters.

SQLite3 does not natively support neither arrays nor Time nor Bool. This converters implements the following workarounds:

As this converter is two-way, the implications above apply to values set by the developer as well. For example, if a bool value is set to "true" by default in the database, the converter would raise upon parsing.

  id              INTEGER,
  favorite_movies STRING  NOT NULL DEFAULT '{}'
require "onyx-sql/converters/sqlite3"

class User
  include Onyx::SQL::Model

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

Onyx::SQL::Converters::SQLite3::Any(Int32).new.to_db(42)       # => 42
Onyx::SQL::Converters::SQLite3::Any(Int32).new.to_db([42, 43]) # => "{42, 43}"
Onyx::SQL::Converters::SQLite3::Any(Int32).new.to_db(true)     # => "{1}"

Defined in:


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(value : T) : DB::Any #

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

[View source]