-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Recommended Orm Relational Access #241
Comments
Drogon has no particular abstraction about PivotTables, but I think it might be a good idea to implement PivotTables with Views + ORM. |
Yes, but I'm wondering, how would I possibly do this on my tables, when they have such clear dependencies on others, particularly pivot tables, for instance every product may belong to several carts in a many-to-many relationship. If I do use the orm, I found I'll be using multiple queries anytime I need joins, meaning I'd need to use pure SQL, and it does not seem consistent to use that for relations and the orm for joinless queries. What would be your recommendation to keep consistency in this scenario? Also, is there any plan to automatically generate REST controllers for the generated models, because this would save SOOOO much time, I mean if you had this, which is not particularly hard, this would be a really competitive framework as it'd be as full featured as laravel, except that so fast. I favour the current no migrations approach, as it means you can deal with your databases in their own language and do the migration workflow separate from the rest of the project, being able to take full advantage of the existing workflows and tools for creating databases and the model generation is beautiful. I also like that it uses modern C++, which in my own opinion beats everything else both is expressivity and in completeness. I am currently building a e-commerce platform meant to compete with current offerings in the market, as none are fast.(free ones are slowpokes running on PHP, and the average ones are ASP.NET Core based with very constraining licenses) To build the database and have the cli generate the entire REST for the application would mean that all the work I'd be doing is relative to the specifics of my application, there would be no more wasting time on boilerplate. This would become my number one go to tool for any web project and that's amazing as I finally could use C++ without the resulting productivity loss. I'm more than certain I'm not alone in this thought, and regardless am very thankful for the work already done here, it's exquisite. |
I can't understand what the inconsistency means, can you explain it in more detail or give an example?
This sounds good, I will implement this feature. There are two options:
Thank you for your encouragement, I will continue to improve it. |
Regarding the first I'm not sure, it's an hard subject. Most systems use a query builder, please check what this means(definitely something easier to do in a more functional oriented language): https://laravel.com/docs/5.7/eloquent-relationships //ease of use approach https://codesynthesis.com/products/odb/ // in c++ I'm not entirely sure of how this was implemented so I can't really say much more. I understand this needs a lot of research as it would most definitely impact performance severally. Maybe instead of building the code to work around the dynamic objects generated by the join, there is a way to assist the process with something without a performance cost, like Macros or whatever else is applicable. As for the second point and not sure there won't be issues with this but I'd go for option 1. You could generate two controllers per model, the basecontroller and another one that inherits from it, or just make best practice for the user to inherit from the generated controllers when making new changes. You could then have one cli command to generate both and another that just generates the basecontroller, so you'd have the post, delete, put, get functions(with maybe paginated overloads) and in the controller that inherits from it the developer would add any logic, or overload the functions necessary. If the model changes then the dev looses no progress and if necessary changes the inherited reference to the new generated model. |
@nemesis567 Thank you very much, I have to take the time to think carefully about these problems. |
@nemesis567 , For creating REST controllers for the generated models, I made a PR #244 . After some very simple tests, it seems to be feasible. Please take a look, thank you. |
Pulled the restful branch compiled but it doesn't seem to be generating the controllers with dg_ctl create model ./models |
You should modify the model.json.
the option above can be obtained by creating a new project by the latest version of dg_ctl. |
|
Did you run |
Yes, I did:
I can confirm I'm building the right repo as well. I did not create a new project, just edited the models json.
|
The output in my system. |
|
It looks all right. Let me check. sorry for that. |
Sure no problem, let me know if you need more information. |
@nemesis567 Please check the latest commit. thanks. |
Very good work, no doubt. 👏 👏 👏 |
@nemesis567 Thank you ^.^
Regarding relationships, I tried to create some Joiner (what name is appropriate?) class templates for them. There are some details to consider, and I think it will be done in a week or two. |
For rest, yes, I agree that's important.
|
I'll add this right now.
I'll add this right now.
Currently, the meta data of this is not extracted into model classes, I'll add this later.
I'll add this. |
Let's take the following tables:
With the following relationships: Regarding relationships, have you considered this:
So we should have:
There are benefits to having these all hard coded as there is no dynamic management overhead. Now there is a problem when we want to use complex queries to retrieve related models as these methods would be doing multiple queries. As such I think it'd be relevant to define the relationships themselves in code, so that their role would be assembling the necessary queries when the intention is not to retrieve a related model but to use this relation in a more complex query. For example product->reviews()->findBy().By having some sort of definition of the reviews relationship, we could build a query at once that filters all the skus that belong to the given product. This query helper would not return any result until a GET type of query is applied, like findBy. reviews() would return a static class that would have the job of binding the SQL together in a single query. You could do all above through such a class, but you'd need to figure out a way for it to work reversed. Also for all above I favour written code, even if it becomes messy, results in more space or is harder to maintain, than performance loss related to dynamic typing or reflection. Furthermore
Please read whatever I say with a grain of salt, this is just a rough overview I came up with, definitely not with enough consideration, but in hopes that it fits somewhere along the right path to go. |
Thank you very much, there are many good ideas in your comments, I will implement them step by step. So much work to do ;-) I am afraid that it will take a lot of time to implement all. So, as what you said, we prefer to use model APIs for queries instead of using Mapper templates? For now model classes are just data abstractions (All queries are executed by Mappers), so there are a lot of work related to model generation. Maybe we can provide some methods, such as BTW: I value performance very much, all the reflections are done in the initial phase of drogon applications. Did you see the letast tfb benchmark result? |
I agree with the static methods for the model classes. I am talking on the model level, not questioning whether the underlying query building happens in a different class as long as it's low overhead. Basically, what the static relationship classes I was talking about earlier would do is provide an abstraction similar to the Mapper, basically a query building utility. Now I am not entirely sure how the mapper works yet so I'll have to look into it before going further. Yes, I have seen the benchmark, and while interesting I'd rather see how this would behave in production. |
can you add this type of api? you can use a function to read data part from file, before writing new content to the file.
|
Now all operations are executed with the Mapper template, model classes haven't queries-related methods. You should do this by using findBy() method : mapper.limit(1).findBy(Criteria(Users.Cols._admin, true) ... ); |
@an-tao Please check e-mail. |
@nemesis567 I have added the request validations and field selections to the REST APIs. |
@nemesis567 I added |
I'd like to know what's the recommended way to access pivot tables and related records with the ORM, if there is one and if not the recommended way of doing so in the most performant way as intended by drogon.
The text was updated successfully, but these errors were encountered: