mdtsql

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 22, 2026 License: MIT Imports: 15 Imported by: 0

README

mdtsql

PkgGoDev Actions Status

A CLI tool that executes SQL queries on various files including markdown table files and outputs the results to various files.

install

Go install
go install github.com/noborus/mdtsql/cmd/mdtsql@latest
Homebrew
brew install noborus/tap/mdtsql
Linux packages (deb/rpm)

Linux users can install prebuilt packages from the Github Releases page.

  • Debian/Ubuntu: *.deb
  • RHEL/Fedora/openSUSE: *.rpm

Asset names are published like this:

  • mdtsql_<version>_linux_amd64.deb
  • mdtsql_<version>_linux_amd64.rpm
  • mdtsql_<version>_linux_386.deb
  • mdtsql_<version>_linux_386.rpm
  • mdtsql_<version>_linux_arm64.deb
  • mdtsql_<version>_linux_arm64.rpm

Example:

# Debian/Ubuntu
sudo dpkg -i mdtsql_<version>_linux_amd64.deb

# RHEL/Fedora/openSUSE
sudo rpm -i mdtsql_<version>_linux_amd64.rpm

Download and install example (v0.1.0, amd64):

curl -fLO https://github.com/noborus/mdtsql/releases/download/v0.1.0/mdtsql_0.1.0_linux_amd64.deb
sudo dpkg -i mdtsql_0.1.0_linux_amd64.deb
Binary

Download the latest release from Github Releases

The following binaries can be downloaded from release.

  • Darwin_arm64
  • Darwin_x86_64
  • Linux_arm64
  • Linux_i386
  • Linux_x86_64
  • Windows_arm64
  • Windows_x86_64

To install a binary, download the appropriate file for your system, extract it, and place the mdtsql executable in a directory included in your system's PATH.

For example, on a Unix-like system, you might do:

tar xvf mdtsql_Darwin_x86_64.tar.gz
mv mdtsql /usr/local/bin/

Usage

Executes SQL for markdown containing table. The result can be output to CSV, JSON, LTSV, YAML, Markdown, etc.

mdtsql query "SELECT * FROM file.md"
mdtsql table file.md
option
mdtsql --help
Execute SQL for table in markdown.
The result can be output to CSV, JSON, LTSV, YAML, Markdown, etc.

Usage:
  mdtsql [flags]
  mdtsql [command]

Available Commands:
  completion  Generate the autocompletion script for the specified shell
  help        Help about any command
  list        List and analyze SQL dumps
  query       Execute SQL queries on markdown table and tabular data
  table       SQL(SELECT * FROM table) for markdown table and tabular data

Flags:
  -d, --Delimiter string   output delimiter (CSV only) (default ",")
  -O, --Header             output header (CSV only)
  -o, --OutFormat string   output format=at|csv|ltsv|json|jsonl|tbln|raw|md|vf|yaml (default "md")
  -c, --caption            caption table name
      --config string      config file (default is $HOME/.mdtsql.yaml)
      --debug              debug print
  -h, --help               help for mdtsql
  -v, --version            display version information

Use "mdtsql [command] --help" for more information about a command.
Example
mdtsql query "SELECT * FROM file.md"
c1 a b c
1 a1 b1 c1
2 a2 b2 c2
3 a3 b3 c3

If the markdown includes multiple tables, the second and subsequent tables are marked with ::number.

mdtsql query "SELECT * FROM file.md::1"

Specify the output format with option -o. -o csv, -o ltsv, -ojson ...

mdtsql -o csv query "SELECT * FROM file.md"
1,a1,b1,c1
2,a2,b2,c2
3,a3,b3,c3
List Command

The list command displays all the tables in the specified markdown file.

mdtsql list file.md
mdtsql list abc.md
Table Name: [0]
+-------------+------+
| column name | type |
+-------------+------+
| c1          | text |
| a           | text |
| b           | text |
| c           | text |
+-------------+------+

Table Name: [1]
+-------------+------+
| column name | type |
+-------------+------+
| c1          | text |
| a           | text |
| b           | text |
| c           | text |
+-------------+------+

Table Name: [2]
+-------------+------+
| column name | type |
+-------------+------+
| c1          | text |
| a           | text |
| b           | text |
| c           | text |
+-------------+------+

Table Command

The table command executes SQL(SELECT * FROM table) for markdown table and tabular data.

mdtsql table file.md
mdtsql table file.md::1

Caption option

The --caption or -c option specifies a caption name, not a sequential number. This allows you to specify the same table even if the order changes.

mdtsql --caption list testdata/abc.md
Table Name: [header]
+-------------+------+
| column name | type |
+-------------+------+
| c1          | text |
| a           | text |
| b           | text |
| c           | text |
+-------------+------+

Table Name: [caption]
+-------------+------+
| column name | type |
+-------------+------+
| c1          | text |
| a           | text |
| b           | text |
| c           | text |
+-------------+------+

Table Name: [caption_1]
+-------------+------+
| column name | type |
+-------------+------+
| c1          | text |
| a           | text |
| b           | text |
| c           | text |
+-------------+------+
mdtsql --caption query "SELECT * FROM testdata/abc.md::caption_1"
| c1 | a  | b  | c  |
|----|----|----|----|
|  1 | a1 | b1 | c1 |
|  2 | a2 | b2 | c2 |
|  3 | a3 | b3 | c3 |

Multiple queries

You can specify multiple queries with the ; separator.

mdtsql query "INSERT INTO abc.md::2 (c1, a, b, c) VALUES ('4', 'a4', 'b4', 'c4');SELECT * FROM abc.md::2"
c1 a b c
1 a1 b1 c1
2 a2 b2 c2
3 a3 b3 c3
4 a4 b4 c4
mdtsql query "UPDATE abc.md::2 SET c='u4' WHERE c1=3;SELECT * FROM abc.md::2"
c1 a b c
1 a1 b1 c1
2 a2 b2 c2
3 a3 b3 u4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Caption bool

Caption is a caption specification.

Functions

func Analyze

func Analyze(fileName string) ([]table, error)

Analyze parses the markdown file and returns the table information.

func Dump added in v0.1.0

func Dump(w io.Writer, tables []table)

Dump outputs the table information.

func NewMDTReader added in v0.1.0

func NewMDTReader(reader io.Reader, opts *trdsql.ReadOpts) (trdsql.Reader, error)

NewMDTReader returns a new MDTReader.

Types

type MDTReader added in v0.1.0

type MDTReader struct {
	// contains filtered or unexported fields
}

MDTReader is a reader for markdown table.

func (MDTReader) Names added in v0.1.0

func (t MDTReader) Names() ([]string, error)

func (MDTReader) PreReadRow added in v0.1.0

func (t MDTReader) PreReadRow() [][]any

func (MDTReader) ReadRow added in v0.1.0

func (t MDTReader) ReadRow(row []any) ([]any, error)

ReadRow only returns EOF.

func (MDTReader) Types added in v0.1.0

func (t MDTReader) Types() ([]string, error)

Directories

Path Synopsis
cmd
mdtsql command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL