Moved futured getSQL topic to another branch

This commit is contained in:
Cyrill Schumacher 2015-02-16 08:43:42 +11:00 committed by spf13
parent b209f44335
commit 41c0e82f95

View file

@ -140,55 +140,3 @@ your markdown files until the content has been downloaded.
- Photo gallery JSON powered: [https://github.com/pcdummy/hugo-lightslider-example](https://github.com/pcdummy/hugo-lightslider-example)
- Github Starred Repositories [in a posts](https://github.com/SchumacherFM/blog-cs/blob/master/content%2Fposts%2Fgithub-starred.md) with the related [short code](https://github.com/SchumacherFM/blog-cs/blob/master/layouts%2Fshortcodes%2FghStarred.html).
- more?
## The Future
### YAML and TOML
If the community demands the implementation of *getYaml*
[YAML](http://yaml.org/) or *getToml* [TOML](https://github.com/toml-lang/toml)
these functions will certainly follow.
### getSql
The outlook to support more sources is of course implementing SQL support. The following description is an initial idea and may change.
Maybe adding a new CLI option:
--sqlSource=path/to/filename.ext
#### `--sqlSource`
The file must start with `[mysql|postres|mssql|...]_[\w]+.ext`
The part before the first underscore specifies the driver to use, which can
be one from [https://github.com/golang/go/wiki/SQLDrivers](https://github.com/golang/go/wiki/SQLDrivers).
The file itself contains only the connection string and no other comments
or characters.
How the connection string looks like depends heavily on the used driver.
For MySQL:
hugo --sqlSource=path/to/mysql_credentials.txt
The file `mysql_credentials.txt` contains the connection string:
`username:password@protocol(address)/dbname?param=value` and nothing more!
In your template you can process `getSql` the same way as with
the `getJson` function:
{{ $rows := getSql "SELECT id,artist,genre,title FROM musicTable" }}
<ul>
{{range first 5 $rows }}
<li>#{{ .id }} {{.artist}}</a></li>
{{end}}
</ul>
Queries with `SELECT * FROM table` are of course also possible but
should not be used.
Returned **values** will be converted to **strings**.
Abusing `getSql` with [DML](http://en.wikipedia.org/wiki/Data_manipulation_language)
or [DDL](http://en.wikipedia.org/wiki/Data_definition_language) statements
causes Hugo to hang up.