add mirror context
This commit is contained in:
parent
87f1b70b27
commit
7f5092c396
2 changed files with 50 additions and 0 deletions
15
src/main/scala/minisql/context/MirrorContext.scala
Normal file
15
src/main/scala/minisql/context/MirrorContext.scala
Normal file
|
@ -0,0 +1,15 @@
|
|||
package minisql
|
||||
|
||||
import minisql.context.mirror.*
|
||||
|
||||
class MirrorContext[Idiom <: idiom.Idiom, Naming <: NamingStrategy](
|
||||
val idiom: Idiom,
|
||||
val naming: Naming
|
||||
) extends context.Context[Idiom, Naming] {
|
||||
|
||||
type DBRow = Row
|
||||
|
||||
type DBResultSet = Iterable[DBRow]
|
||||
|
||||
type DBStatement = IArray[Any]
|
||||
}
|
35
src/main/scala/minisql/context/mirror.scala
Normal file
35
src/main/scala/minisql/context/mirror.scala
Normal file
|
@ -0,0 +1,35 @@
|
|||
package minisql.context.mirror
|
||||
|
||||
import minisql.{MirrorContext, NamingStrategy}
|
||||
import minisql.idiom.Idiom
|
||||
import minisql.util.Messages.fail
|
||||
import scala.reflect.ClassTag
|
||||
|
||||
/**
|
||||
* No extra class defined
|
||||
*/
|
||||
opaque type Row = IArray[Any] *: EmptyTuple
|
||||
|
||||
extension (r: Row) {
|
||||
|
||||
def data: IArray[Any] = r._1
|
||||
|
||||
def add(value: Any): Row = (r.data :+ value) *: EmptyTuple
|
||||
|
||||
def apply[T](idx: Int)(using t: ClassTag[T]): T = {
|
||||
r.data(idx) match {
|
||||
case v: T => v
|
||||
case other =>
|
||||
fail(
|
||||
s"Invalid column type. Expected '${t.runtimeClass}', but got '$other'"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
trait MirrorCodecs[I <: Idiom, N <: NamingStrategy] {
|
||||
this: MirrorContext[I, N] =>
|
||||
|
||||
given byteEncoder: Encoder[Byte]
|
||||
|
||||
}
|
Loading…
Reference in a new issue