Skip to content

Commit

Permalink
Merge pull request #100 from Grupo-Abraxas/CU-jpz3xw_Improve-field-se…
Browse files Browse the repository at this point in the history
…rvice-creation

Cu jpz3xw improve field service creation
  • Loading branch information
krabbit93 committed Mar 4, 2021
2 parents cba8d56 + 3f4dc98 commit 21267c3
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import cats.data.{ Ior, NonEmptyList }
import cats.instances.list._
import cats.instances.option._

import com.arkondata.slothql.cypher.syntax.LiftedMap

trait CypherFragment {
type Statement <: CypherStatement

Expand Down Expand Up @@ -496,6 +498,10 @@ object CypherFragment {
}
}

case class SetNode(to: Expr[Map[String, _]], props: Expr[Map[String, Expr[_]]]) extends Write

case class ExtendNode(to: Expr[Map[String, _]], props: Expr[Map[String, Expr[_]]]) extends Write

def toCypher(clause: Clause): GenS[Part] = clause match {
case Match(pattern, optional, where) =>
for {
Expand All @@ -517,6 +523,18 @@ object CypherFragment {
} yield s"WITH $ret$where"
case Create(pattern) => partsSequence(pattern.toList).map(ps => s"CREATE ${ps.mkString(", ")}")
case SetProps(set) => partsSequence(set.toList).map(ss => s"SET ${ss.mkString(", ")}")
case SetNode(n, props0) =>
for {
name <- part(n)
props <- part(props0)
set <- GenS.part(s"SET $name = $props")
} yield set
case ExtendNode(n, props0) =>
for {
name <- part(n)
props <- part(props0)
set <- GenS.part(s"SET $name += $props")
} yield set
case Delete(elems, detach) =>
val detachStr = if (detach) "DETACH " else ""
partsSequence(elems.toList).map(es => s"${detachStr}DELETE ${es.mkString(", ")}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,16 @@ package object syntax extends CypherSyntaxLowPriorityImplicits {
CF.Clause.SetProps(NonEmptyList(prop, props.toList)),
res
)

def apply[R](setNode: CF.Clause.SetNode)(res: Query[R]): Query[R] = CF.Query.Clause(
setNode,
res
)

def apply[R](setNode: CF.Clause.ExtendNode)(res: Query[R]): Query[R] = CF.Query.Clause(
setNode,
res
)
}

object Delete {
Expand Down Expand Up @@ -879,6 +889,13 @@ package object syntax extends CypherSyntaxLowPriorityImplicits {
def updateDynamic[V](prop: String)(value: Expr[V]): Update.Prop =
CF.Clause.SetProps.One(e.asInstanceOf[Expr[Map[String, Any]]], prop, value)
}

def :=(props: Expr[Map[String, Expr[_]]]): CF.Clause.SetNode =
CF.Clause.SetNode(e.asInstanceOf[Expr[Map[String, Any]]], props)

def +=(props: Expr[Map[String, Expr[_]]]): CF.Clause.ExtendNode =
CF.Clause.ExtendNode(e.asInstanceOf[Expr[Map[String, Any]]], props)

def setProp: set.type = set
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,30 @@ class CypherSyntaxWriteSpec extends CypherSyntaxBaseSpec {
"RETURN `id`(`n0`)"
).returns[Long]

"support settings node properties from map" in
test(
Match { case n @ Node("id" := "123") =>
Update(n := lit(Map("foo" -> lit("qwerty")))) {
n.id
}
},
"MATCH (`n0`{ `id`: \"123\" }) " +
"SET `n0` = {`foo`: \"qwerty\"} " +
"RETURN `id`(`n0`)"
).returns[Long]

"support settings node properties from map extending properties" in
test(
Match { case n @ Node("id" := "123") =>
Update(n += lit(Map("foo" -> lit("qwerty")))) {
n.id
}
},
"MATCH (`n0`{ `id`: \"123\" }) " +
"SET `n0` += {`foo`: \"qwerty\"} " +
"RETURN `id`(`n0`)"
).returns[Long]

"support setting relationship properties" in
test(
Match { case (a @ Node("A")) - (e @ Rel("E")) > (b @ Node("B")) =>
Expand Down

0 comments on commit 21267c3

Please sign in to comment.