module CQL::Postgres::Types

Defined in:

postgres/types/binary.cr
postgres/types/binary_decoder.cr
postgres/types/codecs.cr
postgres/types/decimal_text.cr
postgres/types/oid.cr
postgres/types/param.cr

Constant Summary

EPOCH = Time.utc(2000, 1, 1)
TEXT_CODEC = Codec.new(false, ->(bytes : Bytes) do (String.new(bytes)).as(Value) end)

Class Method Summary

Class Method Detail

def self.codec_for(oid : UInt32) : Codec #

Types without a codec arrive as text and decode to String.


[View source]
def self.date(bytes : Bytes) : Time #

[View source]
def self.microseconds_since_epoch(bytes : Bytes) : Time #

[View source]
def self.parse_json(bytes : Bytes) : JSON::Any #

[View source]
def self.read_int(type : T.class, bytes : Bytes) : T forall T #

[View source]
def self.register(oid : UInt32, binary : Bool = true, borrowed : Bool = false, &decode : Bytes -> Value) : Nil #

Adds or replaces the decoding of a type, e.g. an extension type. The bytes a decoder receives are a private copy unless the codec is registered with borrowed: true (the built-in ones are), which hands out a view of the connection's receive buffer that is only valid during the call. The table is replaced as a whole, so readers on other fibers or threads never see it half-edited.

struct Shout
  include CQL::Postgres::Types::Custom
  getter text : String

  def initialize(@text : String)
  end
end

oid = 777_001_u32 # the type's OID, e.g. from pg_type
CQL::Postgres::Types.register(oid, binary: false) { |bytes| Shout.new(String.new(bytes)) }

[View source]
def self.span_from_microseconds(micros : Int64) : Time::Span #

[View source]