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: 9 months ago
JSON representation
Parse and reformat tabular data in emacs.
- Host: GitHub
- URL: https://github.com/functionreturnfunction/format-table
- Owner: functionreturnfunction
- Created: 2018-11-29T18:06:51.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-02-02T01:53:39.000Z (about 7 years ago)
- Last Synced: 2024-08-05T06:03:53.107Z (over 1 year ago)
- Topics: emacs, json, library, sql
- Language: Emacs Lisp
- Size: 75.2 KB
- Stars: 8
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.org
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