You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
NOTE: THIS IS A PREVIEW TECHNOLOGY, FEATURES AND CONFIGURATION SETTINGS CAN CHANGE IN FUTURE RELEASES.
16
16
@@ -24,7 +24,6 @@ plugins {
24
24
}
25
25
```
26
26
27
-
28
27
## Configuration
29
28
30
29
You can configure any number of databases under the `sql.db` configuration scope. For example:
@@ -79,7 +78,7 @@ The following options are available:
79
78
80
79
`batchSize`
81
80
: Query the data in batches of the given size. This option is recommended for queries that may return large a large result set, so that the entire result set is not loaded into memory at once.
82
-
: *NOTE:* this feature requires that the underlying SQL database supports `LIMIT` and `OFFSET`.
81
+
: _NOTE:_ this feature requires that the underlying SQL database supports `LIMIT` and `OFFSET`.
83
82
84
83
`emitColumns`
85
84
: When `true`, the column names in the `SELECT` statement are emitted as the first tuple in the resulting channel.
INSERT INTO SAMPLE (NAME, LEN) VALUES ('WORLD!', 6);
105
104
```
106
105
107
-
*NOTE:* the target table (e.g. `SAMPLE` in the above example) must be created beforehand.
106
+
_NOTE:_ the target table (e.g. `SAMPLE` in the above example) must be created beforehand.
108
107
109
108
The following options are available:
110
109
@@ -125,7 +124,87 @@ The following options are available:
125
124
126
125
`setup`
127
126
: A SQL statement that is executed before inserting the data, e.g. to create the target table.
128
-
: *NOTE:* the underlying database should support the *create table if not exist* idiom, as the plugin will execute this statement every time the script is run.
127
+
: _NOTE:_ the underlying database should support the _create table if not exist_ idiom, as the plugin will execute this statement every time the script is run.
128
+
129
+
## SQL Execution Functions
130
+
131
+
This plugin provides the following function for executing SQL statements that don't return data, such as DDL (Data Definition Language) and DML (Data Manipulation Language) operations.
132
+
133
+
### sqlExecute
134
+
135
+
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 DML statements (`INSERT`, `UPDATE`, `DELETE`), it returns a Map with `success: true` and `result` set to the number of rows affected. For DDL statements (`CREATE`, `ALTER`, `DROP`), it returns a Map with `success: true` and `result: null`.
136
+
137
+
For example:
138
+
139
+
```nextflow
140
+
include { sqlExecute } from 'plugin/nf-sqldb'
141
+
142
+
// Create a table (returns Map with result: null for DDL operations)
: The database handle. It must be defined under `sql.db` in the Nextflow configuration.
181
+
182
+
`statement`
183
+
: The SQL statement to execute. This can be any DDL or DML statement that doesn't return a result set.
184
+
185
+
## Differences Between Dataflow Operators and Execution Function
186
+
187
+
The plugin provides two different ways to interact with databases:
188
+
189
+
1.**Dataflow Operators** (`fromQuery` and `sqlInsert`): These are designed to integrate with Nextflow's dataflow programming model, operating on channels.
190
+
191
+
-`fromQuery`: Queries data from a database and returns a channel that emits the results.
192
+
-`sqlInsert`: Takes data from a channel and inserts it into a database.
193
+
194
+
2.**Execution Function** (`sqlExecute`): This is designed for direct SQL statement execution that doesn't require channel integration.
195
+
-`sqlExecute`: Executes a SQL statement. For DML operations, it returns the count of affected rows. For DDL operations, it returns null.
196
+
197
+
Use **Dataflow Operators** when you need to:
198
+
199
+
- Query data that will flow into your pipeline processing
200
+
- Insert data from your pipeline processing into a database
- Perform one-off operations (deleting all records, truncating a table, etc.)
207
+
- Execute statements where you don't need the results as part of your dataflow
129
208
130
209
## Querying CSV files
131
210
@@ -159,4 +238,4 @@ The `CSVREAD` function provided by the H2 database engine allows you to query an
159
238
160
239
Like all dataflow operators in Nextflow, the operators provided by this plugin are executed asynchronously.
161
240
162
-
In particular, data inserted using the `sqlInsert` operator is *not* guaranteed to be available to any subsequent queries using the `fromQuery` operator, as it is not possible to make a channel factory operation dependent on some upstream operation.
241
+
In particular, data inserted using the `sqlInsert` operator is _not_ guaranteed to be available to any subsequent queries using the `fromQuery` operator, as it is not possible to make a channel factory operation dependent on some upstream operation.
0 commit comments