Use companions in custom row classes

This commit is contained in:
Simon Binder 2021-04-25 15:21:43 +02:00
parent df7f1fb051
commit eb5196e9e8
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
2 changed files with 10 additions and 10 deletions

View File

@ -69,11 +69,11 @@ class User implements Insertable<User> {
@override
Map<String, Expression> toColumns(bool nullToAbsent) {
return {
'id': Variable<int>(id),
'name': Variable<String>(name),
'birth_date': Variable<DateTime>(birthDate),
};
return UsersCompanion(
id: Value(id),
name: Value(name),
birthDate: Value(birthDate),
).toColumns(nullToAbsent);
}
}
```

View File

@ -80,11 +80,11 @@ class CustomRowClass implements Insertable<CustomRowClass> {
@override
Map<String, Expression> toColumns(bool nullToAbsent) {
return {
'not_really_an_id': Variable<int>(notReallyAnId),
'some_float': Variable<double>(anotherName),
'custom': Variable<String?>(const CustomConverter().mapToSql(custom))
};
return TableWithoutPKCompanion(
notReallyAnId: Value(notReallyAnId),
someFloat: Value(anotherName),
custom: Value(custom),
).toColumns(nullToAbsent);
}
}