trait ValueReads[T] extends AnyRef
Typeclass for decoding wire values to Scala/Java types.
Postgres has its own type system, so the mapping of postgres types to scala types is not 1:1. Furthermore, postgres allows creating custom types (i.e.: commonly enums, but any arbitrary type can effectively be created) which also require their own mapping to scala types.
The following built-in types and their corresponding scala / java types are provided (read this table as "Postgres Type X can be read into Scala / Java Type Y"):
Postgres Type | Scala / Java Type |
---|---|
BIGINT (int8) | Long |
BOOL | Boolean |
BYTEA (byte[]) | Buf |
CHARACTER(n) | String |
DATE (date) | |
DOUBLE (float8) | Double |
INET | Inet (java.net.InetAddress and a subnet) |
INTEGER (int, int4) | Int and Long |
JSON | String or Json |
JSONB | |
NUMERIC (decimal) | BigDecimal |
REAL (float4) | Float and Double |
SMALLINT (int2) | Short, Int and Long. As well as Byte (bounds are checked), since Postgres doesn't have |
TEXT | String |
TIMESTAMP | |
TIMESTAMP WITH TIME ZONE | |
UUID | |
VARCHAR | String |
- Note
numeric types don't have the same correspondence for reading and writing.
- See also
- Alphabetic
- By Inheritance
- ValueReads
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Abstract Value Members
- abstract def accepts(tpe: PgType): Boolean
Returns true if this typeclass is able to decode a wire value of the specified type.
Returns true if this typeclass is able to decode a wire value of the specified type.
- tpe
the type of the wire value to decode.
- returns
true if this typeclass can decode the value, false otherwise.
- abstract def reads(tpe: PgType, buf: Buf, charset: Charset): T
Decodes a non-null value from the wire, throwing an exception if the decoding fails.
Concrete Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- def orElse(that: ValueReads[T]): ValueReads[T]
Returns a
ValueReads
instance that will usethis
if it accepts the type, otherwise will delegate tothat
.Returns a
ValueReads
instance that will usethis
if it accepts the type, otherwise will delegate tothat
.- that
the instance to delegate to when
this
does not accept the provided type.- returns
a
ValueReads
instance that will usethis
if it accepts the type, otherwise will delegate tothat
.
- See also
- def reads(tpe: PgType, value: WireValue, charset: Charset): T
Decode a potentially
NULL
wire value into the requested scala type.Decode a potentially
NULL
wire value into the requested scala type. Note that no further validation is done on the passed inPgType
, the client is expected to have invoked accepts first. Not respecting this may lead to successfully reading an invalid value.- tpe
the postgres type to decode (used when the typeclass supports more than one).
- value
the value on the wire. This may be NULL.
- charset
the server's character set (necessary for decoding strings).
- returns
the decoded value or an exception
- def readsNull(tpe: PgType): T
Produce the value corresponding to the SQL NULL.
Produce the value corresponding to the SQL NULL. Note that typically, there is no sensical value (i.e.: there's no Int value to produce for a NULL), thus this method has a default implementation of producing an error.
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()