Skip to content

Commit

Permalink
Moved futured getSQL topic to another branch
Browse files Browse the repository at this point in the history
  • Loading branch information
SchumacherFM authored and tychoish committed Aug 13, 2017
1 parent 8520fb3 commit ea3dab7
Showing 1 changed file with 0 additions and 52 deletions.
52 changes: 0 additions & 52 deletions docs/content/extras/dynamiccontent.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

0 comments on commit ea3dab7

Please sign in to comment.