Skip to content

Commit 49053b3

Browse files
gnpricechrisbobbe
authored andcommitted
db: Add Account.copyWithCompanion
Ideally this method would be generated along with the rest of the Account class, so that it'd be sure to stay in sync as columns are added. I have a draft for implementing that in Drift, and will follow up after this by sending that as a PR there.
1 parent 358a9e0 commit 49053b3

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

lib/model/database.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,31 @@ class Accounts extends Table {
3939

4040
Column<String> get ackedPushToken => text().nullable()();
4141

42+
// If adding a column, be sure to add it to copyWithCompanion too.
43+
4244
@override
4345
List<Set<Column<Object>>> get uniqueKeys => [
4446
{realmUrl, userId},
4547
{realmUrl, email},
4648
];
4749
}
4850

51+
extension AccountExtension on Account {
52+
Account copyWithCompanion(AccountsCompanion data) { // TODO(drift): generate this
53+
return Account(
54+
id: data.id.present ? data.id.value : id,
55+
realmUrl: data.realmUrl.present ? data.realmUrl.value : realmUrl,
56+
userId: data.userId.present ? data.userId.value : userId,
57+
email: data.email.present ? data.email.value : email,
58+
apiKey: data.apiKey.present ? data.apiKey.value : apiKey,
59+
zulipVersion: data.zulipVersion.present ? data.zulipVersion.value : zulipVersion,
60+
zulipMergeBase: data.zulipMergeBase.present ? data.zulipMergeBase.value : zulipMergeBase,
61+
zulipFeatureLevel: data.zulipFeatureLevel.present ? data.zulipFeatureLevel.value : zulipFeatureLevel,
62+
ackedPushToken: data.ackedPushToken.present ? data.ackedPushToken.value : ackedPushToken,
63+
);
64+
}
65+
}
66+
4967
class UriConverter extends TypeConverter<Uri, String> {
5068
const UriConverter();
5169
@override String toSql(Uri value) => value.toString();

0 commit comments

Comments
 (0)