add mirror context

This commit is contained in:
jilen 2024-12-19 12:36:44 +08:00
parent 87f1b70b27
commit 7f5092c396
2 changed files with 50 additions and 0 deletions

View 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]
}

View 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]
}