Skip to content

Commit

Permalink
New URLs plus table/database actions, closes #6
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Feb 26, 2024
1 parent 24e8f96 commit 7789c6a
Showing 1 changed file with 37 additions and 8 deletions.
45 changes: 37 additions & 8 deletions datasette_extract/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,11 @@ def register_commands(cli):
cli.add_command(extract, name="extract")


@hookimpl
def startup():
# TODO: Create tables etc, maybe using sqlite-migrate
pass


@hookimpl
def register_routes():
return [
(r"^/-/extract/(?P<database>[^/]+)$", extract_create_table),
(r"^/-/extract/(?P<database>[^/]+)/(?P<table>[^/]+)$", extract_to_table),
(r"^/(?P<database>[^/]+)/-/extract$", extract_create_table),
(r"^/(?P<database>[^/]+)/(?P<table>[^/]+)/-/extract$", extract_to_table),
]


Expand All @@ -210,3 +204,38 @@ def get_type(type_):
return "number"
else:
return "string"


async def can_use_extract(datasette, actor, database, table=None):
# TODO: Add proper permissions checks
return True


@hookimpl
def database_actions(datasette, actor, database):
async def inner():
if not await can_use_extract(datasette, actor, database):
return []
return [
{
"href": datasette.urls.database(database) + "/-/extract",
"label": "Create table with extracted data",
}
]

return inner


@hookimpl
def table_actions(datasette, actor, database, table):
async def inner():
if not await can_use_extract(datasette, actor, database, table):
return []
return [
{
"href": datasette.urls.table(database, table) + "/-/extract",
"label": "Extract data into this table",
}
]

return inner

0 comments on commit 7789c6a

Please sign in to comment.