diff --git a/moor/CHANGELOG.md b/moor/CHANGELOG.md index b765db27..b042f8ed 100644 --- a/moor/CHANGELOG.md +++ b/moor/CHANGELOG.md @@ -1,2 +1,5 @@ +## 1.1.0 +- Transactions + ## 1.0.0 - Initial version of the Moor library diff --git a/moor/example/example.g.dart b/moor/example/example.g.dart index 8acf7d66..0187ce77 100644 --- a/moor/example/example.g.dart +++ b/moor/example/example.g.dart @@ -22,6 +22,15 @@ class Category { id: id ?? this.id, description: description ?? this.description, ); + @override + String toString() { + return (StringBuffer('Category(') + ..write('id: $id, ') + ..write('description: $description') + ..write(')')) + .toString(); + } + @override int get hashCode => (id.hashCode) * 31 + description.hashCode; @override @@ -95,6 +104,17 @@ class Recipe { instructions: instructions ?? this.instructions, category: category ?? this.category, ); + @override + String toString() { + return (StringBuffer('Recipe(') + ..write('id: $id, ') + ..write('title: $title, ') + ..write('instructions: $instructions, ') + ..write('category: $category') + ..write(')')) + .toString(); + } + @override int get hashCode => (((id.hashCode) * 31 + title.hashCode) * 31 + instructions.hashCode) * @@ -186,6 +206,16 @@ class Ingredient { name: name ?? this.name, caloriesPer100g: caloriesPer100g ?? this.caloriesPer100g, ); + @override + String toString() { + return (StringBuffer('Ingredient(') + ..write('id: $id, ') + ..write('name: $name, ') + ..write('caloriesPer100g: $caloriesPer100g') + ..write(')')) + .toString(); + } + @override int get hashCode => ((id.hashCode) * 31 + name.hashCode) * 31 + caloriesPer100g.hashCode; @@ -270,6 +300,16 @@ class IngredientInRecipe { ingredient: ingredient ?? this.ingredient, amountInGrams: amountInGrams ?? this.amountInGrams, ); + @override + String toString() { + return (StringBuffer('IngredientInRecipe(') + ..write('recipe: $recipe, ') + ..write('ingredient: $ingredient, ') + ..write('amountInGrams: $amountInGrams') + ..write(')')) + .toString(); + } + @override int get hashCode => ((recipe.hashCode) * 31 + ingredient.hashCode) * 31 + diff --git a/moor/test/data/tables/todos.g.dart b/moor/test/data/tables/todos.g.dart index 37bf7f4d..52e1ad9d 100644 --- a/moor/test/data/tables/todos.g.dart +++ b/moor/test/data/tables/todos.g.dart @@ -39,6 +39,18 @@ class TodoEntry { targetDate: targetDate ?? this.targetDate, category: category ?? this.category, ); + @override + String toString() { + return (StringBuffer('TodoEntry(') + ..write('id: $id, ') + ..write('title: $title, ') + ..write('content: $content, ') + ..write('targetDate: $targetDate, ') + ..write('category: $category') + ..write(')')) + .toString(); + } + @override int get hashCode => ((((id.hashCode) * 31 + title.hashCode) * 31 + content.hashCode) * 31 + @@ -140,6 +152,15 @@ class Category { id: id ?? this.id, description: description ?? this.description, ); + @override + String toString() { + return (StringBuffer('Category(') + ..write('id: $id, ') + ..write('description: $description') + ..write(')')) + .toString(); + } + @override int get hashCode => (id.hashCode) * 31 + description.hashCode; @override @@ -210,6 +231,16 @@ class User { name: name ?? this.name, isAwesome: isAwesome ?? this.isAwesome, ); + @override + String toString() { + return (StringBuffer('User(') + ..write('id: $id, ') + ..write('name: $name, ') + ..write('isAwesome: $isAwesome') + ..write(')')) + .toString(); + } + @override int get hashCode => ((id.hashCode) * 31 + name.hashCode) * 31 + isAwesome.hashCode; @@ -285,6 +316,15 @@ class SharedTodo { todo: todo ?? this.todo, user: user ?? this.user, ); + @override + String toString() { + return (StringBuffer('SharedTodo(') + ..write('todo: $todo, ') + ..write('user: $user') + ..write(')')) + .toString(); + } + @override int get hashCode => (todo.hashCode) * 31 + user.hashCode; @override diff --git a/moor_flutter/CHANGELOG.md b/moor_flutter/CHANGELOG.md index 3b8ec0ae..3737868f 100644 --- a/moor_flutter/CHANGELOG.md +++ b/moor_flutter/CHANGELOG.md @@ -1,2 +1,5 @@ +## 1.1.0 +- Transactions + ## 1.0.0 - Initial release \ No newline at end of file diff --git a/moor_generator/CHANGELOG.md b/moor_generator/CHANGELOG.md index cd631326..7676dc3a 100644 --- a/moor_generator/CHANGELOG.md +++ b/moor_generator/CHANGELOG.md @@ -1,2 +1,5 @@ +## 1.1.0 +- The generated data classes now implement `toString()` + ## 1.0.0 - Initial version of the Moor generator \ No newline at end of file diff --git a/moor_generator/lib/src/writer/data_class_writer.dart b/moor_generator/lib/src/writer/data_class_writer.dart index a6745804..3a002615 100644 --- a/moor_generator/lib/src/writer/data_class_writer.dart +++ b/moor_generator/lib/src/writer/data_class_writer.dart @@ -29,6 +29,8 @@ class DataClassWriter { // And a convenience method to copy data from this class. _writeCopyWith(buffer); + _writeToString(buffer); + buffer.write('@override\n int get hashCode => '); if (table.columns.isEmpty) { @@ -118,6 +120,35 @@ class DataClassWriter { buffer.write(');'); } + void _writeToString(StringBuffer buffer) { + /* + @override + String toString() { + return (StringBuffer('User(') + ..write('id: $id,') + ..write('name: $name,') + ..write('isAwesome: $isAwesome') + ..write(')')).toString(); + } + */ + + buffer + ..write('@override\nString toString() {') + ..write("return (StringBuffer('${table.dartTypeName}(')"); + + for (var i = 0; i < table.columns.length; i++) { + final column = table.columns[i]; + final getterName = column.dartGetterName; + + buffer.write("..write('$getterName: \$$getterName"); + if (i != table.columns.length - 1) buffer.write(', '); + + buffer.write("')"); + } + + buffer..write("..write(')')).toString();")..write('\}\n'); + } + /// Recursively creates the implementation for hashCode of the data class, /// assuming it has at least one field. When it has one field, we just return /// the hash code of that field. Otherwise, we multiply it with 31 and add