blacken-docs

This commit is contained in:
Simon Willison 2026-02-20 11:28:39 -08:00
commit 6a2c27b15b
3 changed files with 8 additions and 19 deletions

View file

@ -1074,11 +1074,9 @@ You can also return an async function, which will be awaited on startup. Use thi
async def inner():
db = datasette.get_database()
if "my_table" not in await db.table_names():
await db.execute_write(
"""
await db.execute_write("""
create table my_table (mycol text)
"""
)
""")
return inner
@ -1561,7 +1559,6 @@ The resolver will automatically apply the most specific rule.
from datasette import hookimpl
from datasette.permissions import PermissionSQL
TRUSTED = {"alice", "bob"}
@ -2261,8 +2258,7 @@ This example logs events to a ``datasette_events`` table in a database called ``
def startup(datasette):
async def inner():
db = datasette.get_database("events")
await db.execute_write(
"""
await db.execute_write("""
create table if not exists datasette_events (
id integer primary key,
event_type text,
@ -2270,8 +2266,7 @@ This example logs events to a ``datasette_events`` table in a database called ``
actor text,
properties text
)
"""
)
""")
return inner

View file

@ -90,12 +90,10 @@ Here's a recipe for taking a table with existing latitude and longitude columns,
"SELECT AddGeometryColumn('museums', 'point_geom', 4326, 'POINT', 2);"
)
# Now update that geometry column with the lat/lon points
conn.execute(
"""
conn.execute("""
UPDATE museums SET
point_geom = GeomFromText('POINT('||"longitude"||' '||"latitude"||')',4326);
"""
)
""")
# Now add a spatial index to that column
conn.execute(
'select CreateSpatialIndex("museums", "point_geom");'

View file

@ -233,15 +233,11 @@ As an example, here's a very simple plugin which executes an HTTP response and r
async def fetch_url(datasette, request):
if request.method == "GET":
return Response.html(
"""
return Response.html("""
<form action="/-/fetch-url" method="post">
<input type="hidden" name="csrftoken" value="{}">
<input name="url"><input type="submit">
</form>""".format(
request.scope["csrftoken"]()
)
)
</form>""".format(request.scope["csrftoken"]()))
vars = await request.post_vars()
url = vars["url"]
return Response.text(httpx.get(url).text)