Skip to content

Commit

Permalink
Implement projection DSL
Browse files Browse the repository at this point in the history
  • Loading branch information
Primetalk committed Mar 20, 2024
1 parent 98b6205 commit a27b5ae
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import io.getquill.generic.DecodingType
import ru.primetalk.typed.ontology.dbquill.parser.TupleConverter
import ru.primetalk.typed.ontology.dbquill.parser.ontQuote
import io.getquill.util.LoadConfig
import ru.primetalk.typed.ontology.simple.meta.Projector

object OntPerson {
given schemaBasedParser: SchemaBasedParser.type = SchemaBasedParser
Expand All @@ -36,7 +37,7 @@ object OntPerson {

val orders = run(orderQuery)

println(orders.map(_ ->> Order1.date))
println(orders.map(_ π Order1.smallerSchema))

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@ object Order1 extends TableBuilder:
val date1 = date
type Date = date.type
type TableSchema = Id #: Date #: EmptySchema

type SmallerSchema = Date #: EmptySchema
val smallerSchema = fields(date)

val tableSchema: TableSchema = fields(id, date)
val ts = fields(id, date)
type TS = ts.Type
val svt = summon[SchemaValueType.Aux1[TableSchema]]
val smallerSvt = summon[SchemaValueType.Aux1[SmallerSchema]]
type Row = TupleConverter[svt.Value]
// type ARow = svt.Value #@ TableSchema
type ARow = (*:[Int, *:[LocalDate, EmptyTuple]]) #@ TableSchema
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,15 @@ trait ProjectorAnnotatedTypes extends RecordSchemaAnnotatedTypes:
VS <: Tuple,
](using
rpvt: RecordPropertyValueType[P, VP],
existingSchemaProjector: Projector[From, VFrom, S, VS],
existingSchemaProjector: Projector[From, VFrom#@From, S, VS #@ S],
propertyProjector: PropertyProjector[From, VFrom, P, VP],
svtps: SchemaValueType[P #: S, VP *: VS]
): Projector[From, VFrom, P #: S, VP *: VS] =
svtps: SchemaValueType[P #: S, (VP *: VS) #@ (P #: S)]
): Projector[From, VFrom #@From, P #: S, (VP *: VS) #@ (P #: S)] =
new:
val from: SchemaValueType[From, VFrom] = existingSchemaProjector.from
val to: SchemaValueType[P #: S, VP *: VS] = svtps
def apply(v: VFrom): VP *: VS =
(propertyProjector(v) *: existingSchemaProjector(v))
val from: SchemaValueType[From, VFrom#@From] = existingSchemaProjector.from
val to: SchemaValueType[P #: S, (VP *: VS) #@ (P #: S)] = svtps
def apply(v: VFrom#@From): (VP *: VS) #@ (P #: S) =
(propertyProjector(v) *: existingSchemaProjector(v)).#@[(P #: S)]

implicit class ValueOps[S <: RecordSchema, V](v: V)(using svtv: SchemaValueType[S, V]):
type Schema = S
Expand All @@ -212,6 +212,10 @@ trait ProjectorAnnotatedTypes extends RecordSchemaAnnotatedTypes:
pp.apply(av)
def /[VP,P <:SimplePropertyId[?, VP]](p: P)(using pp: PropertyProjector[S, V#@S, P, VP]) =
pp.apply(av)
def >>[VS2, S2 <: RecordSchema](s2: S2)(using p: Projector[S, V #@ S, S2, VS2 #@ S2]) =
p(av)
inline def π[VS2, S2 <: RecordSchema](s2: S2)(using p: Projector[S, V #@ S, S2, VS2 #@ S2]) =
p(av)

trait TableBuilderAnnotatedTypes:
final case class TableBuilderExtensionR[S <: RecordSchema, V <: Tuple](
Expand Down

0 comments on commit a27b5ae

Please sign in to comment.