Add property alist
This commit is contained in:
parent
17e97495b7
commit
2b52ef3203
3 changed files with 28 additions and 25 deletions
|
@ -4,8 +4,18 @@ import minisql.*
|
|||
import minisql.idiom.*
|
||||
import minisql.parsing.*
|
||||
import minisql.util.*
|
||||
import minisql.ast.{Ast, Entity, Map, Property, Ident, Filter, given}
|
||||
import minisql.ast.{
|
||||
Ast,
|
||||
Entity,
|
||||
Map,
|
||||
Property,
|
||||
Ident,
|
||||
Filter,
|
||||
PropertyAlias,
|
||||
given
|
||||
}
|
||||
import scala.quoted.*
|
||||
import scala.deriving.*
|
||||
import scala.compiletime.*
|
||||
import scala.compiletime.ops.string.*
|
||||
import scala.collection.immutable.{Map => IMap}
|
||||
|
@ -36,8 +46,17 @@ private inline def transform[A, B](inline q1: Quoted)(
|
|||
fast(q1, f.param0, f.body)
|
||||
}
|
||||
|
||||
inline def query[E](inline table: String): EntityQuery[E] =
|
||||
Entity(table, Nil)
|
||||
inline def alias(inline from: String, inline to: String): PropertyAlias =
|
||||
PropertyAlias(List(from), to)
|
||||
|
||||
inline def query[E](
|
||||
inline table: String,
|
||||
inline alias: PropertyAlias*
|
||||
): EntityQuery[E] =
|
||||
Entity(
|
||||
table,
|
||||
List(alias*)
|
||||
)
|
||||
|
||||
extension [A, B](inline f1: A => B) {
|
||||
private inline def param0 = parsing.parseParamAt(f1, 0)
|
||||
|
|
|
@ -43,27 +43,6 @@ object StatementInterpolator {
|
|||
implicit def liftTokenizer: Tokenizer[Lift] =
|
||||
Tokenizer[Lift] {
|
||||
case lift: ScalarLift => ScalarLiftToken(lift)
|
||||
case lift =>
|
||||
fail(
|
||||
s"Can't tokenize a non-scalar lifting. ${lift.name}\n" +
|
||||
s"\n" +
|
||||
s"This might happen because:\n" +
|
||||
s"* You are trying to insert or update an `Option[A]` field, but Scala infers the type\n" +
|
||||
s" to `Some[A]` or `None.type`. For example:\n" +
|
||||
s" run(query[Users].update(_.optionalField -> lift(Some(value))))" +
|
||||
s" In that case, make sure the type is `Option`:\n" +
|
||||
s" run(query[Users].update(_.optionalField -> lift(Some(value): Option[Int])))\n" +
|
||||
s" or\n" +
|
||||
s" run(query[Users].update(_.optionalField -> lift(Option(value))))\n" +
|
||||
s"\n" +
|
||||
s"* You are trying to insert or update whole Embedded case class. For example:\n" +
|
||||
s" run(query[Users].update(_.embeddedCaseClass -> lift(someInstance)))\n" +
|
||||
s" In that case, make sure you are updating individual columns, for example:\n" +
|
||||
s" run(query[Users].update(\n" +
|
||||
s" _.embeddedCaseClass.a -> lift(someInstance.a),\n" +
|
||||
s" _.embeddedCaseClass.b -> lift(someInstance.b)\n" +
|
||||
s" ))"
|
||||
)
|
||||
}
|
||||
|
||||
implicit def tokenTokenizer: Tokenizer[Token] = Tokenizer[Token](identity)
|
||||
|
|
|
@ -14,7 +14,12 @@ class QuotedSuite extends munit.FunSuite {
|
|||
import mirrorContext.given
|
||||
|
||||
test("SimpleQuery") {
|
||||
val o = mirrorContext.io(query[Foo]("foo").filter(_.id > 0))
|
||||
val o = mirrorContext.io(
|
||||
query[Foo](
|
||||
"foo",
|
||||
alias("id", "id1")
|
||||
).filter(_.id > 0)
|
||||
)
|
||||
println("============" + o)
|
||||
o
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue