minimal doc
This commit is contained in:
parent
de180356bc
commit
c8d9fe333e
3 changed files with 26 additions and 6 deletions
8
src/main/scala/minisql/ParamEncoder.scala
Normal file
8
src/main/scala/minisql/ParamEncoder.scala
Normal file
|
@ -0,0 +1,8 @@
|
|||
package minisql
|
||||
|
||||
trait ParamEncoder[E] {
|
||||
|
||||
type Stmt
|
||||
|
||||
def setParam(s: Stmt, idx: Int, v: E): Unit
|
||||
}
|
|
@ -6,8 +6,8 @@ import scala.quoted.*
|
|||
|
||||
type Parser[O <: Ast] = PartialFunction[Expr[?], Expr[O]]
|
||||
|
||||
private[minisql] inline def parseParamAt[A, B](
|
||||
inline f: A => B,
|
||||
private[minisql] inline def parseParamAt[F](
|
||||
inline f: F,
|
||||
inline n: Int
|
||||
): ast.Ident = ${
|
||||
parseParamAt('f, 'n)
|
||||
|
|
|
@ -1,13 +1,16 @@
|
|||
package minisql.dsl
|
||||
|
||||
import minisql.*
|
||||
import minisql.parsing
|
||||
import minisql.ast.{Ast, Entity, Map, Property, Ident, given}
|
||||
import scala.quoted.*
|
||||
import scala.compiletime.*
|
||||
import scala.compiletime.ops.string.*
|
||||
import scala.collection.immutable.{Map => IMap}
|
||||
|
||||
sealed trait Dsl {
|
||||
def ast: Ast
|
||||
def lifts: IMap[String, (Any, ParamEncoder[?])] = IMap.empty
|
||||
}
|
||||
|
||||
trait Query[E] extends Dsl
|
||||
|
@ -21,7 +24,13 @@ extension [E](inline e: EntityQuery[E]) {
|
|||
}
|
||||
|
||||
extension [A, B](inline f1: A => B) {
|
||||
private inline def param0 = parsing.parseParamAt[A, B](f1, 0)
|
||||
private inline def param0 = parsing.parseParamAt(f1, 0)
|
||||
private inline def body = parsing.parseBody(f1)
|
||||
}
|
||||
|
||||
extension [A1, A2, B](inline f1: (A1, A2) => B) {
|
||||
private inline def param0 = parsing.parseParamAt(f1, 0)
|
||||
private inline def param1 = parsing.parseParamAt(f1, 1)
|
||||
private inline def body = parsing.parseBody(f1)
|
||||
}
|
||||
|
||||
|
@ -31,10 +40,13 @@ private inline def transform[D1 <: Dsl, D2 <: Dsl, A, B](inline ast: Ast)(
|
|||
f2(fast(ast, f.param0, f.body))
|
||||
}
|
||||
|
||||
given FromExpr[EntityQuery[?]] with {
|
||||
private given FromExpr[EntityQuery[?]] with {
|
||||
def unapply(x: Expr[EntityQuery[?]])(using Quotes): Option[EntityQuery[?]] = {
|
||||
x match {
|
||||
case '{ val x: Ast = ${ Expr(ast) }; EntityQuery(x) } =>
|
||||
case '{
|
||||
val x: Ast = ${ Expr(ast) }
|
||||
EntityQuery(x)
|
||||
} =>
|
||||
Some(EntityQuery(ast))
|
||||
case '{ EntityQuery(${ Expr(ast) }) } =>
|
||||
Some(EntityQuery(ast))
|
||||
|
@ -45,7 +57,7 @@ given FromExpr[EntityQuery[?]] with {
|
|||
}
|
||||
}
|
||||
}
|
||||
given FromExpr[Dsl] with {
|
||||
private given FromExpr[Dsl] with {
|
||||
def unapply(x: Expr[Dsl])(using Quotes): Option[Dsl] = {
|
||||
import quotes.reflect.*
|
||||
x match {
|
||||
|
|
Loading…
Reference in a new issue