Open CodeLionX opened 6 years ago
What about dates, timestamps and so on?
What about dates, timestamps and so on?
I see two possible solutions for dates and times:
java.sql.Date
as a ColumnDef type. The caveat is that java.sql.Date
is subclass of java.util.Date
and then immediately Object
String
s encoding a datetime and parse these strings any time they're used.I personally prefer the first option.
I try to avoid using the old java.util.Date
-classes. In the sample application I used java.time.LocalDate
or java.time.LocalDateTime
, but we may adjust this to java.time.ZonedDateTime
to be independent of the local server's timezone.
This will lead to a more complex context-bound as well:
object ColumnDef {
type ¬[A] = A => Nothing // ~ type-negation
type ¬¬[A] = ¬[¬[A]] // ~ type-double-negation to compensate for union-notation
// recursive definition
trait Disj[T] {
type or[S] = Disj[T with ¬[S]]
type apply[X] = ¬¬[X] <:< ¬[T]
}
// for convenience
type |∨|[T] = { type or[S] = Disj[¬[T]]#or[S] }
def apply[T: |∨|[AnyVal]#or[String]#or[ZonedDateTime]#apply](name: String)(implicit ct: ClassTag[T]): ColumnDef[T] =
new ColumnDef[T](name)(ct)
}
This time I used a recursive definition of the union of two types.
As of PR #102 the type-bound for cell types is explicitly set to Any
in:
class ColumnDef[+T <: Any](...
It is also covariant to comply with our map-based implementation for Record
s. We now have to check if the suggested type-bounds are still applicable.
Issue
I suggest using type constraints to restrict the domain of possible value types (
T
) for the creation ofColumnDef[T]
s to(AnyVal ∨ String)
. This would allow following types:AnyVal
,Byte
,Short
,Int
,Long
,Float
,Double
,Char
,Boolean
String
(asString -> CharSequence -> Object -> Any
, we need to include it separately)T extends AnyVal
)Problem Description
Currently, it is possible to create arbitrary complex types for usage in
Relation
s. E.g.:Supporting Information
Possible implementation for restricting the value type of relations via the factory method in the companion object of
ColumnDef[T]
:see Miles Sabin (2009): Unboxed union types in Scala via the Curry-Howard isomorphism