Composite
Attributes
- Source
- Composite.scala
- Graph
-
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
Composite.type
Members list
Type members
Types
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
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
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
Overload for a single element tuple.
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
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
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
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
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
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
Creates a composite SQLDefinitionRead which cannot write values.
Overload for a single element tuple.
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
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