-
Notifications
You must be signed in to change notification settings - Fork 535
Sequel orm support #1030
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
Sequel orm support #1030
Conversation
* ActiveRecordAccessor extends from RecordAccessor, for consistency it should be ActiveRecordRecordAccessor because other orms will be OrmRecordAccessor < RecordAccessor which makes more sense. * Another idea would be to rename RecordAccessor but then I think it would be difficult to understand what the Accessor class was for. * Separate out dependencies in the gemspec. The gem no longer requires ActiveRecord to be loaded into your namespace.
…equel_orm_support
@Aryk This a quite a major set of changes. As I see it quickly looking through you are changing major components of the project. It looks like this PR covers:
I think it would be better to address these as separate PRs. That would minimize the conflicts as we work on new versions of the Thanks for taking this on. |
Thanks for the feedback:
Well, I think the think that solidifies the decision, is lets say you were doing meta programming, and had
Which functionality specifically? I really hope I did not add more reference_class stuff into record accessor. I think I wrote in the original ticket but I really feel things should be refactored to record accessors can instantiated with the orm model and have no jsonapi-resource specific code in them. Please comment specifically where I added functionality that is not related to accessing the record on the record accessor.
Yeah, this was a big pain, especially when it came to fixtures and schema, but my solution I think is good especially to make adding other orms easier. |
|
Would you be willing to create a few PRs from this?
In general I think it's best to add one feature, refactor, or bug fix per PR. |
It is an abstract class, it has an interface, that's all it is. I make no reference to "active" anything. Yes there is a find method. That is part of the interface for RecordAccessor. You could rename "find" to "get", but "find" simply gets the record from the orm. This gem has to have some basic requirements about the RecordAccessor and that is one of them. The fact it has the same name as the ActiveRecord#find is simply because "find" isn't a bad name. I was going to call the method "i_summon_an_orm_model_record", which then calls
The ActiveRecordAccessor rename is small. I think its a rename in like 3 places, so doesnt really make sense to split out, IMO.
I 100% agree it's best to split up when you can. It would be very difficult to split these although it sounds nice, but you need to implement the Sequel accessor (aka 2nd orm) to see where the refactoring of the existing tests needs to be done. Separating is probably possible is possible, but I would rather somebody takes over this projects and does even bigger refactors while reducing code, separating concerns, and getting all specs passing, rather than focusing on how to best split up PRs. And if they have extra time to split up PRs, then great. IMO, there is a big PR because the codebase has significant flaws when it comes to adding another orm, although the test suite is pretty extensive, so kudos for that! 👍 Like I mentioned early, I've moved on from this and decided for an approach with just serializing my response while I handle JSON-API like calls manually. I'd be happy to revisit this gem in the future if somebody else takes Sequel support across the finish line. :) My advice would be to rewrite the RecordAccessor:
SequelRecordAccessor.find(instructions) And then the RecordAccessor decides what to do with those instructions. Right now, there is a lot of logic that is not simply about returning records from an orm (ie Anyways, that's my two cents. |
else | ||
context = options[:context] | ||
|
||
records = filter_records(filters, options) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is ActiveRecord based. The intent of the RecordAccessor was to remove all of this so other ORMs will not be dependent on ActiveRecord. The original RecordAccessor was designed to have only abstract methods and no logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is it "AR based" exactly. Yes I moved it up into record accessor because I was trying to seperate ORM specific calls like Model.find (in AR) vs Model[] (in sequel) and the instructions from the resource.rb about which record to get. filter_records is actually a perfect example of what I was saying in my previous comment about how RecordAccessor.find should probably take in some kind of Instruction class/object that simply has the sort, filters, and include. So this should be taken out of RecordAccessor entirely include RecordAccessor never needs to simply "filter" records. It shouldn't even be a public api function.
I made a comment above on your code change showing where I was referring. I'll look this over again in the morning and consider your other points. |
I think we are trying to solve different things with the |
@dgeb and I have been discussing the architecture and we're looking into some changes related to the relationship between Resources, RecordAccessors, and caching that we hope will clean things up a bit. |
But its not just that. I highly recommend that whatever accesses the ORMs do not know about resource and just do their job (access the orm to get records from it). You are going back and forth right now and it's confusing (its also breaking separation of concerns principle). Maybe infact, the orm accessor shouldn't even return records from the orm, but just a simple "data" or "included" array and that is it (idk, i havent really tried, but i would give it a try). That way the jsonapi-resources library simply has an interface with some kind of data provider (like an orm) and that's it. The data provider could in theory be another api if you wanted. To the library itself it wouldn't matter. |
@Aryk Larry and I both share your concerns - these are the architectural issues we've discussed untangling. There is also some entanglement with caching in the RecordAccessor, which I believe drove the initial implementation. We are looking at alternative implementations to provide a cleaner separation of concerns all around. |
@dgeb Great, I think you will need to refactor a lot, so I would also suggest that anyone who wants to build on what I did wait until you do this refactoring. I think it will be much easier to reason about the app after it will be done. |
@mmun Larry is going to investigate how to best remove caching entirely from the
I agree, and this should be possible with a leaner, record-only-focused
After @lgebhardt's first pass at the |
There was an attempt to write sequel adapter in cerebris#1030. I took commits from this PR. This commit fixes most of the failures that are result of applying these commits into much newer codebase. Most of the code is also copied from the original PR.
Following up on the ticket I originally created to make this library truly ORM agnostic (see: #1006).
I got alot of it working, laid the foundations, reorganized the files, and set this up to be a multi-orm library, but jsonapi-resources has a ton of functionality and I ended up spending a lot of time with the last 20% of functionality. I'm also not sure of the maintainers appetite to merge a significant refactoring such as this, hence putting a lot of my time at risk.
Here are some more details:
Some Outstanding Questions/Thoughts:
There are some more refactorings I feel should be done:
Anyways, I'm leaving this PR up, perhaps someone wants to take it across the finish line. 😄 I will not be continuing work on this.
If you do work on this and have questions, feel free to ask, but try to bundle your questions so I can answer more efficiently. Thanks!