datasette / datasette-import

Tools for importing data into Datasette
Apache License 2.0
10 stars 0 forks source link

Paste into existing table #3

Open simonw opened 6 months ago

simonw commented 6 months ago

Split from:

simonw commented 6 months ago

I wrote this code earlier:

@hookimpl
def table_actions(datasette, actor, database, table):
    async def inner():
        if not await can_paste(datasette, actor, database, table):
            return []
        return [
            {
                "href": datasette.urls.table(database, table) + "/-/paste",
                "label": "Paste data into this table",
                "description": "Paste in JSON, CSV or TSV data (e.g. from Google Sheets)",
            }
        ]

    return inner

And for register_routes():

        (r"^/(?P<database>[^/]+)/(?P<table>[^/]+)/-/paste$", paste_to_table),
simonw commented 6 months ago

There may be a bunch of extra complexity around this:

simonw commented 6 months ago

Super advanced: ability to reformat data to populate columns correctly, for example reformatting dates to match. This is likely to be a separate feature, there's a lot of depth to this one and it affects how imports work too.

Might also need a bit of persistence around this in order to remember what those conversions were for future loads into the same table.