RFC: Visual editor for SQL queries #2061
Janpot
announced in
Early feedback
Replies: 1 comment
-
Instead of writing the query in the editor, we should create a .SQL (and a .ts) file for the user in the IDE and let them write it there. When this query is executed, we'll show the output in a preview table. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Summary
Bring a simpler workflow to Toolpad for writing queries for postgres and MySql databases.
Motivation
#1952
Design
Add another option when creating queries. Name it "PostgreSQL query". After choosing it, an editor opens, similar to the "HTTP request" one.
At the top the user can choose the PostgreSQL datasource in an autocomplete. If none is available, they get the option to create a new data source.
Connection editor
A dialog for adding a postgres connection to Toolpad. In the file system, connection consists of two parts:
The connection definition in the resources folder:
The .env file
The dialog presents fields for user/password/host/port/... and a "test connection" button. Hitting the "save" button stores all the parameters in the resource and .env files. We can give the option for choosing your own env variable name. We should always avoid overwriting existing env variables without prior user consent.
query editor
All connections under resources that are of the
postgresql
kind are available in the connection dropdown. The query editor itself has a code editor for SQL queries and a preview table.parameter interpolation
We could support mustache to inject parameters in SQL but with the following restrictions:
Interpolations will be replaced with parameters
$0
,$1
to avoid unwanted SQL injection. This means thatfirst gets translated to
and passed to the db as such. There will be no string replacement of interpolations in queries. i.e. we won't translate that into
Note this means that not all interpolation is possible. i.e. the following is invalid:
the SQL query itself won't be available anywhere in the runtime on the browserside. The query is stored serverside and only parameters are transferred when executing it.
The query gets stored in the page as
To simplify an initial implementation, we could opt for starting out without mustache support and instead add a parameters section as in the pre-13 implementation.
The rest of the query works analog to the rest queries
Trade-offs
Alternatives
As an alternative we we could work towards a concept that is better integrated with the custom functions and which progressively allows ejecting queries to code files
Beta Was this translation helpful? Give feedback.
All reactions