Skip to content

Commit ac469c6

Browse files
refactor: Rename execute function to sqlExecute and update documentation
- Renamed the `execute` function to `sqlExecute` for clarity and consistency. - Updated all references in the README, example scripts, and tests to reflect the new function name. - Enhanced documentation to provide clearer usage examples for SQL execution functions. Signed-off-by: Edmund Miller <[email protected]> Co-authored-by: Edmund Miller <[email protected]> Co-authored-by: Paolo Di Tommaso <[email protected]>
1 parent a5f1073 commit ac469c6

File tree

6 files changed

+32
-32
lines changed

6 files changed

+32
-32
lines changed

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,15 @@ The following options are available:
131131

132132
This plugin provides the following functions for executing SQL statements that don't return data, such as DDL (Data Definition Language) and DML (Data Manipulation Language) operations.
133133

134-
### execute
134+
### sqlExecute
135135

136-
The `execute` function executes a SQL statement that doesn't return a result set, such as `CREATE`, `ALTER`, `DROP`, `INSERT`, `UPDATE`, or `DELETE` statements. For example:
136+
The `sqlExecute` function executes a SQL statement that doesn't return a result set, such as `CREATE`, `ALTER`, `DROP`, `INSERT`, `UPDATE`, or `DELETE` statements. For example:
137137

138138
```nextflow
139-
include { execute } from 'plugin/nf-sqldb'
139+
include { sqlExecute } from 'plugin/nf-sqldb'
140140
141141
// Create a table
142-
execute(
142+
sqlExecute(
143143
db: 'foo',
144144
statement: '''
145145
CREATE TABLE IF NOT EXISTS sample_table (
@@ -151,13 +151,13 @@ execute(
151151
)
152152
153153
// Insert data
154-
execute(
154+
sqlExecute(
155155
db: 'foo',
156156
statement: "INSERT INTO sample_table (id, name, value) VALUES (1, 'alpha', 10.5)"
157157
)
158158
159159
// Delete data
160-
execute(
160+
sqlExecute(
161161
db: 'foo',
162162
statement: "DELETE FROM sample_table WHERE id = 1"
163163
)
@@ -173,7 +173,7 @@ The following options are available:
173173

174174
### executeUpdate
175175

176-
The `executeUpdate` function is similar to `execute`, but it returns the number of rows affected by the SQL statement. This is particularly useful for DML operations like `INSERT`, `UPDATE`, and `DELETE` where you need to know how many rows were affected. For example:
176+
The `executeUpdate` function is similar to `sqlExecute`, but it returns the number of rows affected by the SQL statement. This is particularly useful for DML operations like `INSERT`, `UPDATE`, and `DELETE` where you need to know how many rows were affected. For example:
177177

178178
```nextflow
179179
include { executeUpdate } from 'plugin/nf-sqldb'
@@ -216,8 +216,8 @@ The plugin provides two different ways to interact with databases:
216216
- `fromQuery`: Queries data from a database and returns a channel that emits the results.
217217
- `sqlInsert`: Takes data from a channel and inserts it into a database.
218218

219-
2. **Execution Functions** (`execute` and `executeUpdate`): These are designed for direct SQL statement execution that doesn't require channel integration.
220-
- `execute`: Executes a SQL statement without returning any data.
219+
2. **Execution Functions** (`sqlExecute` and `executeUpdate`): These are designed for direct SQL statement execution that doesn't require channel integration.
220+
- `sqlExecute`: Executes a SQL statement without returning any data.
221221
- `executeUpdate`: Executes a SQL statement and returns the count of affected rows.
222222

223223
Use **Dataflow Operators** when you need to:

examples/sql-execution/main.nf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/usr/bin/env nextflow
22

33
/*
4-
* Example script demonstrating how to use the SQL execute and executeUpdate functions
4+
* Example script demonstrating how to use the SQL sqlExecute and executeUpdate functions
55
*/
66

7-
include { execute; executeUpdate } from 'plugin/nf-sqldb'
7+
include { sqlExecute; executeUpdate } from 'plugin/nf-sqldb'
88
include { fromQuery } from 'plugin/nf-sqldb'
99

1010
// Define database configuration in nextflow.config file

plugins/nf-sqldb/src/main/nextflow/sql/ChannelSqlExtension.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ class ChannelSqlExtension extends PluginExtensionPoint {
149149
* @param params A map containing 'db' (database alias) and 'statement' (SQL string to execute)
150150
*/
151151
@Function
152-
void execute(Map params) {
153-
CheckHelper.checkParams('execute', params, EXECUTE_PARAMS)
152+
void sqlExecute(Map params) {
153+
CheckHelper.checkParams('sqlExecute', params, EXECUTE_PARAMS)
154154

155155
final String dbName = params.db as String ?: 'default'
156156
final String statement = params.statement as String

plugins/nf-sqldb/src/main/nextflow/sql/QueryHandler.groovy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ class QueryHandler implements QueryOp<QueryHandler> {
5252
type_mapping.TINYINT = Byte
5353
type_mapping.SMALLINT = Short
5454
type_mapping.INTEGER = Integer
55-
type_mapping.BIGINT = Long
55+
type_mapping.BIGINT = Long
5656
type_mapping.REAL= Float
5757
type_mapping.FLOAT= Double
58-
type_mapping.DOUBLE = Double
59-
type_mapping.BINARY = byte[]
58+
type_mapping.DOUBLE = Double
59+
type_mapping.BINARY = byte[]
6060
type_mapping.VARBINARY = byte[]
6161
type_mapping.LONGVARBINARY= byte[]
6262
type_mapping.DATE = java.sql.Date

plugins/nf-sqldb/src/test/nextflow/sql/SqlExecutionTest.groovy

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class SqlExecutionTest extends Specification {
5353
sqlExtension.init(session)
5454

5555
when: 'Creating a table'
56-
sqlExtension.execute([
56+
sqlExtension.sqlExecute([
5757
db: 'test',
5858
statement: 'CREATE TABLE test_table(id INT PRIMARY KEY, name VARCHAR(255))'
5959
])
@@ -62,7 +62,7 @@ class SqlExecutionTest extends Specification {
6262
sql.rows('SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = \'TEST_TABLE\'').size() > 0
6363

6464
when: 'Altering the table'
65-
sqlExtension.execute([
65+
sqlExtension.sqlExecute([
6666
db: 'test',
6767
statement: 'ALTER TABLE test_table ADD COLUMN description VARCHAR(255)'
6868
])
@@ -71,7 +71,7 @@ class SqlExecutionTest extends Specification {
7171
sql.rows('SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = \'TEST_TABLE\' AND COLUMN_NAME = \'DESCRIPTION\'').size() > 0
7272

7373
when: 'Dropping the table'
74-
sqlExtension.execute([
74+
sqlExtension.sqlExecute([
7575
db: 'test',
7676
statement: 'DROP TABLE test_table'
7777
])
@@ -96,7 +96,7 @@ class SqlExecutionTest extends Specification {
9696
sqlExtension.init(session)
9797

9898
when: 'Inserting data'
99-
sqlExtension.execute([
99+
sqlExtension.sqlExecute([
100100
db: 'test',
101101
statement: 'INSERT INTO test_dml (id, name, value) VALUES (1, \'item1\', 100)'
102102
])
@@ -106,7 +106,7 @@ class SqlExecutionTest extends Specification {
106106
sql.firstRow('SELECT * FROM test_dml WHERE id = 1').name == 'item1'
107107

108108
when: 'Updating data'
109-
sqlExtension.execute([
109+
sqlExtension.sqlExecute([
110110
db: 'test',
111111
statement: 'UPDATE test_dml SET value = 200 WHERE id = 1'
112112
])
@@ -115,7 +115,7 @@ class SqlExecutionTest extends Specification {
115115
sql.firstRow('SELECT value FROM test_dml WHERE id = 1').value == 200
116116

117117
when: 'Deleting data'
118-
sqlExtension.execute([
118+
sqlExtension.sqlExecute([
119119
db: 'test',
120120
statement: 'DELETE FROM test_dml WHERE id = 1'
121121
])
@@ -186,7 +186,7 @@ class SqlExecutionTest extends Specification {
186186
sqlExtension.init(session)
187187

188188
when: 'Executing invalid SQL'
189-
sqlExtension.execute([
189+
sqlExtension.sqlExecute([
190190
db: 'test',
191191
statement: 'INVALID SQL STATEMENT'
192192
])
@@ -195,7 +195,7 @@ class SqlExecutionTest extends Specification {
195195
thrown(Exception)
196196

197197
when: 'Executing query with invalid table name'
198-
sqlExtension.execute([
198+
sqlExtension.sqlExecute([
199199
db: 'test',
200200
statement: 'SELECT * FROM non_existent_table'
201201
])
@@ -213,7 +213,7 @@ class SqlExecutionTest extends Specification {
213213
sqlExtension.init(session)
214214

215215
when: 'Using non-existent database alias'
216-
sqlExtension.execute([
216+
sqlExtension.sqlExecute([
217217
db: 'non_existent_db',
218218
statement: 'SELECT 1'
219219
])
@@ -222,15 +222,15 @@ class SqlExecutionTest extends Specification {
222222
thrown(IllegalArgumentException)
223223

224224
when: 'Missing statement parameter'
225-
sqlExtension.execute([
225+
sqlExtension.sqlExecute([
226226
db: 'test'
227227
])
228228

229229
then: 'Should throw an IllegalArgumentException'
230230
thrown(IllegalArgumentException)
231231

232232
when: 'Empty statement parameter'
233-
sqlExtension.execute([
233+
sqlExtension.sqlExecute([
234234
db: 'test',
235235
statement: ''
236236
])
@@ -252,7 +252,7 @@ class SqlExecutionTest extends Specification {
252252
sqlExtension.init(session)
253253

254254
when: 'Executing statement without semicolon'
255-
sqlExtension.execute([
255+
sqlExtension.sqlExecute([
256256
db: 'test',
257257
statement: 'CREATE TABLE test_norm(id INT PRIMARY KEY)'
258258
])
@@ -261,7 +261,7 @@ class SqlExecutionTest extends Specification {
261261
sql.rows('SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = \'TEST_NORM\'').size() > 0
262262

263263
when: 'Executing statement with trailing whitespace'
264-
sqlExtension.execute([
264+
sqlExtension.sqlExecute([
265265
db: 'test',
266266
statement: 'DROP TABLE test_norm '
267267
])

plugins/nf-sqldb/src/testResources/testDir/test_sql_db.nf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
nextflow.enable.dsl=2
22

3-
include { fromQuery; sqlInsert; execute; executeUpdate } from 'plugin/nf-sqldb'
3+
include { fromQuery; sqlInsert; sqlExecute; executeUpdate } from 'plugin/nf-sqldb'
44

55
workflow {
66
// Setup: create table
7-
execute(
7+
sqlExecute(
88
db: 'foo',
99
statement: '''
10-
CREATE TABLE IF NOT EXISTS sample_table (
10+
CREATE TABLE IF NOT EXISTS testing (
1111
id INTEGER PRIMARY KEY,
1212
name VARCHAR(100),
1313
value DOUBLE

0 commit comments

Comments
 (0)