Extension to help use `LOAD DATA LOCAL INFILE`
Description
Allows data to be imported by Exec(parameter) after using
special Data::Data as file path of LOAD DATA LOCAL INFILE.
It is easy to use instead of INSERT INTO.
This is easier to import than io.Reader when you want to import data generated from the program.
Implementation method.
- Add the
LOAD DATAflag to Prepare() and Exec(). - Exec() with
LOAD DATAflag set will send the parameter converted to TSV.
Sorry for the big patch. I don't think this is a change that everyone agrees with. I would like to ask you if such an extension is acceptable.
Checklist
- [x] Code compiles correctly
- [x] Created tests which fail without the change (if possible)
- [x] All tests passing
- [x] Extended the README / documentation, if necessary
- [x] Added myself / the copyright holder to the AUTHORS file
I don't like this design. My rough idea is:
// signature
mysql.LoadLocalInfile(conn sql.Conn, query string, file io.Reader)
// usage
import (
"database/sql"
"github.com/go-sql-driver/mysql"
)
// ...
conn := db.Conn()
err := mysql.LoadLocalInfile(conn, "LOAD LOCAL INFILE ... ", string.Reader(data))
// ...
As of Go 1.13, Conn.Raw is added. LoadLocalInfile can be implemented using it.
I don't like this design. My rough idea is:
I understand what you say.
LoadLocalInfile can be implemented using it.
Yes. I think it is good.
However, the io.Reader interface is not easy to handle the large stream data generated.
I wanted a mechanism to help that.