SQLtorial
Create your own SQL Tutorials with SQLtorial.
Motivation
SQLtorial is a gem I cooked up because I was frequently demonstrating how to write certain queries or how to explore data in certain databases. Generally, I wanted each example SQL statement to have a bit of explanation about how it works or what I’m looking for, followed by the query itself, followed by the results that SQL statement generated.
So I decided to write SQLtorial, a command that will process all files ending in *.sql and generate a Markdown document with all the examples concatenated together.
The gem will process each .sql statement in the following manner:
- The first line is considered the title for the entire example
- Comments placed above a SQL query will be run through a Markdown formatter and placed as formatted text before the SQL query
- SQL queries must end with a ;
- SQL queries are run through pgFormatter to create a consistent presentation for queries
- Results from the query are shown in a table after the query. Only the first ten results are shown.
See the examples directory.
Installation
Add this line to your application's Gemfile:
gem 'sqltorial'
And then execute:
$ bundle
Or install it yourself as:
$ gem install sqltorial
Usage
Create a directory for your SQL examples. Create at least one file ending with .sql
and add comments and example queries as you see fit.
When you are ready to execute your examples against a database and compile the examples into a markdown file, create a configuration file following the instructions in the sequelizer README.
Once your sequelizer configuration is set up, run
$ bundle exec sqltorial
The sqltorial
command will convert each .sql
file into a markdown and concatenate the files into a single markdown file called output.md
Development
After checking out the repo, run bin/setup
to install dependencies. Then, run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
to create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Contributing
- Fork it ( https://github.com/outcomesinsights/sqltorial/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Thanks
-
Outcomes Insights, Inc.
- Many thanks for allowing me to release a portion of my work as Open Source Software!
-
knitr
- Thanks for the inspiration!
License
Released under the MIT license, Copyright (c) 2015 Outcomes Insights, Inc.