You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2020/12/12 15:28:06 UTC

[groovy] branch master updated: Update the user guide of GINQ to add a tip about `update` like SQL's

This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new 7ed6be4  Update the user guide of GINQ to add a tip about `update` like SQL's
7ed6be4 is described below

commit 7ed6be4b46d2102890c573a8880f651aca3bdd86
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sat Dec 12 23:25:15 2020 +0800

    Update the user guide of GINQ to add a tip about `update` like SQL's
---
 .../groovy-ginq/src/spec/doc/ginq-userguide.adoc   |  7 ++++++
 .../test/org/apache/groovy/ginq/GinqTest.groovy    | 28 ++++++++++++++++++++++
 2 files changed, 35 insertions(+)

diff --git a/subprojects/groovy-ginq/src/spec/doc/ginq-userguide.adoc b/subprojects/groovy-ginq/src/spec/doc/ginq-userguide.adoc
index f8bf655..78dcaf5 100644
--- a/subprojects/groovy-ginq/src/spec/doc/ginq-userguide.adoc
+++ b/subprojects/groovy-ginq/src/spec/doc/ginq-userguide.adoc
@@ -444,6 +444,13 @@ include::../test/org/apache/groovy/ginq/GinqTest.groovy[tags=ginq_tips_03,indent
 include::../test/org/apache/groovy/ginq/GinqTest.groovy[tags=ginq_tips_04,indent=0]
 ----
 
+==== Query & Update
+This is like `update` in SQL
+[source, groovy]
+----
+include::../test/org/apache/groovy/ginq/GinqTest.groovy[tags=ginq_tips_07,indent=0]
+----
+
 ==== Customize GINQ
 
 For advanced users, you could customize GINQ behaviour by specifying your own target code generator.
diff --git a/subprojects/groovy-ginq/src/spec/test/org/apache/groovy/ginq/GinqTest.groovy b/subprojects/groovy-ginq/src/spec/test/org/apache/groovy/ginq/GinqTest.groovy
index 2b555b3..aed26ab 100644
--- a/subprojects/groovy-ginq/src/spec/test/org/apache/groovy/ginq/GinqTest.groovy
+++ b/subprojects/groovy-ginq/src/spec/test/org/apache/groovy/ginq/GinqTest.groovy
@@ -3083,6 +3083,34 @@ class GinqTest {
     }
 
     @Test
+    void "testGinq - GINQ tips - 3"() {
+        assertGinqScript '''
+// tag::ginq_tips_07[]
+            import groovy.transform.*
+            @TupleConstructor
+            @EqualsAndHashCode
+            @ToString
+            class Person {
+                String name
+                String nickname
+            }
+            
+            def persons = [new Person('Daniel', 'ShanFengXiaoZi'), new Person('Linda', null), new Person('David', null)]
+            def result = GQ {
+                from p in persons
+                where p.nickname == null
+                select p
+            }.stream()
+                .peek(p -> { p.nickname = 'Unknown' }) // update `nickname`
+                .toList()
+            
+            def expected = [new Person('Linda', 'Unknown'), new Person('David', 'Unknown')]
+            assert expected == result
+// end::ginq_tips_07[]
+        '''
+    }
+
+    @Test
     void "testGinq - GINQ examples - 1"() {
         assertGinqScript '''
             def expected =