From 5cc98f74adef04692ccb9feb75e7465bebc8e4d0 Mon Sep 17 00:00:00 2001 From: Ben Sherman Date: Thu, 6 Jul 2023 21:25:12 -0500 Subject: [PATCH 1/2] Add `trailingSemicolon` option Signed-off-by: Ben Sherman --- README.md | 3 +++ .../src/main/nextflow/sql/ChannelSqlExtension.groovy | 3 ++- plugins/nf-sqldb/src/main/nextflow/sql/QueryHandler.groovy | 5 ++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3d91dae..1711a21 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,9 @@ The following options are available: `emitColumns` : When `true`, the column names in the `SELECT` statement are emitted as the first tuple in the resulting channel. +`trailingSemicolon` +: WHen `true`, append a semicolon `;` to the end of the SQL query if it is not present (default: `true`). + ### sqlInsert The `sqlInsert` operator collects the items in a source channel and inserts them into a SQL database. For example: diff --git a/plugins/nf-sqldb/src/main/nextflow/sql/ChannelSqlExtension.groovy b/plugins/nf-sqldb/src/main/nextflow/sql/ChannelSqlExtension.groovy index b9791f8..87b0bdb 100644 --- a/plugins/nf-sqldb/src/main/nextflow/sql/ChannelSqlExtension.groovy +++ b/plugins/nf-sqldb/src/main/nextflow/sql/ChannelSqlExtension.groovy @@ -47,7 +47,8 @@ class ChannelSqlExtension extends PluginExtensionPoint { db: CharSequence, emitColumns: Boolean, batchSize: Integer, - batchDelay: Integer + batchDelay: Integer, + trailingSemicolon: Boolean ] private static final Map INSERT_PARAMS = [ diff --git a/plugins/nf-sqldb/src/main/nextflow/sql/QueryHandler.groovy b/plugins/nf-sqldb/src/main/nextflow/sql/QueryHandler.groovy index d7ea945..8a26255 100644 --- a/plugins/nf-sqldb/src/main/nextflow/sql/QueryHandler.groovy +++ b/plugins/nf-sqldb/src/main/nextflow/sql/QueryHandler.groovy @@ -70,6 +70,7 @@ class QueryHandler implements QueryOp { private boolean emitColumns = false private Integer batchSize private long batchDelayMillis = 100 + private boolean trailingSemicolon = true private int queryCount @Override @@ -97,6 +98,8 @@ class QueryHandler implements QueryOp { this.batchSize = opts.batchSize as Integer if( opts.batchDelay ) this.batchDelayMillis = opts.batchDelay as long + if( opts.trailingSemicolon ) + this.trailingSemicolon = opts.trailingSemicolon as boolean return this } @@ -127,7 +130,7 @@ class QueryHandler implements QueryOp { if( !q ) throw new IllegalArgumentException("Missing query argument") def result = q.trim() - if( !result.endsWith(';') ) + if( trailingSemicolon && !result.endsWith(';') ) result += ';' return result } From bf2244c05e5b99ed5dfb890fbf8a7fb668a6b16c Mon Sep 17 00:00:00 2001 From: Ben Sherman Date: Mon, 10 Jul 2023 10:30:37 -0500 Subject: [PATCH 2/2] Update README.md Co-authored-by: Paolo Di Tommaso --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1711a21..3decdfb 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,7 @@ The following options are available: : When `true`, the column names in the `SELECT` statement are emitted as the first tuple in the resulting channel. `trailingSemicolon` -: WHen `true`, append a semicolon `;` to the end of the SQL query if it is not present (default: `true`). +: When `true`, append a semicolon `;` to the end of the SQL query if it is not present (default: `true`). ### sqlInsert