Emacs can access many RDBMS systems via their command-line utilities using SQLi/comint, however each utility has its own output format for tables and affected row counts. This library allows for conversion between the output formats of many common RDBMS systems, as well as org tables and json.
(format-table string-containing-table input-mode-to-match-string desired-output-mode)
For instance, to reformat an org-mode table, do the following:
(let ((to-format
"
| Foo | Bar |
|-----+-----|
| 1 | 2 |
| 3 | 4 |"))
(format-table to-format 'org 'mysql))
Which will render the following output:
+-----+-----+ | Foo | Bar | +-----+-----+ | 1 | 2 | | 3 | 4 | +-----+-----+ 2 rows in set (0.00 sec)
The following input/output formats are currently supported:
- ms
- org
- mysql
- postgresql
- json
New formats can be added by adding them to `format-table-format-alist’ at runtime.
Currently only exporting/importing arrays of hashes is supported. For instance, that previous org table:
(let ((to-format
"
| Foo | Bar |
|-----+-----|
| 1 | 2 |
| 3 | 4 |"))
(format-table to-format 'org 'json))
Will render as:
[{"Foo":"1","Bar":"2"},{"Foo":"3","Bar":"4"}]