-
I'm building a project where the library code uses generics, and auto-generated implementations will provide any specific types or other settings needed. This way I can avoid a lot of code duplication. I'm not sure how well this will work for adding a diesel table to the library, though. Ideally, I'd use a single model and schema in the library code, and the dependent binary will set the table name (either statically or at runtime, I don't care). The database url is set at runtime, but in this case all binaries use the same database so users only need to do one-time MySQL setup even if they use multiple binaries (tables can be created automatically but not databases), and I can restrict the MySQL permissions a bit. If that's not possible, which would be better?
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
This question is rather generic and therefore hard to answer with specific examples. Generally speaking it should be possible to use the same "model" (although even that term is problematic as it's not the classical ORM model, but more a 1:1 mapping with your queries rather than tables) for diesel with different schemas. After all anything that derives For dynamic schemas you use diesel-dynamic-schema which allows you to define your schemas at runtime, which in turn should allow you to easily swap out the table name, etc. Hopefully that gives you an idea how to approach your problem. As for using traits: That's certainly also possible, but I personally would advice not to try that as that quickly leads to really nasty generic code. |
Beta Was this translation helpful? Give feedback.
I'm not sure what else to add to what I've written above: If you want to have a dynamic schema you need to use `diesel-dynamic-schema' (or build your own extensions). It's an explicit design decision to not offer ways to dynamically change the table name of static schemas.