Search code examples
playframeworkyamlload-data-infile

Load data from file in Play framework YAML


I would like to load some data stored in a file into my mysql database when play is applying evolution to the database.
Basically when play is running the 1.sql to upgrade the database, I would like to run a "LOAD DATA INFILE" or equivalent.

Maybe there is an equivalent existing in yaml for LOAD DATA INFILE ?

If yes, how could I achieve something similar to
LOAD DATA INFILE "/path/to/myfile" INTO TABLE myTable FIELDS TERMINATED BY '|' LINES TERMINATED BY '\n';

Thanks


Solution

  • I found an alternative to this problem,

    in the global.java, when the application is restarted I check if my table is empty with
    if(Ebean.find(MyClass.class).findRowCount() == 0)
    and then I read my file in a classic way with FileInputStream, split the line with the java string split() function and update mysql table with the save() function of my model