Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add trailingSemicolon option #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
5 changes: 4 additions & 1 deletion plugins/nf-sqldb/src/main/nextflow/sql/QueryHandler.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class QueryHandler implements QueryOp<QueryHandler> {
private boolean emitColumns = false
private Integer batchSize
private long batchDelayMillis = 100
private boolean trailingSemicolon = true
private int queryCount

@Override
Expand Down Expand Up @@ -97,6 +98,8 @@ class QueryHandler implements QueryOp<QueryHandler> {
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
}

Expand Down Expand Up @@ -127,7 +130,7 @@ class QueryHandler implements QueryOp<QueryHandler> {
if( !q )
throw new IllegalArgumentException("Missing query argument")
def result = q.trim()
if( !result.endsWith(';') )
if( trailingSemicolon && !result.endsWith(';') )
result += ';'
return result
}
Expand Down