Composite

doobie.Composite
object Composite

Attributes

Source
Composite.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
Composite.type

Members list

Type members

Types

type TupleValues[T <: Tuple] = InverseMap[T, SQLDefinition]

Removes the SQLDefinition wrapper from each member of the tuple.

Removes the SQLDefinition wrapper from each member of the tuple.

e.g. turns (SQLDefinition[A], SQLDefinition[B]) into (A, B).

Attributes

Source
Composite.scala
type TupleValuesRO[T <: Tuple] = InverseMap[T, SQLDefinitionRead]

Removes the SQLDefinitionRead wrapper from each member of the tuple.

Removes the SQLDefinitionRead wrapper from each member of the tuple.

e.g. turns (SQLDefinitionRead[A], SQLDefinitionRead[B]) into (A, B).

Attributes

Source
Composite.scala

Value members

Concrete methods

def apply[T <: Tuple : IsMappedBy[SQLDefinition], R](sqlDefinitionsTuple: T)(map: (TupleValues[T]) => R)(unmap: R => TupleValues[T]): SQLDefinition[R]

Allows you to define a composite type that is composed of other SQLDefinitions.

Allows you to define a composite type that is composed of other SQLDefinitions.

For example you can compose multiple Columns:

 case class Person(name: String, age: Int)
 val nameCol = Column[String]("name")
 val ageCol = Column[Int]("age")
 val person: SQLDefinition[Person] =
   Composite((nameCol.sqlDef, ageCol.sqlDef))(Person.apply)(Tuple.fromProductTyped)

 // or alternatively
 val person: SQLDefinition[Person] =
   Composite((nameCol, ageCol).toSqlResults)(Person.apply)(Tuple.fromProductTyped)

Or even other Composites:

 val pet1Col = Column[String]("pet1")
 val pet2Col = Column[String]("pet2")
 case class Pets(pet1: String, pet2: String)
 val pets: SQLDefinition[Pets] = Composite((pet1Col.sqlDef, pet2Col.sqlDef))(Pets.apply)(Tuple.fromProductTyped)

 case class PersonWithPets(person: Person, pets: Pets)
 val personWithPets: SQLDefinition[PersonWithPets] =
   Composite((person, pets))(PersonWithPets.apply)(Tuple.fromProductTyped)

Value parameters

map

Function to map the tuple of components to the final result

sqlDefinitionsTuple

Tuple of SQLDefinitions to compose

unmap

Function to map the final result to the tuple of components

Attributes

Source
Composite.scala
def apply[A, R](sqlDefinition: SQLDefinition[A])(map: A => R)(unmap: R => A): SQLDefinition[R]

Overload for a single element tuple.

Overload for a single element tuple.

Attributes

Source
Composite.scala
def fromMultiOption[A1, A2, R](a1Def: SQLDefinition[Option[A1]], a2Def: SQLDefinition[Option[A2]])(map: (A1, A2) => R)(unmap: R => (A1, A2)): SQLDefinition[Option[R]]

SQLDefinition when the element is defined by two Optional values.

SQLDefinition when the element is defined by two Optional values.

Usually the database constraints will enforce that both are either Some or None.

When using this we need to introduce a separate type so Scala compiler would know which Read and Write instances to use in SQL queries.

Example:

 /** If the document type supports a total amount, it will be stored here. If this is [[Some]] then
   * [[colAmountCurrency]] will be [[Some]] as well, enforced by the database constraints.
   */
 val colAmount: Column[Option[BigDecimal]] = Column("amount")

 /** Same as [[colAmount]] but for the currency. */
 val colAmountCurrency: Column[Option[AppCurrency]] = Column("amount_currency")

 /** The amount of the document if the document type supports a total amount. */
 case class TotalAmount(m: Option[Money]) extends AnyVal
 object TotalAmount
     extends WithSQLDefinition[TotalAmount](
       Composite
         .fromMultiOption(colAmountCurrency.sqlDef, colAmount.sqlDef)(_.toSquants(_))(m =>
           (AppCurrency.fromSquants(m.currency).getOrThrow, m.amount)
         )
         .imap(TotalAmount(_))(_.m)
     )

Attributes

Source
Composite.scala
def fromMultiOption[A1, A2, A3, R](a1Def: SQLDefinition[Option[A1]], a2Def: SQLDefinition[Option[A2]], a3Def: SQLDefinition[Option[A3]])(map: (A1, A2, A3) => R)(unmap: R => (A1, A2, A3)): SQLDefinition[Option[R]]

SQLDefinition when the element is defined by three Optional values.

SQLDefinition when the element is defined by three Optional values.

Usually the database constraints will enforce that both are either Some or None.

Attributes

See also

fromMultiOption overload for 2 Optional values for additional documentation.

Source
Composite.scala
def fromMultiOption[A1, A2, A3, A4, R](a1Def: SQLDefinition[Option[A1]], a2Def: SQLDefinition[Option[A2]], a3Def: SQLDefinition[Option[A3]], a4Def: SQLDefinition[Option[A4]])(map: (A1, A2, A3, A4) => R)(unmap: R => (A1, A2, A3, A4)): SQLDefinition[Option[R]]

SQLDefinition when the element is defined by four Optional values.

SQLDefinition when the element is defined by four Optional values.

Usually the database constraints will enforce that both are either Some or None.

Attributes

See also

fromMultiOption overload for 2 Optional values for additional documentation.

Source
Composite.scala
def fromMultiOption[A1, A2, A3, A4, A5, R](a1Def: SQLDefinition[Option[A1]], a2Def: SQLDefinition[Option[A2]], a3Def: SQLDefinition[Option[A3]], a4Def: SQLDefinition[Option[A4]], a5Def: SQLDefinition[Option[A5]])(map: (A1, A2, A3, A4, A5) => R)(unmap: R => (A1, A2, A3, A4, A5)): SQLDefinition[Option[R]]

SQLDefinition when the element is defined by five Optional values.

SQLDefinition when the element is defined by five Optional values.

Usually the database constraints will enforce that both are either Some or None.

Attributes

See also

fromMultiOption overload for 2 Optional values for additional documentation.

Source
Composite.scala
def fromMultiOption[A1, A2, A3, A4, A5, A6, R](a1Def: SQLDefinition[Option[A1]], a2Def: SQLDefinition[Option[A2]], a3Def: SQLDefinition[Option[A3]], a4Def: SQLDefinition[Option[A4]], a5Def: SQLDefinition[Option[A5]], a6Def: SQLDefinition[Option[A6]])(map: (A1, A2, A3, A4, A5, A6) => R)(unmap: R => (A1, A2, A3, A4, A5, A6)): SQLDefinition[Option[R]]

SQLDefinition when the element is defined by six Optional values.

SQLDefinition when the element is defined by six Optional values.

Usually the database constraints will enforce that both are either Some or None.

Attributes

See also

fromMultiOption overload for 2 Optional values for additional documentation.

Source
Composite.scala
def fromMultiOption[A1, A2, A3, A4, A5, A6, A7, R](a1Def: SQLDefinition[Option[A1]], a2Def: SQLDefinition[Option[A2]], a3Def: SQLDefinition[Option[A3]], a4Def: SQLDefinition[Option[A4]], a5Def: SQLDefinition[Option[A5]], a6Def: SQLDefinition[Option[A6]], a7Def: SQLDefinition[Option[A7]])(map: (A1, A2, A3, A4, A5, A6, A7) => R)(unmap: R => (A1, A2, A3, A4, A5, A6, A7)): SQLDefinition[Option[R]]

SQLDefinition when the element is defined by seven Optional values.

SQLDefinition when the element is defined by seven Optional values.

Usually the database constraints will enforce that both are either Some or None.

Attributes

See also

fromMultiOption overload for 2 Optional values for additional documentation.

Source
Composite.scala
def readOnly[T <: Tuple : IsMappedBy[SQLDefinitionRead], R](sqlDefinitionsTuple: T)(map: (TupleValuesRO[T]) => R): SQLDefinitionRead[R]

Creates a composite SQLDefinitionRead which cannot write values.

Creates a composite SQLDefinitionRead which cannot write values.

Attributes

Source
Composite.scala
def readOnly[A, R](sqlDefinition: SQLDefinitionRead[A])(map: A => R): SQLDefinitionRead[R]

Overload for a single element tuple.

Overload for a single element tuple.

Attributes

Source
Composite.scala
def unsafe[R](sqlDefinitions: NonEmptyVector[SQLDefinition[_]], isOption: Boolean)(map: (Iterator[Any]) => R)(unmap: R => Iterator[Any]): SQLDefinition[R]

Type-unsafe version of apply.

Type-unsafe version of apply.

Value parameters

map

Function to map the components that make up the composite type to the final result.

unmap

Function to map the final result to the components that make up the composite type.

Attributes

Source
Composite.scala
def unsafeReadOnly[R](sqlDefinitions: NonEmptyVector[SQLDefinitionRead[_]])(map: (Iterator[Any]) => R): SQLDefinitionRead[R]

Type-unsafe version of readOnly.

Type-unsafe version of readOnly.

Value parameters

map

Function to map the components that make up the composite type to the final result.

Attributes

Source
Composite.scala