Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paste into existing table #3

Open
simonw opened this issue Mar 19, 2024 · 3 comments
Open

Paste into existing table #3

simonw opened this issue Mar 19, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@simonw
Copy link
Contributor

simonw commented Mar 19, 2024

Split from:

@simonw simonw added the enhancement New feature or request label Mar 19, 2024
@simonw
Copy link
Contributor Author

simonw commented Mar 19, 2024

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
Copy link
Contributor Author

simonw commented Mar 20, 2024

There may be a bunch of extra complexity around this:

  • Validation: checking if the pasted data matches the expected columns
  • Mapping - maybe you can paste data in that doesn't quite match and then select columns to match?
  • Replace v.s. ignore and general primary key awareness
  • Ability to alter the table to add columns that are missing

@simonw
Copy link
Contributor Author

simonw commented Mar 20, 2024

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.

@simonw simonw transferred this issue from datasette/datasette-paste Apr 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant