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

Overview

Converts between the PostgreSQL's native "JSON" column type and Crystal objects with #to_json and .from_json methods (e.g. JSON::Serializable or Hash). See Field to read about of how to apply converters.

CREATE TABLE users (
  meta  JSON NOT NULL DEFAULT "{}"
);
require "onyx-sql/converters/pg/json"

class User
  include Onyx::SQL::Model

  struct Meta
    include JSON::Serilalizable
    property foo : String
  end

  schema do
    type meta : Meta, converter: PG::JSON(Meta)
  end
end

Defined in:

onyx-sql/converters/pg/json.cr

Class Method Summary

Class Method Detail

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

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

[View source]