Datasette plugin for executing SQL queries from templates
Project description
datasette-template-sql
Datasette plugin for executing SQL queries from templates.
This plugin makes a new function, sql(sql_query), available to your Datasette templates.
You can use it like this:
{% for row in sql("select 1 + 1 as two, 2 * 4 as eight") %}
{% for key in row.keys() %}
{{ key }}: {{ row[key] }}<br>
{% endfor %}
{% endfor %}
The plugin will execute SQL against the current database for the page in database.html, table.html and row.html templates. If a template does not have a current database (index.html for example) the query will execute against the first attached database.
You can pass an optional second argument to specify a named database to use for the query. For example, if you have attached a news.db database you could use this:
{% for article in sql(
"select headline, date, summary from articles order by date desc limit 5",
"news"
) %}
<h3>{{ article.headline }}</h2>
<p class="date">{{ article.date }}</p>
<p>{{ article.summary }}</p>
{% endfor %}
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file datasette_template_sql-0.1-py3-none-any.whl.
File metadata
- Download URL: datasette_template_sql-0.1-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.6.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
22394a1ba13d62b7db7b64b766ea57616f4431a6868cb2a32a5f9cfc5c07cb60
|
|
| MD5 |
cfc7c24d6a4f6e2ef9a246c0d4e717e8
|
|
| BLAKE2b-256 |
237a607305faced4ec8b412449aaf97fbcf63ec4f345bdfa4f4259ae1ab464dc
|