db.mysql: Add local_infile option to Config for LOAD DATA LOCAL INFILE support. #71
Describe the feature
Summary The db.mysql module currently does not support LOAD DATA LOCAL INFILE, which is the fastest way to bulk-load data into MySQL (typically 10-20x faster than multi-value INSERT statements). This is because MYSQL_OPT_LOCAL_INFILE must be set via mysql_options() before mysql_real_connect(), but DB.conn is a private field, making it impossible for users to call C.mysql_options() from outside the module.
Current Problem When bulk-loading a 570K-row, 61-column CSV file:
Multi-value INSERT (current approach): ~33 seconds LOAD DATA LOCAL INFILE (if available): estimated ~2-3 seconds The performance gap is significant for any data ingestion use case.
Proposed Solution Add a local_infile field to mysql.Config:
pub struct Config {
pub:
host string
port u32 = 3306
user string
password string
dbname string
local_infile bool = false // <-- new field
}```
In the connect() function, before calling C.mysql_real_connect():
```c
if config.local_infile {
C.mysql_options(conn, C.MYSQL_OPT_LOCAL_INFILE, &true_val)
}```
This is a minimal, backward-compatible change — local_infile defaults to false, so existing code is unaffected.
### Use Case
Use Case Example
```v
import db.mysql
mut db := mysql.connect(
host: '127.0.0.1'
port: 3306
user: 'root'
password: ''
dbname: 'mydb'
local_infile: true // <-- enable LOAD DATA LOCAL INFILE
)!```
// Now LOAD DATA LOCAL INFILE works
db.exec_none("LOAD DATA LOCAL INFILE '/path/to/data.csv' INTO TABLE mytable FIELDS TERMINATED BY ',' ENCLOSED BY '\"' LINES TERMINATED BY '\\n' IGNORE 1 LINES")
Alternative Considered
Using StmtHandle.execute() with prepared statements for batch inserts, but StmtHandle reallocates bind arrays on every call (see stmt.c.v:844), making it slower than multi-value INSERT for large batches.
### Proposed Solution
_No response_
### Other Information
_No response_
### Acknowledgements
- [ ] I may be able to implement this feature request
- [ ] This feature might incur a breaking change
### Version used
V lastest
### Environment details (OS name and version, etc.)
V version: latest
MySQL: 8.0+
OS: Linux (WSL)
> [!NOTE]
> You can use the 👍 reaction to increase the issue's priority for developers.
>
> Please note that only the 👍 reaction to the issue itself counts as a vote.
> Other reactions and those to comments will not be taken into account.