trait ValueWrites[T] extends AnyRef
Typeclass for encoding Scala/Java types to Postgres wire values.
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 written from Scala / Java Type Y"):
Postgres Type | Scala / Java Type |
---|---|
BIGINT (int8) | Long, Int, Short, Byte |
BOOL | Boolean |
BYTEA (byte[]) | Buf |
CHARACTER(n) | String |
DATE (date) | |
DOUBLE (float8) | Double, Float |
INET | Inet (java.net.InetAddress and a subnet) |
INTEGER (int, int4) | Int, Short, Byte |
JSON | String or Json |
JSONB | |
NUMERIC (decimal) | BigDecimal |
REAL (float4) | Float |
SMALLINT (int2) | Short and Byte |
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
- ValueWrites
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Abstract Value Members
- abstract def accepts(tpe: PgType): Boolean
Returns true when this implementation is able to encode values of the provided Postgres type.
Returns true when this implementation is able to encode values of the provided Postgres type. Returns false otherwise.
- tpe
the Postgres type to check.
- returns
true if this implementation can encode values for the type, false otherwise.
- abstract def writes(tpe: PgType, value: T, charset: Charset): WireValue
Encode a value to Postgres' wire representation for a particular Postgres type.
Encode a value to Postgres' wire representation for a particular Postgres type.
- tpe
the Postgres type to encode the value into.
- value
the value to encode.
- charset
when applicable, the character set to use when encoding.
- returns
the encoded value
- Note
It is the responsability of the caller to ensure that the Postgres type is accepted by this implementation.
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: ValueWrites[T]): ValueWrites[T]
Returns a
ValueWrites
instance that will usethis
if it accepts the type, otherwise will delegate tothat
.Returns a
ValueWrites
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
ValueWrites
instance that will usethis
if it accepts the type, otherwise will delegate tothat
.
- See also
- 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()