Import .sql files
pounard opened this issue · comments
For project setup we oftenly need a file import procedure.
Difficulty resides in the fact that we need to parse the file, taking care of escape sequences and split file using the ;
separator into a list of SQL commands.
Ideally:
- Split file using the
;
separator, while preserving those in escape sequences, this must depend upon the driver because each SQL dialect has its own escape sequences. - Cleanup lines and remove end of lines that start with
--
. - Some SQL servers also consider comments starting with
//
or being enclosed in/* */
, handle that as well. - Remove cleanup statements that end up being empty.
- Ideally, do this without storing the file into memory, stream parsing and execute statements as we go.
- The import file parser must be agnostic of what's consuming it, a callable should be provided to handle statements.
- Write a command for parsing a file and outputing using a normalized output, for debugging.