mysql icon indicating copy to clipboard operation
mysql copied to clipboard

Extension to help use `LOAD DATA LOCAL INFILE`

Open noborus opened this issue 5 years ago • 2 comments

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.

  1. Add the LOAD DATA flag to Prepare() and Exec().
  2. Exec() with LOAD DATA flag 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

noborus avatar Feb 13 '20 05:02 noborus

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.

methane avatar Feb 13 '20 06:02 methane

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.

noborus avatar Feb 13 '20 10:02 noborus