-
Notifications
You must be signed in to change notification settings - Fork 12
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
Allow SQL queries to retrieve report data #2853
Comments
@clemens-msupply my feeling is that limiting us to GraphQL endpoints is far too restrictive- it will place a huge burden on the dev team to create new endpoints (or expand existing), be too slow to develop new reports, and too slow to run with large data sets. |
This would feel much easier if we had a role in the DB for reporting that was basically read only, but unfortunately sqlite does not support and access has to be in application logic. |
FYI I might useful to see that I did with JSON and custom SQL in notify (I think you've seen this code before though?) I'd personally lean towards writing SQL rather than having to learn a new language, although it does look pretty cool. I think we could get a long way without having to have different versions of sql syntax. As a reasonably complex example, this query runs fine in both postgresql...
Query
Maybe we could provide a few custom functions we can call if needed to create some common ground if a problematic area is discovered? Say a GET_CURRENT_DATETIME() function, that we can implement in either as a db specific function, or perhaps replacing them at run time in our rust code, similar to how we use these constants in our migrations?
Or at least the UI could default to one query and only provide an option for a custom version when it's really needed. |
Do you know if there is a sqlite version of: Agree, and I was actually leaning to providing SQL with the option to have two versions, one for sqlite and one for postgres. The sqlglot transpiler looks actually quite cool and might be useful to generate two versions of the same query... |
I had a brief look but didn't find one... |
Currently, report data is retrieved using the existing graphql queries.
Advantages of this approach are:
But there are also some disadvantages. For more advanced, non-standard reports where there isn't a matching GraphQL endpoint the returned data must be processed using Tera. Some known problems with graphql queries + Tera:
Expected behaviour
It would be much better if we could query and mutate data using a query language such as SQL so that the returned data is in the right shape for the Tera template, i.e. so that no or only minimal post-processing is needed in Tera.
Possible solutions:
Using direct SQL database queries
Allow direct SQL queries on the underlying database. To solve the permission problem the report designer would have to specify the permissions and reports need to be manually reviewed to not query unrelated data.
Disadvantage is that reports expect a stable database schema. To solve this we could provide stable table views, e.g.
report_org_table_name
.Another problem is that we support Sqlite and Postgres, and SQL query syntax might vary slightly. There are a couple of possible solutions:
Use https://prql-lang.org/ It's written in Rust and might easily integrate. It also transpiles to Sqlite and Postgres. However, it's not common SQL (even though it looks nicer).R&D idea using Sqlite to query Graphql endpointsSqlite syntax could then be used to bring graphql data into the right shape...
This seems to be too hard/complex. There is also a problem with how vtables and JOINs work in sqlite: https://sqlite.org/forum/forumpost/521e7da42b
The text was updated successfully, but these errors were encountered: