Move non-metadata configuration from metadata.yaml to datasette.yaml

* Allow and permission blocks moved to datasette.yaml
* Documentation updates, initial framework for configuration reference
This commit is contained in:
Alex Garcia 2023-10-12 09:16:37 -07:00 committed by GitHub
commit 35deaabcb1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 595 additions and 493 deletions

View file

@ -71,11 +71,11 @@ You can also use the `sqlite-utils <https://sqlite-utils.datasette.io/>`__ tool
Canned queries
--------------
As an alternative to adding views to your database, you can define canned queries inside your ``metadata.yaml`` file. Here's an example:
As an alternative to adding views to your database, you can define canned queries inside your ``datasette.yaml`` file. Here's an example:
.. [[[cog
from metadata_doc import metadata_example
metadata_example(cog, {
from metadata_doc import config_example, config_example
config_example(cog, {
"databases": {
"sf-trees": {
"queries": {
@ -88,7 +88,7 @@ As an alternative to adding views to your database, you can define canned querie
})
.. ]]]
.. tab:: YAML
.. tab:: datasette.yaml
.. code-block:: yaml
@ -99,7 +99,7 @@ As an alternative to adding views to your database, you can define canned querie
sql: select qSpecies from Street_Tree_List
.. tab:: JSON
.. tab:: datasette.json
.. code-block:: json
@ -147,11 +147,11 @@ Here's an example of a canned query with a named parameter:
where neighborhood like '%' || :text || '%'
order by neighborhood;
In the canned query metadata looks like this:
In the canned query configuration looks like this:
.. [[[cog
metadata_example(cog, yaml="""
config_example(cog, """
databases:
fixtures:
queries:
@ -166,10 +166,11 @@ In the canned query metadata looks like this:
""")
.. ]]]
.. tab:: YAML
.. tab:: datasette.yaml
.. code-block:: yaml
databases:
fixtures:
queries:
@ -182,7 +183,8 @@ In the canned query metadata looks like this:
where neighborhood like '%' || :text || '%'
order by neighborhood
.. tab:: JSON
.. tab:: datasette.json
.. code-block:: json
@ -210,7 +212,7 @@ In this example the ``:text`` named parameter is automatically extracted from th
You can alternatively provide an explicit list of named parameters using the ``"params"`` key, like this:
.. [[[cog
metadata_example(cog, yaml="""
config_example(cog, """
databases:
fixtures:
queries:
@ -227,10 +229,11 @@ You can alternatively provide an explicit list of named parameters using the ``"
""")
.. ]]]
.. tab:: YAML
.. tab:: datasette.yaml
.. code-block:: yaml
databases:
fixtures:
queries:
@ -245,7 +248,8 @@ You can alternatively provide an explicit list of named parameters using the ``"
where neighborhood like '%' || :text || '%'
order by neighborhood
.. tab:: JSON
.. tab:: datasette.json
.. code-block:: json
@ -290,7 +294,7 @@ You can set a default fragment hash that will be included in the link to the can
This example demonstrates both ``fragment`` and ``hide_sql``:
.. [[[cog
metadata_example(cog, yaml="""
config_example(cog, """
databases:
fixtures:
queries:
@ -304,10 +308,11 @@ This example demonstrates both ``fragment`` and ``hide_sql``:
""")
.. ]]]
.. tab:: YAML
.. tab:: datasette.yaml
.. code-block:: yaml
databases:
fixtures:
queries:
@ -319,7 +324,8 @@ This example demonstrates both ``fragment`` and ``hide_sql``:
from facetable join facet_cities on facetable.city_id = facet_cities.id
where neighborhood like '%' || :text || '%' order by neighborhood;
.. tab:: JSON
.. tab:: datasette.json
.. code-block:: json
@ -350,7 +356,7 @@ Canned queries by default are read-only. You can use the ``"write": true`` key t
See :ref:`authentication_permissions_query` for details on how to add permission checks to canned queries, using the ``"allow"`` key.
.. [[[cog
metadata_example(cog, {
config_example(cog, {
"databases": {
"mydatabase": {
"queries": {
@ -364,7 +370,7 @@ See :ref:`authentication_permissions_query` for details on how to add permission
})
.. ]]]
.. tab:: YAML
.. tab:: datasette.yaml
.. code-block:: yaml
@ -376,7 +382,7 @@ See :ref:`authentication_permissions_query` for details on how to add permission
write: true
.. tab:: JSON
.. tab:: datasette.json
.. code-block:: json
@ -407,7 +413,7 @@ You can customize how Datasette represents success and errors using the followin
For example:
.. [[[cog
metadata_example(cog, {
config_example(cog, {
"databases": {
"mydatabase": {
"queries": {
@ -426,7 +432,7 @@ For example:
})
.. ]]]
.. tab:: YAML
.. tab:: datasette.yaml
.. code-block:: yaml
@ -444,7 +450,7 @@ For example:
on_error_redirect: /mydatabase
.. tab:: JSON
.. tab:: datasette.json
.. code-block:: json
@ -510,7 +516,7 @@ Available magic parameters are:
Here's an example configuration that adds a message from the authenticated user, storing various pieces of additional metadata using magic parameters:
.. [[[cog
metadata_example(cog, yaml="""
config_example(cog, """
databases:
mydatabase:
queries:
@ -527,10 +533,11 @@ Here's an example configuration that adds a message from the authenticated user,
""")
.. ]]]
.. tab:: YAML
.. tab:: datasette.yaml
.. code-block:: yaml
databases:
mydatabase:
queries:
@ -545,7 +552,8 @@ Here's an example configuration that adds a message from the authenticated user,
)
write: true
.. tab:: JSON
.. tab:: datasette.json
.. code-block:: json