module
CQL::Postgres::Types
Defined in:
postgres/types/binary.crpostgres/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
-
.codec_for(oid : UInt32) : Codec
Types without a codec arrive as text and decode to String.
- .date(bytes : Bytes) : Time
- .microseconds_since_epoch(bytes : Bytes) : Time
- .parse_json(bytes : Bytes) : JSON::Any
- .read_int(type : T.class, bytes : Bytes) : T forall T
-
.register(oid : UInt32, binary : Bool = true, borrowed : Bool = false, &decode : Bytes -> Value) : Nil
Adds or replaces the decoding of a type, e.g.
- .span_from_microseconds(micros : Int64) : Time::Span
Class Method Detail
Types without a codec arrive as text and decode to String.
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)) }