Closed solewniczak closed 1 year ago
I like the idea to be able to save queries for reuse in the sqlite admin interface itself. I would make a nice addition.
For having stored queries with results that can be embedded into wiki pages I would prefer to have it in a separate plugin. Actually the the dbquery plugin already does it. It's also database agnostic. To be a proper alternative to struct aggregations additional features like dynamic sorting, filtering and paging would be nice. But again I see that as potential features for the dbquery plugin.
I removed the syntax component from the commit, keeping only the query saving feature. Do you think you can merge it now?
I've introduced several improvements to the plugin's admin interface:
Looks good. One general question. Would it make sense to save these per database? Because most select would be very specific to a certain database, right?
Do you mean to save the queries in individual databases, not in an additional "sqlite.sqlite3" database? It can make sense indeed since we already have the special table: "opts" and we can create another one. But I was a little bit scared to update existing databases so I decided to keep the saved queries in a separate database.
This branch extends the sqlite plugin with two important contributions:
The main idea of this extension is to provide the most general way to overcome query limitations of plugins that use sqlite (with primarily struct in mind). The two important use cases where I find this plugin useful are advanced join operations and group by queries which cannot be performed using standard struct syntax.
While the first contribution is quite straightforward, the second one have some security implications - every user that has write permission and knows (or can guess) the query's name, can see the query results. However for wikis where there are not strict security rules, this feature can be very useful. One way to make it a little bit safer is add the config option that will enable usage of named queries in wikicode (which can be turn off by default).
In order to display a results of a named query, we can use the syntax:
<sqlite>dbname.query_name</sqlite>
. The<sqlite>
tag takes optional parameters. Firstly, we can define the parser used on the raw query results for each individual column. The parsers are classes from struct types and are available only when the sturct plugin is installed in wiki:<sqlite parser_(nr of column in sequence)="ParserName(optional config in json format)>dbname.query_name</sqlite>
Secondly we can pass the arguments for the query (separated by comas), which will replace the quotation marks in the SQL:
<sqlite args="first arg,second arg">dbname.query_name</sqlite>
The arguments can be static strings or special variables:
$ID$
,$NS$
,$PAGE$
,$USER$
,$TODAY$
.Examples: