-
-
Notifications
You must be signed in to change notification settings - Fork 698
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
Ability for a canned query to write to the database #698
Comments
{
"databases": {
"my-database": {
"queries": {
"add_twitter_handle": {
"sql": "insert into twitter_handles (username) values (:username)",
"write": true
}
}
}
}
} |
By default this will extract the To address this: allow an extra optional |
This is going to need CSRF protection - see https://github.com/simonw/asgi-csrf |
Also relevant: this will benefit from an authentication/permissions layer: #699 |
This is also going to need me to handle POST form submissions which means I need to be able to parse the form body. I guess that will go in datasette/utils/asgi.py. |
I have code for form parsing in |
It would be useful if this feature supported different types of input - at the most basic level |
This is going to require a pretty full rewrite of the existing canned query logic, which currently shares a codepath with the code that lets you submit a SQL query: datasette/datasette/views/base.py Lines 464 to 563 in 298a899
|
This feature should include the ability to set a custom redirect URL for after the query has been executed - that way it can be used to build things like "delete this row" which redirect back to the correct table. |
YAML for metadata is relevant to this: #713 |
I really want the option to use a Idea: metadata syntax like this: {
"databases": {
"my-database": {
"queries": {
"add_twitter_handle": {
"sql": "insert into twitter_handles (username) values (:username)",
"write": true,
"params": {
"username": {
"widget": "textarea"
}
}
}
}
}
}
} I can ship with some default widgets and provide a plugin hook for registering extra widgets. This opens up some really exciting possibilities for things like map widgets that let you draw polygons. |
What should happen when a query has been successfully executed? That depends on the query. Some queries may wish to redirect to another page. Other queries might want to show a custom message. There should at least be a default message saying the query has been executed. |
Need to figure out what the |
Some extra thoughts now that this is mostly working:
|
One challenge with this feature is that it confuses the messaging about what Datasette does somewhat. Prior to shipping this, Datasette's core value proposition is as a way to publish read-only data. That changed a little in 0.37 in February when plugins gained the supported ability to execute writes, but there was no way of doing that without a plugin. With this feature, Datasette becomes a read-write database solution. I should update the documentation to help explain this. Essentially the message is that Datasette can be used in one of two "modes" - it can be used just for sharing/publishing data, or you can use it to collect and manage data, most likely still in collaboration with plugins for things like authentication. |
Message also now shows number of affected rows after executing query.
Message also now shows number of affected rows after executing query.
Refs #698. First working version of this feature. * request.post_vars() no longer discards empty values
Landed the work so far from #796! Here's the documentation: https://datasette.readthedocs.io/en/latest/sql_queries.html#writable-canned-queries |
CSRF is done. Last step: figure out a smart way to integrate this with permissions and authentication. |
Idea: default is anyone can execute a query. Or you can specify the following: {
"databases": {
"my-database": {
"queries": {
"add_twitter_handle": {
"sql": "insert into twitter_handles (username) values (:username)",
"write": true,
"allow": {
"id": ["simon"],
"role": ["staff"]
}
}
}
}
}
} These get matched against the actor JSON. If any of the fields in any of the keys of
|
I'd really like to support SQL query defined permissions too, mainly to set an example for how plugins could do something similar. |
Idea: an |
There can be a detailed section explaining these different mechanisms on the authentication documentation page. I imagine they will end up applying to more than just canned queries. |
Canned queries are currently read-only: https://datasette.readthedocs.io/en/0.38/sql_queries.html#canned-queries
Add a
"write": true
option to their definition inmetadata.json
which turns them into queries that are submitted via POST and send their queries to the write queue.Then they can be used as a really quick way to define a writable interface and JSON API!
The text was updated successfully, but these errors were encountered: