Initial Thoughts #27
Replies: 4 comments 1 reply
-
Thanks for taking the time to provide feedback. it is super helpful
I think that I know what you are talking about, but am not 100% sure. Could you include the code snippet so that I can make sure that I am on the same page?
I thought to handle this case w/ the update builder: user.update()
.password(new_password)
.exec(&db)
.await
.unwrap(); Fundamentally, in order to persist an update, toasty needs to know what changed. I don't think that having the model itself track its own change set is a great idea. Instead, the approach is to have a separate type (here, the update builder) do the tracking. The update builder could be extended to provide more "getter" methods that let you read the in-progress updated values. Does something like this work for you?
It would be great if you could share some examples of where the leaking or "unmaintainable code chunks" happened and what they look like.
All the tests already use sqlite in memory. How about we extend the test crate to add feature flags per datastore. Then you can pick the data store you want to test against locally and CI can handle the others? |
Beta Was this translation helpful? Give feedback.
-
096c64d landed, so local tests default to only using sqlite in-memory |
Beta Was this translation helpful? Give feedback.
-
Concerning my 1. here is a code snippet somewhat taken from the example let user = User::find_by_id(&u1.id).get(&db).await.unwrap();
// Here the todos are not loaded (which is good imo because this gives the user the flexibility to load them only when needed
// The user currently has no way to know whether or not which relation is loaded tho
// The naive way to get the todos would be:
let todos = user.todos(); // note due to type-system you have to assign them to a temp var which is imo not too nice
// and then call this
todos.get(); // which panics because you have to do the following
let real_todos = todos.all(&db).await.unwrap(); Maybe i dont understand what the .get() function tries to achieve |
Beta Was this translation helpful? Give feedback.
-
My 2. point is somewhat complex to explain but in enterprise the way to you would often develop complex high-level applications is by using a architectural-approach that completely separates the database entities from the domain types. Meaning that the user maps from and to the generated entities and therefore loosing the connection to things like the update builder. When one does this the database mapping and interactions could be either:
To be clear i am not sure if the second approach is really something one should wish for because it means a lot of Magic and performance implications. What is the way that you expect the users to develop using toasty?
|
Beta Was this translation helpful? Give feedback.
-
Hi there,
thanks for your ongoing work and this crate. I think it does fill some kind of gap in the ecosystem.
That said i have some initial thoughts when playing around with the lib
When trying to access some referenced struct like the todos in the
hello-toasty
-example one always has to calltodos.all(&db).await...
before the firsttodos.get()
otherwise one gets a panic. This is something i think could be represented with the typesystem via a generic.For me when writing any high-level-application like a rest-service a orm has to one thing: Make it easy to fetch update and insert my data. This can be done right now with toasty and things like sea-orm aswell. But the real struggles appears when one tries to separate the database from the business-logic e.g by using DDD and a strong domain layer. Because then the persistence layer does not know anything about possible changes in the data anymore. It has to provide generic functions. Think about the following code:
The reason i dont like any existing solutions currently is the fact that one cant really use a strong domain layer without leaking database stuff or heavy unmaintainable code chunks. I was hoping toasty could provide a way to do this.
I think it would be easier to use in-memory sqlite instead of dynamodb in the tests as this does not require any additional setup
For the same reason i cant really run the tests locally so one could maybe think about using testcontainer
Beta Was this translation helpful? Give feedback.
All reactions