Replies: 2 comments
-
Thanks for opening up this thread. To add the most important point upfront: We do not have any design yet how database views should be supported or not, therefore I cannot provide any details on how something should be implemented. That written, let me try to address a few of your suggestions:
That would be reasonable.
There is no need to design a complete new DSL for that, at least not for querying …. That should reuse the existing query dsl. For defining such a view I would imaging a similar setup than the
Runtime errors are unfortunately not a solution for something like that if that should be part of diesel itself. If you want to experiment with such an implementation I suggest you to try that out as a third party crate. For the inclusion in diesel itself the requirements for such a feature are that it cannot cause runtime issues for such things like mutations.
Diesel requires primary keys for tables because it's best practice to have a primary key on your database table. As for views: views shouldn't implement |
Beta Was this translation helpful? Give feedback.
-
Here are some thoughts I have regarding the further implementation of views: == Null-ability
This is something I may or may not take on, it's a desired feature but most likely more time-consuming that I currently be able to invest. == Updating == Automatic joins |
Beta Was this translation helpful? Give feedback.
-
I want to start working on this. But I really don't know where to start. What could we consider a proof of concept? I was thinking a version where we completely disallow insert/update/delete, even in views that some DB (postgres for example) would allow it and consider all columns as nullable, to normalize any nullability inconsistencies (since we are only allowing reads, this wouldn't cause any errors on the DB side). Otherwise the DSL would look like the tables DSL.
Initially this could even be implemented with runtime checks, that panic or throw an error if one tries to manipulate a view. This would make it possible (?) to share the DSL with tables in it's entirety. This could be implemented as an experimental feature gate.
unchecked-views
orexperimental-views
or something along those lines.And about the point you made about primary keys: why does Diesel require primary keys on tables in the first place? What would be the technical difficulties of implementing views, without said primary keys?
The features described above would already be useful for a lot of people. From my experience views are mostly used as read only anyway.
Once we have a proof of concept working I'm sure new questions will arise and we can continue discussion from there.
Beta Was this translation helpful? Give feedback.
All reactions