Allow both decoder and encoder
This commit is contained in:
parent
cb0c6082d0
commit
63a9a0cad3
3 changed files with 21 additions and 3 deletions
|
@ -18,6 +18,7 @@ opaque type EntityQuery[E] <: Query[E] = Query[E]
|
||||||
|
|
||||||
object EntityQuery {
|
object EntityQuery {
|
||||||
extension [E](inline e: EntityQuery[E]) {
|
extension [E](inline e: EntityQuery[E]) {
|
||||||
|
|
||||||
inline def map[E1](inline f: E => E1): EntityQuery[E1] = {
|
inline def map[E1](inline f: E => E1): EntityQuery[E1] = {
|
||||||
transform(e)(f)(Map.apply)
|
transform(e)(f)(Map.apply)
|
||||||
}
|
}
|
||||||
|
@ -25,6 +26,7 @@ object EntityQuery {
|
||||||
inline def filter(inline f: E => Boolean): EntityQuery[E] = {
|
inline def filter(inline f: E => Boolean): EntityQuery[E] = {
|
||||||
transform(e)(f)(Filter.apply)
|
transform(e)(f)(Filter.apply)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,6 +92,7 @@ private def compileImpl[I <: Idiom, N <: NamingStrategy](
|
||||||
.getOrElse(report.errorAndAbort(s"NamingStrategy not known at compile"))
|
.getOrElse(report.errorAndAbort(s"NamingStrategy not known at compile"))
|
||||||
|
|
||||||
val stmt = idiom.translate(ast)(using naming)
|
val stmt = idiom.translate(ast)(using naming)
|
||||||
|
report.info(s"Static Query: ${stmt}")
|
||||||
Expr(stmt._2)
|
Expr(stmt._2)
|
||||||
case None =>
|
case None =>
|
||||||
report.info("Dynamic Query")
|
report.info("Dynamic Query")
|
||||||
|
|
|
@ -15,6 +15,14 @@ trait RowExtract[A, Row] {
|
||||||
|
|
||||||
object RowExtract {
|
object RowExtract {
|
||||||
|
|
||||||
|
private[context] def single[Row, E](
|
||||||
|
decoder: ColumnDecoder.Aux[Row, E]
|
||||||
|
): RowExtract[E, Row] = new RowExtract[E, Row] {
|
||||||
|
def extract(row: Row): Try[E] = {
|
||||||
|
decoder.decode(row, 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private def extractorImpl[A, Row](
|
private def extractorImpl[A, Row](
|
||||||
decoders: IArray[Any],
|
decoders: IArray[Any],
|
||||||
m: Mirror.ProductOf[A]
|
m: Mirror.ProductOf[A]
|
||||||
|
@ -83,14 +91,21 @@ trait Context[I <: Idiom, N <: NamingStrategy] { selft =>
|
||||||
|
|
||||||
inline def io[E](
|
inline def io[E](
|
||||||
inline q: minisql.Query[E]
|
inline q: minisql.Query[E]
|
||||||
)(using r: RowExtract[E, DBRow]): DBIO[IArray[E]] = {
|
): DBIO[IArray[E]] = {
|
||||||
|
|
||||||
|
val extractor = summonFrom {
|
||||||
|
case e: RowExtract[E, DBRow] => e
|
||||||
|
case e: ColumnDecoder.Aux[DBRow, E] =>
|
||||||
|
RowExtract.single(e)
|
||||||
|
}
|
||||||
|
|
||||||
val lifts = q.liftMap
|
val lifts = q.liftMap
|
||||||
val stmt = minisql.compile(q, idiom, naming)
|
val stmt = minisql.compile(q, idiom, naming)
|
||||||
val (sql, params) = stmt.expand(lifts)
|
val (sql, params) = stmt.expand(lifts)
|
||||||
(
|
(
|
||||||
sql = sql,
|
sql = sql,
|
||||||
params = params.map(_.value.get.asInstanceOf),
|
params = params.map(_.value.get.asInstanceOf),
|
||||||
mapper = (rows) => rows.traverse(r.extract)
|
mapper = (rows) => rows.traverse(extractor.extract)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -304,7 +304,7 @@ trait MirrorIdiomBase extends Idiom {
|
||||||
Tokenizer[OnConflict.Target] {
|
Tokenizer[OnConflict.Target] {
|
||||||
case OnConflict.NoTarget => stmt""
|
case OnConflict.NoTarget => stmt""
|
||||||
case OnConflict.Properties(props) =>
|
case OnConflict.Properties(props) =>
|
||||||
val listTokens = listTokenizer(astTokenizer).token(props)
|
val listTokens = listTokenizer(using astTokenizer).token(props)
|
||||||
stmt"(${listTokens})"
|
stmt"(${listTokens})"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue