hairyhenderson/gomplate

SQL datasource

Closed this issue · 3 comments

Hi,

Thanks for gomplate, it's gorgeous.

What do you think of adding SQL datasource ? I need to render from a PostgreSQL query.

Regards,
Étienne

Hi @bersace, thanks for filing this issue!

I've considered it in the past, but there are a few problems (at least):

  • low demand - I think you're the very first user to ask for it, and I had no personal need for it myself
  • doesn't map cleanly to the URL/filesystem model - what would the "file" be in this case? how to express a SQL query in a URL? the closest thing I could think of is something like postgres://user@pass:dbserver:5432/dbname?query=SELECT+foo,+bar+FROM+table, but that quickly gets untenable
  • SQL drivers are compile-time dependencies so I'd need to pick supported databases judiciously, and each time a new one is added that adds to the (already large) binary size...
  • how the returned data could be processed would be highly dependent on the query, and so it would be very difficult to write a template flexible enough to operate on different datasources

Ultimately I don't think I'm convinced that SQL as a datasource makes sense for gomplate. It's far more suited to simple k/v datasources.

As a workaround, you could easily write a script that queries the database, outputting the data as CSV, and then gomplate could template using that as an input. And if you really don't want to have a script wrapping it, you could even add it as a plugin!

I'm going to close this for now, but feel free to re-open if you have a compelling reason!

Thanks for such a detailed answer. I'll go with plugins.

A note about this, SQL allows export as JSON or CSV. This should ease writing a plugin.