Skip to content

Commit

Permalink
Include actor in track_event async example, refs #2319
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Apr 12, 2024
1 parent 2a08ffe commit 7d6d471
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions docs/plugin_hooks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2001,8 +2001,7 @@ This example logs events to a `datasette_events` table in a database called `eve
from datasette import hookimpl
import json
@hookimpl
def startup(datasette):
async def inner():
Expand All @@ -2013,27 +2012,28 @@ This example logs events to a `datasette_events` table in a database called `eve
id integer primary key,
event_type text,
created text,
actor text,
properties text
)
"""
)
return inner
@hookimpl
def track_event(datasette, event):
async def inner():
db = datasette.get_database("events")
properties = event.properties()
await db.execute_write(
"""
insert into datasette_events (event_type, created, properties)
values (?, strftime('%Y-%m-%d %H:%M:%S', 'now'),?)
insert into datasette_events (event_type, created, actor, properties)
values (?, strftime('%Y-%m-%d %H:%M:%S', 'now'), ?, ?)
""",
(event.name, json.dumps(properties)),
(event.name, json.dumps(event.actor), json.dumps(properties)),
)
return inner
Example: `datasette-events-db <https://datasette.io/plugins/datasette-events-db>`_
Expand Down

0 comments on commit 7d6d471

Please sign in to comment.