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
Add writable canned query demo to latest.datasette.io #2134
Comments
Here's a simple plugin that can do this: from datasette import hookimpl
@hookimpl
def startup(datasette):
db = datasette.add_memory_database("counters")
async def inner():
await db.execute_write("create table if not exists counters (name text primary key, value integer)")
await db.execute_write("insert or ignore into counters (name, value) values ('counter', 0)")
return inner
@hookimpl
def canned_queries(database):
if database == "counters":
return {
"increment": {
"sql": "update counters set value = value + 1 where name = 'counter'",
"write": True,
},
"decrement": {
"sql": "update counters set value = value - 1 where name = 'counter'",
"write": True,
},
} |
Annoying thing about this plugin is that you don't see the new counter value when you submit the increment or decrement query. Maybe canned queries should support SQL multiple statements? Could return the result of the last one. |
Alternatively, what about if there was a custom SQL function available during canned write queries for setting the output message? Then the fact that canned queries don't return a table view wouldn't be a problem. Bit weird though. |
Or... how about if the |
Now live at https://latest.datasette.io/counters |
This would be useful while working on:
The text was updated successfully, but these errors were encountered: