diff --git a/src/main/scala/minisql/context/MirrorContext.scala b/src/main/scala/minisql/context/MirrorContext.scala new file mode 100644 index 0000000..c1be053 --- /dev/null +++ b/src/main/scala/minisql/context/MirrorContext.scala @@ -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] +} diff --git a/src/main/scala/minisql/context/mirror.scala b/src/main/scala/minisql/context/mirror.scala new file mode 100644 index 0000000..cd3b725 --- /dev/null +++ b/src/main/scala/minisql/context/mirror.scala @@ -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] + +}