|
| 1 | +# Why |
| 2 | +Sometimes there is a need to update a database, based on data in an excel file. It can be |
| 3 | +data altered outside of a system or data that should be added to an existing data structure. |
| 4 | + |
| 5 | +Current sql output format is mysql-compatible-ish. |
| 6 | + |
| 7 | + |
| 8 | +# Example usages |
| 9 | + |
| 10 | +``` |
| 11 | +Usage: excel-2-sql [options] <file> <table> |
| 12 | +
|
| 13 | +Options: |
| 14 | + -V, --version output the version number |
| 15 | + -e|--example Show example data |
| 16 | + -m|--method <method> Method for sql, valid options: insert, update, replace |
| 17 | + -c|--column <column> Column to insert/update |
| 18 | + -w|--where <column> Column for where |
| 19 | + -f|--filter <column> Column to apply a filter for |
| 20 | + -h, --help output usage information |
| 21 | +``` |
| 22 | + |
| 23 | + |
| 24 | +## Insert data into existing table |
| 25 | +$ `./excel-2-sql example.xlsx example` |
| 26 | +``` |
| 27 | +-- Working with example.xlsx |
| 28 | +INSERT example SET id='1',firstname='jane',lastname='doe',department='it',age='32'; |
| 29 | +INSERT example SET id='2',firstname='john',lastname='doe',department='marketing',age='30'; |
| 30 | +INSERT example SET id='3',firstname='foo',lastname='bar',department='marketing',age='31'; |
| 31 | +INSERT example SET id='4',firstname='john',lastname='smith',department='finance',age='40'; |
| 32 | +INSERT example SET id='5',firstname='jane',lastname='smith',department='finance',age='40'; |
| 33 | +``` |
| 34 | + |
| 35 | + |
| 36 | +## Replace data in existing table (based on defined primary keys) |
| 37 | +$ `./excel-2-sql -m replace example.xlsx example` |
| 38 | + |
| 39 | +``` |
| 40 | +-- Working with example.xlsx |
| 41 | +REPLACE INTO example SET id='1',firstname='jane',lastname='doe',department='it',age='32'; |
| 42 | +REPLACE INTO example SET id='2',firstname='john',lastname='doe',department='marketing',age='30'; |
| 43 | +REPLACE INTO example SET id='3',firstname='foo',lastname='bar',department='marketing',age='31'; |
| 44 | +REPLACE INTO example SET id='4',firstname='john',lastname='smith',department='finance',age='40'; |
| 45 | +REPLACE INTO example SET id='5',firstname='jane',lastname='smith',department='finance',age='40'; |
| 46 | +``` |
| 47 | + |
| 48 | +## Update data in existing table (based on defined primary keys) |
| 49 | +$ `./excel-2-sql -w id -m update example.xlsx example` |
| 50 | + |
| 51 | +``` |
| 52 | +-- Working with example.xlsx |
| 53 | +UPDATE example SET id='1',firstname='jane',lastname='doe',department='it',age='32' WHERE id='1'; |
| 54 | +UPDATE example SET id='2',firstname='john',lastname='doe',department='marketing',age='30' WHERE id='2'; |
| 55 | +UPDATE example SET id='3',firstname='foo',lastname='bar',department='marketing',age='31' WHERE id='3'; |
| 56 | +UPDATE example SET id='4',firstname='john',lastname='smith',department='finance',age='40' WHERE id='4'; |
| 57 | +UPDATE example SET id='5',firstname='jane',lastname='smith',department='finance',age='40' WHERE id='5'; |
| 58 | +``` |
| 59 | + |
| 60 | +## Only update certain columns in existing table (based on defined primary keys) |
| 61 | +$ `./excel-2-sql -w id -m update -c firstname,lastname example.xlsx example` |
| 62 | + |
| 63 | +``` |
| 64 | +-- Working with example.xlsx |
| 65 | +UPDATE example SET firstname='jane',lastname='doe' WHERE id='1'; |
| 66 | +UPDATE example SET firstname='john',lastname='doe' WHERE id='2'; |
| 67 | +UPDATE example SET firstname='foo',lastname='bar' WHERE id='3'; |
| 68 | +UPDATE example SET firstname='john',lastname='smith' WHERE id='4'; |
| 69 | +UPDATE example SET firstname='jane',lastname='smith' WHERE id='5'; |
| 70 | +``` |
| 71 | + |
| 72 | +## Only update certain columns in existing table (based on defined primary keys) and filter by age |
| 73 | +$ `./excel-2-sql -w id -m update -c firstname,lastname -f "age>31" example.xlsx example` |
| 74 | + |
| 75 | +``` |
| 76 | +-- Working with example.xlsx |
| 77 | +UPDATE example SET firstname='jane',lastname='doe' WHERE id='1'; |
| 78 | +UPDATE example SET firstname='john',lastname='smith' WHERE id='4'; |
| 79 | +UPDATE example SET firstname='jane',lastname='smith' WHERE id='5'; |
| 80 | +``` |
| 81 | + |
0 commit comments