Skip to content

functionreturnfunction/format-table

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

format-table https://travis-ci.org/functionreturnfunction/format-table.png?branch=master https://img.shields.io/coveralls/github/functionreturnfunction/format-table/master.svg https://melpa.org/packages/format-table-badge.svg

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.

Usage

(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)

Supported Formats

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.

JSON note

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"}]