Skip to content

Commit

Permalink
bunch of todos
Browse files Browse the repository at this point in the history
  • Loading branch information
sviezypan committed Jul 30, 2021
1 parent 75a269b commit 11c8a6c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
6 changes: 5 additions & 1 deletion core/jvm/src/main/scala/zio/sql/newtypes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ package zio.sql
trait NewtypesModule {

type ColumnName = String
type TableName = String
sealed trait TableName
object TableName {
final case class Source(name: String) extends TableName
case object Derived extends TableName
}

sealed case class FunctionName(name: String)

Expand Down
16 changes: 16 additions & 0 deletions core/jvm/src/main/scala/zio/sql/select.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ trait SelectModule { self: ExprModule with TableModule =>

val mapper: ResultType => Out

type Repr[TableType]
type TableType

val columns: Repr[_ <: TableType]

/**
* Maps the [[Read]] query's output to another type by providing a function
* that can transform from the current type to the new type.
Expand Down Expand Up @@ -270,11 +275,18 @@ trait SelectModule { self: ExprModule with TableModule =>
}
}

//TODO change type Read.Repr to ColumnsRepr
sealed case class Union[Repr, Out](left: Read.Aux[Repr, Out], right: Read.Aux[Repr, Out], distinct: Boolean)
extends Read[Out] {
type ResultType = Repr

val mapper: ResultType => Out = left.mapper

//TODO left has type Expr[T1, String], right has Expr[T2, String], Repr is Expr[T1 with T2, String]
type Repr[TableType] = left.Repr[left.TableType with right.TableType]

//TODO turn the name columns into indexed columns so they can apply to either left hand or right hand side
val columns: Repr[left.TableType with right.TableType] = left.columns.asInstanceOf
}

sealed case class Literal[B: TypeTag](values: Iterable[B]) extends Read[(B, Unit)] {
Expand All @@ -283,6 +295,10 @@ trait SelectModule { self: ExprModule with TableModule =>
val mapper: ResultType => (B, Unit) = identity(_)

def typeTag: TypeTag[B] = implicitly[TypeTag[B]]

type Repr[TableType] = (Expr[Features.Source, TableType, B], Unit)

val columns: Repr[TableType] = (Expr.Source(TableName.Derived, Column[B]("1")), ())
}

def lit[B: TypeTag](values: B*): Read[(B, Unit)] = Literal(values.toSeq)
Expand Down
2 changes: 2 additions & 0 deletions core/jvm/src/main/scala/zio/sql/table.scala
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ trait TableModule { self: ExprModule with SelectModule =>
def unapply[A, B](tuple: (A, B)): Some[(A, B)] = Some(tuple)
}

// turn column into seald trait
// with "named" and "indexed" subtypes
sealed case class Column[A: TypeTag](name: String) {
def typeTag: TypeTag[A] = implicitly[TypeTag[A]]
}
Expand Down

0 comments on commit 11c8a6c

Please sign in to comment.