mysql.batch
mysql.batch
Function
Set the number of rows per batch for batch exec.
Syntax
mysql(dsn).query(sql).batch(size)
Parameters
| Parameters | Type | Required | Default value | Description |
|---|---|---|---|---|
| size | Int | No | 0 | Batch size; values less than 0 are treated as 0. |
Return value
| Type | Description |
|---|---|
| Mysql | Returns the new MySQL query builder. |
Example
rows = [['A'], ['B'], ['C']] db = mysql('mysql://user:pass@127.0.0.1/test') result = db.query('insert into user(name) values (?)').binds(rows).batch(2).sql() // Output: insert into user(name) values ('A'), ('B') /* binds: 3 rows, batch: 2, workers: 1 */ print result
Notes
- batch(0) means that all rows will be used for INSERT batch preview and optimization; non-INSERT execution will be processed in batches of 1 row.