Closed simonw closed 1 year ago
Some unfinished code I just removed while working on #8:
async def post(self, request):
formdata = await request.form()
database_name = request.url_vars["database"]
columns = [
c.split(".", 1)[1] for c in formdata.keys() if c.startswith("column.")
]
table = formdata["table"]
# TODO: Create table
raise NotImplementedError
I'm going to force the user to have a primary key in their table - it will default to id integer primary key
but they can change it to a text
if they want to (and change the name).
Should I let users have a compound primary key? I think not - if they really want that they can use a create table
statement directly, but it feels too confusing to explain to users who are using a visual table builder.
This feature will be much more interesting when accompanied by some plugin that supports inserting data into tables.
Well that exists now! https://github.com/datasette/datasette-write-ui
The UI can look like this:
So the primary key column is always at the top and can't be dragged around or deleted, but can have its name and type changed (probably limit type to integer
or text
though, float
feels weird - blob
could be OK but I'd rather not go there yet.)
Actually no need for delete buttons that are checkboxes, they can be real buttons that JavaScript remove that row from the page.
And there needs to be a prominent "add column" button that adds a new row.
The "table name" form field should fetch()
check for tables with the same name and display an error + prevent you from submitting if your table matches an existing table.
I won't bother with "add another column" just yet, I'll provide ten and people can add more using the edit table screen later if they need to.
Demo:
This feature will be much more interesting when accompanied by some plugin that supports inserting data into tables.