How to combine, merge, or otherwise edit Companion entries? #3154
Answered
by
simolus3
wanglophile
asked this question in
Q&A
-
Can I combine, merge or otherwise edit Companion entries? For example, given an initial Companion entry of
How can I add a Something like:
with the end goal of having a new Companion of
|
Beta Was this translation helpful? Give feedback.
Answered by
simolus3
Aug 15, 2024
Replies: 1 comment 3 replies
-
I didn't try it, but I think this should work: extension Merge<T> on Insertable<T> {
Insertable<T> merge(Insertable<T> other) {
return _MergeInsertable(this, other);
}
}
final class _MergeInsertable<T> implements Insertable<T> {
final Insertable<T> _base;
final Insertable<T> _mergedIn;
_MergeInsertable(this._base, this._mergedIn);
@override
Map<String, Expression<Object>> toColumns(bool nullToAbsent) {
return {
..._base.toColumns(nullToAbsent),
..._mergedIn.toColumns(nullToAbsent),
};
}
} I'm not entirely convinced that this should be a part of drift though. We have |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
wanglophile
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I didn't try it, but I think this should work:
I'm not entirely convinced that this should be a part of drift though. We have
copyWith
, but I don't think merges are used that often.