mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
Add getSQL idea
This commit is contained in:
parent
fdf8db9c21
commit
47b7cfeb44
1 changed files with 35 additions and 1 deletions
|
@ -13,7 +13,7 @@ weight: 91
|
||||||
|
|
||||||
Dynamic content with a static site generator? Yes it is possible!
|
Dynamic content with a static site generator? Yes it is possible!
|
||||||
|
|
||||||
In addition to the [built-in variables](/templates/variables/) available from Hugo, you can specify your own custom data that can be accessed via templates or shortcodes.
|
Besides the [data files](/extras/datafiles/) available from Hugo, you can specify your own custom data that can be accessed via templates or shortcodes.
|
||||||
|
|
||||||
Hugo supports loading data from [YAML](http://yaml.org/), [JSON](http://www.json.org/), and [TOML](https://github.com/toml-lang/toml) files located in the `data` directory.
|
Hugo supports loading data from [YAML](http://yaml.org/), [JSON](http://www.json.org/), and [TOML](https://github.com/toml-lang/toml) files located in the `data` directory.
|
||||||
|
|
||||||
|
@ -26,3 +26,37 @@ As explained in [Source Organization](/overview/source-directory/), the `data` f
|
||||||
**The keys in this map will be a dot chained set of _path_, _filename_ and _key_ in file (if applicable).**
|
**The keys in this map will be a dot chained set of _path_, _filename_ and _key_ in file (if applicable).**
|
||||||
|
|
||||||
This is best explained with an example:
|
This is best explained with an example:
|
||||||
|
|
||||||
|
## The Future: getSQL
|
||||||
|
|
||||||
|
The outlook to support more sources is of course implementing SQL support.
|
||||||
|
|
||||||
|
Maybe adding two new CLI switches:
|
||||||
|
|
||||||
|
--sqlDriver=mysql|postres|mssql
|
||||||
|
--sqlSource=string|filename
|
||||||
|
|
||||||
|
#### `--sqlDriver`
|
||||||
|
|
||||||
|
specifies the driver to use which can be one from [https://github.com/golang/go/wiki/SQLDrivers](https://github.com/golang/go/wiki/SQLDrivers)
|
||||||
|
|
||||||
|
#### `--sqlSource`
|
||||||
|
|
||||||
|
You can either provide the connection string on the command file OR an existing file which contains the connection string.
|
||||||
|
|
||||||
|
How the connection string looks like depends heavily on the used driver. For MySQL:
|
||||||
|
|
||||||
|
hugo --sqlDriver=mysql \
|
||||||
|
--sqlSource=username:password@protocol(address)/dbname?param=value
|
||||||
|
|
||||||
|
or with a file name:
|
||||||
|
|
||||||
|
hugo --sqlDriver=mysql --sqlSource=path/to/myCredentials.txt
|
||||||
|
|
||||||
|
The file myCredentials.txt contains the connection string: `username:password@protocol(address)/dbname?param=value` and nothing more!
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
$data := getSQL "SELECT id,artist,genre,title from musicTable"
|
||||||
|
```
|
||||||
|
|
Loading…
Reference in a new issue