Open robertjpayne opened 8 years ago
This is a good idea. I like it.
Any suggestions for the API?
@nviennot I don't think it needs to be particularly crazy, just looking at code there is:
def _create(options={})
attrs = self.class.persistable_attributes(@_attributes)
result = NoBrainer.run(self.class.rql_table.insert(attrs))
self.pk_value ||= result['generated_keys'].to_a.first
@new_record = false
unlock_unique_fields # just an optimization for the uniquness validation
true
end
def _update(attrs)
rql = ->(doc){ self.class.persistable_attributes(attrs, :rql_doc => doc) }
NoBrainer.run { selector.update(&rql) }
end
Maybe all we need is a class method that is generate_insert_rql(attrs)
and generate_update_rql(selector, attrs)
which both return a block that is passed directly into NoBrainer.run
?
Thoughts? Might not be the cleanest and I'm not 100% certain on functionality of the self.class.persistable_attributes
.
Closing this as it's just a bit too hefty to do so…
Reopening because this usecase is common, and this needs to be addressed in some ways.
I have quite a unique use case but I think it may be nice to have official support for rather than monkey patching.
Our application requires sync capabilities and to handle conflicts during writes I've devised a plan to atomically check a field while updating it like (sorry if syntax is not 100% correct):
This would be pretty easy to if there was pluggable access to how the RQL query is generated for inserts/updates on a per-model-class basis.