Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/functionreturnfunction/format-table

Parse and reformat tabular data in emacs.
https://github.com/functionreturnfunction/format-table

emacs json library sql

Last synced: 3 months ago
JSON representation

Parse and reformat tabular data in emacs.

Awesome Lists containing this project

README

        

* format-table [[https://travis-ci.org/functionreturnfunction/format-table][https://travis-ci.org/functionreturnfunction/format-table.png?branch=master]] [[https://coveralls.io/github/functionreturnfunction/format-table][https://img.shields.io/coveralls/github/functionreturnfunction/format-table/master.svg]] [[http://melpa.org/#/format-table][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

#+BEGIN_SRC emacs-lisp
(format-table string-containing-table input-mode-to-match-string desired-output-mode)
#+END_SRC

For instance, to reformat an org-mode table, do the following:
#+BEGIN_SRC emacs-lisp
(let ((to-format
"
| Foo | Bar |
|-----+-----|
| 1 | 2 |
| 3 | 4 |"))
(format-table to-format 'org 'mysql))
#+END_SRC

Which will render the following output:
#+BEGIN_SRC
+-----+-----+
| Foo | Bar |
+-----+-----+
| 1 | 2 |
| 3 | 4 |
+-----+-----+
2 rows in set (0.00 sec)
#+END_SRC

** 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:

#+BEGIN_SRC emacs-lisp
(let ((to-format
"
| Foo | Bar |
|-----+-----|
| 1 | 2 |
| 3 | 4 |"))
(format-table to-format 'org 'json))
#+END_SRC

Will render as:
#+BEGIN_SRC javascript
[{"Foo":"1","Bar":"2"},{"Foo":"3","Bar":"4"}]
#+END_SRC