diff --git a/README.md b/README.md index 9b1519655d..343884b7c5 100644 --- a/README.md +++ b/README.md @@ -1981,6 +1981,7 @@ dynamicQuery[Person].insert(setOpt(_.name, Some("John"))) // it's also possible to use a runtime string value as the column name dynamicQuery[Person].update(set("name", quote("John"))) +dynamicQuery[Person].update(setOpt("name", Some("John"))) // to insert or update a case class instance, use `insertValue`/`updateValue` val p = Person(0, "John", 21) @@ -3319,4 +3320,4 @@ The project was created having Philip Wadler's talk ["A practical theory of lang * [A Practical Theory of Language-Integrated Query](http://homepages.inf.ed.ac.uk/slindley/papers/practical-theory-of-linq.pdf) * [Everything old is new again: Quoted Domain Specific Languages](http://homepages.inf.ed.ac.uk/wadler/papers/qdsl/qdsl.pdf) -* [The Flatter, the Better](http://db.inf.uni-tuebingen.de/staticfiles/publications/the-flatter-the-better.pdf) \ No newline at end of file +* [The Flatter, the Better](http://db.inf.uni-tuebingen.de/staticfiles/publications/the-flatter-the-better.pdf) diff --git a/quill-core/src/main/scala/io/getquill/dsl/DynamicQueryDSL.scala b/quill-core/src/main/scala/io/getquill/dsl/DynamicQueryDSL.scala index 10583197c2..53e5a6d69a 100644 --- a/quill-core/src/main/scala/io/getquill/dsl/DynamicQueryDSL.scala +++ b/quill-core/src/main/scala/io/getquill/dsl/DynamicQueryDSL.scala @@ -88,6 +88,12 @@ trait DynamicQueryDsl { case Some(v) => setValue(property, v) case None => DynamicSetEmpty() } + + def setOpt[T, U](property: String, value: Option[U])(implicit enc: Encoder[U]): DynamicSet[T, U] = + value match { + case Some(v) => setValue(property, v) + case None => DynamicSetEmpty() + } def set[T, U](property: String, value: Quoted[U]): DynamicSet[T, U] = set((f: Quoted[T]) => splice(Property(f.ast, property)), value)