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

Overview

Converts between the PostgreSQL ENUM type and Crystal Enums. See Field to read about of how to apply converters.

CREATE TYPE users_role AS ENUM ('writer', 'moderator', 'admin');
CREATE TYPE users_permissions AS ENUM ('create_posts', 'edit_posts');

CREATE TABLE users (
  role        users_role          NOT NULL  DEFAULT 'writer',
  permissions users_permissions[] NOT NULL  DEFAULT '{create_posts}'
);
require "onyx-sql/converters/pg"

class User
  include Onyx::SQL::Model

  enum Role
    Writer
    Moderator
    Admin
  end

  enum Permission
    CreatePosts
    EditPosts
  end

  schema do
    type role : Role, converter: PG::Enum(User::Role)
    type permissions : Array(Permission), converter: PG::Enum(User::Permission)
  end
end

Defined in:

onyx-sql/converters/pg/enum.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(value : T) : DB::Any #

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

[View source]