mirror of https://github.com/AMT-Cheif/drift.git
Remove unnecessary type parameter on createCompanion
This commit is contained in:
parent
718af051ff
commit
6e32e37dd7
|
@ -4,6 +4,7 @@
|
|||
to check values for both an upper and lower bound
|
||||
- Automatically map `BOOLEAN` and `DATETIME` columns declared in a sql file to the appropriate type
|
||||
(both used to be `double` before).
|
||||
- __Breaking__: Remove the type parameter from `Insertable.createCompanion`.
|
||||
|
||||
## 2.0.0
|
||||
This is the first major update after the initial release and moor and we have a lot to cover:
|
||||
|
|
|
@ -39,13 +39,13 @@ class Category extends DataClass implements Insertable<Category> {
|
|||
}
|
||||
|
||||
@override
|
||||
T createCompanion<T extends UpdateCompanion<Category>>(bool nullToAbsent) {
|
||||
CategoriesCompanion createCompanion(bool nullToAbsent) {
|
||||
return CategoriesCompanion(
|
||||
id: id == null && nullToAbsent ? const Value.absent() : Value(id),
|
||||
description: description == null && nullToAbsent
|
||||
? const Value.absent()
|
||||
: Value(description),
|
||||
) as T;
|
||||
);
|
||||
}
|
||||
|
||||
Category copyWith({int id, String description}) => Category(
|
||||
|
@ -216,7 +216,7 @@ class Recipe extends DataClass implements Insertable<Recipe> {
|
|||
}
|
||||
|
||||
@override
|
||||
T createCompanion<T extends UpdateCompanion<Recipe>>(bool nullToAbsent) {
|
||||
RecipesCompanion createCompanion(bool nullToAbsent) {
|
||||
return RecipesCompanion(
|
||||
id: id == null && nullToAbsent ? const Value.absent() : Value(id),
|
||||
title:
|
||||
|
@ -227,7 +227,7 @@ class Recipe extends DataClass implements Insertable<Recipe> {
|
|||
category: category == null && nullToAbsent
|
||||
? const Value.absent()
|
||||
: Value(category),
|
||||
) as T;
|
||||
);
|
||||
}
|
||||
|
||||
Recipe copyWith({int id, String title, String instructions, int category}) =>
|
||||
|
@ -449,14 +449,14 @@ class Ingredient extends DataClass implements Insertable<Ingredient> {
|
|||
}
|
||||
|
||||
@override
|
||||
T createCompanion<T extends UpdateCompanion<Ingredient>>(bool nullToAbsent) {
|
||||
IngredientsCompanion createCompanion(bool nullToAbsent) {
|
||||
return IngredientsCompanion(
|
||||
id: id == null && nullToAbsent ? const Value.absent() : Value(id),
|
||||
name: name == null && nullToAbsent ? const Value.absent() : Value(name),
|
||||
caloriesPer100g: caloriesPer100g == null && nullToAbsent
|
||||
? const Value.absent()
|
||||
: Value(caloriesPer100g),
|
||||
) as T;
|
||||
);
|
||||
}
|
||||
|
||||
Ingredient copyWith({int id, String name, int caloriesPer100g}) => Ingredient(
|
||||
|
@ -655,8 +655,7 @@ class IngredientInRecipe extends DataClass
|
|||
}
|
||||
|
||||
@override
|
||||
T createCompanion<T extends UpdateCompanion<IngredientInRecipe>>(
|
||||
bool nullToAbsent) {
|
||||
IngredientInRecipesCompanion createCompanion(bool nullToAbsent) {
|
||||
return IngredientInRecipesCompanion(
|
||||
recipe:
|
||||
recipe == null && nullToAbsent ? const Value.absent() : Value(recipe),
|
||||
|
@ -666,7 +665,7 @@ class IngredientInRecipe extends DataClass
|
|||
amountInGrams: amountInGrams == null && nullToAbsent
|
||||
? const Value.absent()
|
||||
: Value(amountInGrams),
|
||||
) as T;
|
||||
);
|
||||
}
|
||||
|
||||
IngredientInRecipe copyWith(
|
||||
|
|
|
@ -7,8 +7,12 @@ import 'package:moor/moor.dart';
|
|||
/// database.
|
||||
@optionalTypeArgs
|
||||
abstract class Insertable<D extends DataClass> {
|
||||
/// Used internally by moor.
|
||||
T createCompanion<T extends UpdateCompanion<D>>(bool nullToAbsent);
|
||||
/// Converts this object into a companion that can be used for inserts. On
|
||||
/// data classes, [nullToAbsent] will map `null` fields to [Value.absent()].
|
||||
/// Otherwise, null fields will be mapped to `Value(null)`.
|
||||
///
|
||||
/// Mainly used internally by moor.
|
||||
UpdateCompanion<D> createCompanion(bool nullToAbsent);
|
||||
}
|
||||
|
||||
/// A common supertype for all data classes generated by moor. Data classes are
|
||||
|
@ -48,8 +52,8 @@ abstract class UpdateCompanion<D extends DataClass> implements Insertable<D> {
|
|||
const UpdateCompanion();
|
||||
|
||||
@override
|
||||
T createCompanion<T extends UpdateCompanion<D>>(bool nullToAbsent) {
|
||||
return this as T;
|
||||
UpdateCompanion<D> createCompanion(bool nullToAbsent) {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -34,12 +34,12 @@ class NoId extends DataClass implements Insertable<NoId> {
|
|||
}
|
||||
|
||||
@override
|
||||
T createCompanion<T extends UpdateCompanion<NoId>>(bool nullToAbsent) {
|
||||
NoIdsCompanion createCompanion(bool nullToAbsent) {
|
||||
return NoIdsCompanion(
|
||||
payload: payload == null && nullToAbsent
|
||||
? const Value.absent()
|
||||
: Value(payload),
|
||||
) as T;
|
||||
);
|
||||
}
|
||||
|
||||
NoId copyWith({Uint8List payload}) => NoId(
|
||||
|
@ -166,11 +166,11 @@ class WithDefault extends DataClass implements Insertable<WithDefault> {
|
|||
}
|
||||
|
||||
@override
|
||||
T createCompanion<T extends UpdateCompanion<WithDefault>>(bool nullToAbsent) {
|
||||
WithDefaultsCompanion createCompanion(bool nullToAbsent) {
|
||||
return WithDefaultsCompanion(
|
||||
a: a == null && nullToAbsent ? const Value.absent() : Value(a),
|
||||
b: b == null && nullToAbsent ? const Value.absent() : Value(b),
|
||||
) as T;
|
||||
);
|
||||
}
|
||||
|
||||
WithDefault copyWith({String a, int b}) => WithDefault(
|
||||
|
@ -326,13 +326,12 @@ class WithConstraint extends DataClass implements Insertable<WithConstraint> {
|
|||
}
|
||||
|
||||
@override
|
||||
T createCompanion<T extends UpdateCompanion<WithConstraint>>(
|
||||
bool nullToAbsent) {
|
||||
WithConstraintsCompanion createCompanion(bool nullToAbsent) {
|
||||
return WithConstraintsCompanion(
|
||||
a: a == null && nullToAbsent ? const Value.absent() : Value(a),
|
||||
b: b == null && nullToAbsent ? const Value.absent() : Value(b),
|
||||
c: c == null && nullToAbsent ? const Value.absent() : Value(c),
|
||||
) as T;
|
||||
);
|
||||
}
|
||||
|
||||
WithConstraint copyWith({String a, int b, double c}) => WithConstraint(
|
||||
|
@ -510,7 +509,7 @@ class Config extends DataClass implements Insertable<Config> {
|
|||
}
|
||||
|
||||
@override
|
||||
T createCompanion<T extends UpdateCompanion<Config>>(bool nullToAbsent) {
|
||||
ConfigCompanion createCompanion(bool nullToAbsent) {
|
||||
return ConfigCompanion(
|
||||
configKey: configKey == null && nullToAbsent
|
||||
? const Value.absent()
|
||||
|
@ -518,7 +517,7 @@ class Config extends DataClass implements Insertable<Config> {
|
|||
configValue: configValue == null && nullToAbsent
|
||||
? const Value.absent()
|
||||
: Value(configValue),
|
||||
) as T;
|
||||
);
|
||||
}
|
||||
|
||||
Config copyWith({String configKey, String configValue}) => Config(
|
||||
|
@ -687,7 +686,7 @@ class MytableData extends DataClass implements Insertable<MytableData> {
|
|||
}
|
||||
|
||||
@override
|
||||
T createCompanion<T extends UpdateCompanion<MytableData>>(bool nullToAbsent) {
|
||||
MytableCompanion createCompanion(bool nullToAbsent) {
|
||||
return MytableCompanion(
|
||||
someid:
|
||||
someid == null && nullToAbsent ? const Value.absent() : Value(someid),
|
||||
|
@ -700,7 +699,7 @@ class MytableData extends DataClass implements Insertable<MytableData> {
|
|||
somedate: somedate == null && nullToAbsent
|
||||
? const Value.absent()
|
||||
: Value(somedate),
|
||||
) as T;
|
||||
);
|
||||
}
|
||||
|
||||
MytableData copyWith(
|
||||
|
|
|
@ -60,7 +60,7 @@ class TodoEntry extends DataClass implements Insertable<TodoEntry> {
|
|||
}
|
||||
|
||||
@override
|
||||
T createCompanion<T extends UpdateCompanion<TodoEntry>>(bool nullToAbsent) {
|
||||
TodosTableCompanion createCompanion(bool nullToAbsent) {
|
||||
return TodosTableCompanion(
|
||||
id: id == null && nullToAbsent ? const Value.absent() : Value(id),
|
||||
title:
|
||||
|
@ -74,7 +74,7 @@ class TodoEntry extends DataClass implements Insertable<TodoEntry> {
|
|||
category: category == null && nullToAbsent
|
||||
? const Value.absent()
|
||||
: Value(category),
|
||||
) as T;
|
||||
);
|
||||
}
|
||||
|
||||
TodoEntry copyWith(
|
||||
|
@ -328,13 +328,13 @@ class Category extends DataClass implements Insertable<Category> {
|
|||
}
|
||||
|
||||
@override
|
||||
T createCompanion<T extends UpdateCompanion<Category>>(bool nullToAbsent) {
|
||||
CategoriesCompanion createCompanion(bool nullToAbsent) {
|
||||
return CategoriesCompanion(
|
||||
id: id == null && nullToAbsent ? const Value.absent() : Value(id),
|
||||
description: description == null && nullToAbsent
|
||||
? const Value.absent()
|
||||
: Value(description),
|
||||
) as T;
|
||||
);
|
||||
}
|
||||
|
||||
Category copyWith({int id, String description}) => Category(
|
||||
|
@ -510,7 +510,7 @@ class User extends DataClass implements Insertable<User> {
|
|||
}
|
||||
|
||||
@override
|
||||
T createCompanion<T extends UpdateCompanion<User>>(bool nullToAbsent) {
|
||||
UsersCompanion createCompanion(bool nullToAbsent) {
|
||||
return UsersCompanion(
|
||||
id: id == null && nullToAbsent ? const Value.absent() : Value(id),
|
||||
name: name == null && nullToAbsent ? const Value.absent() : Value(name),
|
||||
|
@ -523,7 +523,7 @@ class User extends DataClass implements Insertable<User> {
|
|||
creationTime: creationTime == null && nullToAbsent
|
||||
? const Value.absent()
|
||||
: Value(creationTime),
|
||||
) as T;
|
||||
);
|
||||
}
|
||||
|
||||
User copyWith(
|
||||
|
@ -778,11 +778,11 @@ class SharedTodo extends DataClass implements Insertable<SharedTodo> {
|
|||
}
|
||||
|
||||
@override
|
||||
T createCompanion<T extends UpdateCompanion<SharedTodo>>(bool nullToAbsent) {
|
||||
SharedTodosCompanion createCompanion(bool nullToAbsent) {
|
||||
return SharedTodosCompanion(
|
||||
todo: todo == null && nullToAbsent ? const Value.absent() : Value(todo),
|
||||
user: user == null && nullToAbsent ? const Value.absent() : Value(user),
|
||||
) as T;
|
||||
);
|
||||
}
|
||||
|
||||
SharedTodo copyWith({int todo, int user}) => SharedTodo(
|
||||
|
@ -954,8 +954,7 @@ class TableWithoutPKData extends DataClass
|
|||
}
|
||||
|
||||
@override
|
||||
T createCompanion<T extends UpdateCompanion<TableWithoutPKData>>(
|
||||
bool nullToAbsent) {
|
||||
TableWithoutPKCompanion createCompanion(bool nullToAbsent) {
|
||||
return TableWithoutPKCompanion(
|
||||
notReallyAnId: notReallyAnId == null && nullToAbsent
|
||||
? const Value.absent()
|
||||
|
@ -965,7 +964,7 @@ class TableWithoutPKData extends DataClass
|
|||
: Value(someFloat),
|
||||
custom:
|
||||
custom == null && nullToAbsent ? const Value.absent() : Value(custom),
|
||||
) as T;
|
||||
);
|
||||
}
|
||||
|
||||
TableWithoutPKData copyWith(
|
||||
|
@ -1162,11 +1161,11 @@ class PureDefault extends DataClass implements Insertable<PureDefault> {
|
|||
}
|
||||
|
||||
@override
|
||||
T createCompanion<T extends UpdateCompanion<PureDefault>>(bool nullToAbsent) {
|
||||
PureDefaultsCompanion createCompanion(bool nullToAbsent) {
|
||||
return PureDefaultsCompanion(
|
||||
id: id == null && nullToAbsent ? const Value.absent() : Value(id),
|
||||
txt: txt == null && nullToAbsent ? const Value.absent() : Value(txt),
|
||||
) as T;
|
||||
);
|
||||
}
|
||||
|
||||
PureDefault copyWith({int id, String txt}) => PureDefault(
|
||||
|
|
|
@ -217,18 +217,18 @@ class DataClassWriter {
|
|||
}
|
||||
|
||||
void _writeCompanionOverride() {
|
||||
// T createCompanion<T extends UpdateCompanion>(bool nullToAbsent)
|
||||
// TableCompanion createCompanion(bool nullToAbsent)
|
||||
|
||||
final companionClass = table.updateCompanionName;
|
||||
_buffer.write('@override\nT createCompanion<T extends UpdateCompanion'
|
||||
'<${table.dartTypeName}>>('
|
||||
'bool nullToAbsent) {\n return $companionClass(');
|
||||
_buffer.write('@override\n'
|
||||
'$companionClass createCompanion(bool nullToAbsent) {\n'
|
||||
'return $companionClass(');
|
||||
|
||||
for (var column in table.columns) {
|
||||
final getter = column.dartGetterName;
|
||||
_buffer.write('$getter: $getter == null && nullToAbsent ? '
|
||||
'const Value.absent() : Value($getter),');
|
||||
}
|
||||
_buffer.write(') as T;}\n');
|
||||
_buffer.write(');}\n');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue