Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upUniversal connection establisher #882
Comments
This comment has been minimized.
|
Can you give some more context on what you're trying to accomplish? It is not a goal of Diesel to make it easy to write code that is generic over the backend. Even if we provided this function, any place that a query is executed would have to sufficiently prove that the query is valid on all possible backends, which is extremely verbose to write. |
This comment has been minimized.
TruputiGalvotas
commented
May 16, 2017
|
Well, for example own/next-cloud allows to use either sqlite or mysql. In other words, I'd like wirte an application which is database agnostic - meaning user could choose which backend to use. Although I don't know if this makes any sense.. |
This comment has been minimized.
|
It's not impossible, but it's not a use case that we design for. Using Diesel with multiple backends generically can often be quite painful, which is why we usually write separate functions per backend in places like CLI. |
TruputiGalvotas commentedMay 1, 2017
Hi, first of all, thank you for your work on this!
I have to state, that I'm new to both rust and working with databases, so please bear with my thoughts here.
So, I really liked rustorm approach of using an enum, for switching which backend to use. Then I've tried to write my own abstraction using enums over diesel, but it was too much work of supporting all the associated types and I think this should be baked in the diesel itself, rather than a separate crate abstraction, although I might have been doing this wrong..
But then I've though at least something like this is possible:
This is of course just a sample..
But then, I've started looking at what infer_schema!() macro does and I've stumbled upon this: https://github.com/diesel-rs/diesel/blob/master/diesel_infer_schema/src/inference.rs where something more universal like and enum is used to switch between different backends.
So, following the guidlines now:
I'd like to use any backend supported by diesel using single structure/trait/enum, so I could easily switch between backends (assuming the sql part is compatible) by simply changing the database url in the code. Also, I'd like to store connection (any diesel supported backend connection) in a struct
As explained above, schema inference code sample which uses enum, probably would be preferable, since it allows easier integration in structs, since generics would not be needed
Again, as explained above, at least macro would be a step forward
I sincerely don't know, maybe someone else could comment on this, or why such approach like in infer_schema!() macro wasn't used for the diesel interface