-
Notifications
You must be signed in to change notification settings - Fork 496
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SQL / ORM-Like bindings extension #3647
Comments
Let's imagine that we have the following SQL Table, from https://www.w3schools.com/postgresql/postgresql_create_demodatabase.php
This will require to call the following APIs: First, let's register a new Entity:
Once the entity is registered we can use
This results in a simple query:
A similar query will be created to filter by ID.
This results in a simple query: The mechanism will be the same for delete functions. If we want to save a new customer:
This results in the following query:
To keep it simple, we should return the errors generated from the specific database to the user for troubleshooting. This API shouldn't do any advanced type mapping. The implementation of this proposal will require each binding to have a reduced collection of parameterizable SQL statements that will be used to perform the operations described in the APIs, all following the same conventions. |
For now I've taken inspiration in the CrudRepository interface from Spring Data -> https://github.com/spring-projects/spring-data-commons/blob/main/src/main/java/org/springframework/data/repository/CrudRepository.java but I will be happy to align with dotNet ORM framework semanticts too @marcduiker can you. help me out with a reference here? |
The most well-known ORM in .NET is Entity Framework. It uses a |
Can you explain the scope a bit more @salaboy? Is this proposal to extend the current Bindings API or to only extend the individual Dapr SDKs, which in turn would translate the 'repository' methods to use the existing Bindings API? |
The idea is to keep it super simple, for now the only change proposed here is to add more "actions" to existing SQL bindings. This allows us to have a set of well-defined behaviors for SQL bindings beyond "query" and "exec". The new actions suggested in the issue description align with the idea of Entities, meaning 1 entity <-> 1 table. So for example: |
To clarify, this doesn't require any changes in the SDK, the proposal is now just adding new "actions" to the existing bindings. This is an opt-in feature from the perspective of the user. This is also a backward compatible change as actions such as "query" and "exec" will remain unmodified. |
@marcduiker I've added a PR with the in-progress PoC |
@salaboy @marcduiker IMO this does not belong into binding and should be a separate building block. Whenever we expand bindings something is extremely wrong / flawed in the design of Dapr. Adding yet another one off is an ugly quick fix -- there is nothing that requires any two bindings to have the same functionality or standard. And introducing such a concept would be wrong. What is being asked here needs to be a separate building block. Adding this to bindings is not the way to go. |
Hi @berndverst can you share more context? "Whenever we expand bindings something is extremely wrong / flawed in the design of Dapr." -> can you explain the reasons why? I am not as senior in Dapr as some of the folks here, so I would love to know why that is the case. Even if this doesn't belong here, extending a binding to have more functionality can help us show an intermediate step towards the final solution. When looking at how frameworks solve this problem, I realized that:
Right now, Bindings are solving points 1 and 2. With this proposal, we are testing point 3, which can help us figure out the correct API to create a new building block. Your thoughts are highly appreciated. |
Describe the proposal
Currently, Bindings provides a very generic way to access SQL databases. While this is a great generic mechanism, bindings will benefit from an interface offering more functionality out-of-the-box, following common patterns that ORM frameworks implement without becoming a full ORM implementation. Always keeping simplicity in mind and making sure that developers can consume these behaviors using REST/RPC APIs (language agnostic). I've updated the proposal to use the concept of
Entity
thanks to @marcduiker for the dotnet reference.add
used in dotnet)remove
used in dotnet)Notice that these should be APIs exposed by the Binding. Instead of creating a new API / Building Block, I suggest extending the current binding functionality following this functionality. This can then be promoted to its own building block—the main reason why this is recommended as part of the Bindings API is that all ORM frameworks always provide the "Query" escape hatch, which is the core of what Bindings provides nowadays.
This proposal aims to provide a much more straightforward approach than frameworks like GORM -> https://gorm.io/docs/, which also provides a full-blown programming model.
Examples will follow in a separate comment.
The text was updated successfully, but these errors were encountered: