Replies: 1 comment 3 replies
-
While I can understand the demand of such a feature I do not think this should be added to diesel any time soon, for the following reasons:
My proposal here is to keep this as third party crate. That implies that if diesel does not expose any required API we could talk about opening this API as part of the public API or providing some alternative better suited for public consumption. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
We use Postgres namespaces ('schemas') heavily, and it would be great if Diesel had support for a typical multi-tenancy setup where the structure of tables is known at compile time, but the namespace for the tables is generated dynamically. I've been thinking that all that is needed is a macro
namespaced_table!
that largely has the same functionality as the existingtable!
, i.e., you could declare a tableTo query from it, you would write
It should be possible to use all the same constructs that you can form with a static
users::table
, except that you writeposts::table("namespace")
. The advantage is that Diesel and Rust will still check most aspects of your queries, like that you only use columns that are declared (I actually got bitten by that one using plain SQL for such queries)I tried to set up something like this by copying the declaration of the
table!
macro and making a few changes, but it seems that this could only be done as part of Diesel since the macro depends on a bunch of private helpers. It would probably also only be possible for Postgres; I have no experience how this sort of thing is set up in MySQL or SQLite.I'd be willing to try implementing this for Postgres; before I do, I'd love to hear whether this is the right direction, and whether the maintainers would be willing to accept a PR along these lines since I don't want to maintain a Diesel fork.
Beta Was this translation helpful? Give feedback.
All reactions