You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2022/01/31 06:40:49 UTC

[groovy-website] branch asf-site updated: add SQL ginq example to Groovy 4 release notes

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

paulk pushed a commit to branch asf-site
in repository https://gitbox.apache.org/repos/asf/groovy-website.git


The following commit(s) were added to refs/heads/asf-site by this push:
     new 5eb81ec  add SQL ginq example to Groovy 4 release notes
5eb81ec is described below

commit 5eb81ecbb60d325af2897b04b776226f80004723
Author: Paul King <pa...@asert.com.au>
AuthorDate: Mon Jan 31 16:40:44 2022 +1000

    add SQL ginq example to Groovy 4 release notes
---
 site/src/site/releasenotes/groovy-4.0.adoc | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/site/src/site/releasenotes/groovy-4.0.adoc b/site/src/site/releasenotes/groovy-4.0.adoc
index 40c52b7..94f25f3 100644
--- a/site/src/site/releasenotes/groovy-4.0.adoc
+++ b/site/src/site/releasenotes/groovy-4.0.adoc
@@ -881,6 +881,29 @@ assert GQ {
 }.toList() == ['Kakuda plum', 'Kiwifruit']
 --------------------------------------
 
+In a future Groovy version we hope to provide GQuery support for SQL databases
+where an optimised SQL query is generated based on the GQuery expression
+much like Groovy's DataSet functionality.
+In the meantime, for small volumes of data, you can use Groovy's standard
+SQL capabilities which return queries from the database as collections.
+Here is what the code would look like for a database with
+`Price` and `VitaminC` tables both having `name` and `per100g` columns:
+
+[source,groovy]
+--------------------------------------
+// ... create sql connection ...
+def price = sql.rows('SELECT * FROM Price')
+def vitC = sql.rows('SELECT * FROM VitaminC')
+assert GQ {
+    from p in price
+    join c in vitC on c.name == p.name
+    orderby c.per100g / p.per100g in desc
+    limit 2
+    select p.name
+}.toList() == ['Kakuda plum', 'Kiwifruit']
+// ... close connect ...
+--------------------------------------
+
 More examples could be found in the link:../using-ginq.html[GQuery documentation] (or directly in
 link:https://github.com/apache/groovy/blob/master/subprojects/groovy-ginq/src/spec/test/org/apache/groovy/ginq/GinqTest.groovy[the source repo]).