Giter VIP home page Giter VIP logo

enkeksi's Introduction

enkeksi - Markdown-SQL evaluator

Python CI Coverate Status Documentation Status

Package author: Jukka Aho (@ahojukka5, [email protected])

enkeksi takes a markdown-formatted input and executes the sql queries found in it, and returns a markdown-formatted output where the results of the sql queries have been added. Package can be used, for example, to create a dynamic project documentation where SQL queries are automatically executed to get example results in a dynamic manner. This way it is easy to spot from the non-working documentation is there is problems with the database.

enkeksi comes with a command line tool markdown-sql-eval which can be used to process markdown files efficiently.

Project is hosted in GitHub: https://github.com/ahojukka5/enkeksi.

Documentation is hosted in ReadTheDocs: https://enkeksi.readthedocs.io/.

Releases are hosted in PyPi: https://pypi.org/project/enkeksi/.

Installing package

To install the most recent package from Python Package Index (PyPi), use git:

pip install enkeksi

To install the development version, you can install the package directly from the GitHub:

pip install git+git://github.com/ahojukka5/enkeksi.git

CLI Usage

Consider the following demo markdown file:

# Sample file

Hello, this is a sample file. Below, we initialize some test data to sqlite
database. It doesn't show in the final output, because of `--hide-input` flag.

```sql
--hide-input
CREATE TABLE Movies (id INTEGER PRIMARY KEY, name TEXT, year INTEGER);
INSERT INTO Movies (name, year) VALUES ("Snow White", 1937);
INSERT INTO Movies (name, year) VALUES ("Fantasia", 1940);
```

To list the content of the database, we need to use `SELECT` in SQL query. We
can use extra option `--caption='Table: Movies'` to add caption to output:

```sql
--hide-input --caption='Table: Movies'
SELECT * FROM Movies;
```

SQL results are formatted using [tabulate](https://pypi.org/project/tabulate/).
Using option `--table-format` we can change how the end results looks like.
By default, `psgl` is used and there rest options can be found from tabulate's
documentation. The total number of rows in database is:

```sql
--caption='With psql formatting'
SELECT COUNT(*) AS 'Number of movies in database' FROM Movies;
```

Option `--hide-headers` can be used to hide the header row of the result.

```sql
--table-format='github' --hide-headers --caption='With github formatting and headers removed'
SELECT COUNT(*) AS 'Now shown' FROM Movies;
```

Processing the file with markdown-sql-eval:

markdown-sql-eval examples/example2.md > examples/example2_rendered.md

Result is:

# Sample file

Hello, this is a sample file. Below, we initialize some test data to sqlite
database. It doesn't show in the final output, because of `--hide-input` flag.

To list the content of the database, we need to use `SELECT` in SQL query. We
can use extra option `--caption='Table: Movies'` to add caption to output:

```text
Table: Movies

+------+------------+--------+
|   id | name       |   year |
|------+------------+--------|
|    1 | Snow White |   1937 |
|    2 | Fantasia   |   1940 |
+------+------------+--------+
```

SQL results are formatted using [tabulate](https://pypi.org/project/tabulate/).
Using option `--table-format` we can change how the end results looks like.
By default, `psgl` is used and there rest options can be found from tabulate's
documentation. The total number of rows in database is:

```sql
SELECT COUNT(*) AS 'Number of movies in database' FROM Movies;
```

```text
With psql formatting

+--------------------------------+
|   Number of movies in database |
|--------------------------------|
|                              2 |
+--------------------------------+
```

Option `--hide-headers` can be used to hide the header row of the result.

```sql
SELECT COUNT(*) AS 'Now shown' FROM Movies;
```

```text
With github formatting and headers removed

|---|
| 2 |
```

The generated markdown file can then be added to your project documentation and hosted using e.g. mkdocs. For that idea, take a look of docs/demo.md, which is hosted in here, and generated from docs/demo_tmpl.md.

Contributing

Contributions are welcome as usual. If you have any good idea, and especially, a better name for a package, raise an issue.

enkeksi's People

Contributors

ahojukka5 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

enkeksi's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.