diff --git a/moor/example/example.g.dart b/moor/example/example.g.dart index 4c11806c..628b2514 100644 --- a/moor/example/example.g.dart +++ b/moor/example/example.g.dart @@ -127,6 +127,15 @@ class CategoriesCompanion extends UpdateCompanion { } return map; } + + @override + String toString() { + return (StringBuffer('CategoriesCompanion(') + ..write('id: $id, ') + ..write('description: $description') + ..write(')')) + .toString(); + } } class $CategoriesTable extends Categories @@ -371,6 +380,17 @@ class RecipesCompanion extends UpdateCompanion { } return map; } + + @override + String toString() { + return (StringBuffer('RecipesCompanion(') + ..write('id: $id, ') + ..write('title: $title, ') + ..write('instructions: $instructions, ') + ..write('category: $category') + ..write(')')) + .toString(); + } } class $RecipesTable extends Recipes with TableInfo<$RecipesTable, Recipe> { @@ -615,6 +635,16 @@ class IngredientsCompanion extends UpdateCompanion { } return map; } + + @override + String toString() { + return (StringBuffer('IngredientsCompanion(') + ..write('id: $id, ') + ..write('name: $name, ') + ..write('caloriesPer100g: $caloriesPer100g') + ..write(')')) + .toString(); + } } class $IngredientsTable extends Ingredients @@ -858,6 +888,16 @@ class IngredientInRecipesCompanion extends UpdateCompanion { } return map; } + + @override + String toString() { + return (StringBuffer('IngredientInRecipesCompanion(') + ..write('recipe: $recipe, ') + ..write('ingredient: $ingredient, ') + ..write('amountInGrams: $amountInGrams') + ..write(')')) + .toString(); + } } class $IngredientInRecipesTable extends IngredientInRecipes diff --git a/moor/lib/src/runtime/data_class.dart b/moor/lib/src/runtime/data_class.dart index eb7dfbc5..1dcd45b6 100644 --- a/moor/lib/src/runtime/data_class.dart +++ b/moor/lib/src/runtime/data_class.dart @@ -122,6 +122,9 @@ class Value { const Value.absent() : value = null, present = false; + + @override + String toString() => present ? 'Value($value)' : 'Value.absent()'; } /// Serializer responsible for mapping atomic types from and to json. diff --git a/moor/test/data/tables/custom_tables.g.dart b/moor/test/data/tables/custom_tables.g.dart index ed9795b6..36448310 100644 --- a/moor/test/data/tables/custom_tables.g.dart +++ b/moor/test/data/tables/custom_tables.g.dart @@ -199,6 +199,17 @@ class ConfigCompanion extends UpdateCompanion { } return map; } + + @override + String toString() { + return (StringBuffer('ConfigCompanion(') + ..write('configKey: $configKey, ') + ..write('configValue: $configValue, ') + ..write('syncState: $syncState, ') + ..write('syncStateImplicit: $syncStateImplicit') + ..write(')')) + .toString(); + } } class ConfigTable extends Table with TableInfo { @@ -407,6 +418,15 @@ class WithDefaultsCompanion extends UpdateCompanion { } return map; } + + @override + String toString() { + return (StringBuffer('WithDefaultsCompanion(') + ..write('a: $a, ') + ..write('b: $b') + ..write(')')) + .toString(); + } } class WithDefaults extends Table with TableInfo { @@ -564,6 +584,14 @@ class NoIdsCompanion extends UpdateCompanion { } return map; } + + @override + String toString() { + return (StringBuffer('NoIdsCompanion(') + ..write('payload: $payload') + ..write(')')) + .toString(); + } } class NoIds extends Table with TableInfo { @@ -759,6 +787,16 @@ class WithConstraintsCompanion extends UpdateCompanion { } return map; } + + @override + String toString() { + return (StringBuffer('WithConstraintsCompanion(') + ..write('a: $a, ') + ..write('b: $b, ') + ..write('c: $c') + ..write(')')) + .toString(); + } } class WithConstraints extends Table @@ -1012,6 +1050,17 @@ class MytableCompanion extends UpdateCompanion { } return map; } + + @override + String toString() { + return (StringBuffer('MytableCompanion(') + ..write('someid: $someid, ') + ..write('sometext: $sometext, ') + ..write('somebool: $somebool, ') + ..write('somedate: $somedate') + ..write(')')) + .toString(); + } } class Mytable extends Table with TableInfo { @@ -1242,6 +1291,16 @@ class EmailCompanion extends UpdateCompanion { } return map; } + + @override + String toString() { + return (StringBuffer('EmailCompanion(') + ..write('sender: $sender, ') + ..write('title: $title, ') + ..write('body: $body') + ..write(')')) + .toString(); + } } class Email extends Table diff --git a/moor/test/data/tables/todos.g.dart b/moor/test/data/tables/todos.g.dart index 4f0f2df6..99a9740e 100644 --- a/moor/test/data/tables/todos.g.dart +++ b/moor/test/data/tables/todos.g.dart @@ -217,6 +217,18 @@ class TodosTableCompanion extends UpdateCompanion { } return map; } + + @override + String toString() { + return (StringBuffer('TodosTableCompanion(') + ..write('id: $id, ') + ..write('title: $title, ') + ..write('content: $content, ') + ..write('targetDate: $targetDate, ') + ..write('category: $category') + ..write(')')) + .toString(); + } } class $TodosTableTable extends TodosTable @@ -484,6 +496,16 @@ class CategoriesCompanion extends UpdateCompanion { } return map; } + + @override + String toString() { + return (StringBuffer('CategoriesCompanion(') + ..write('id: $id, ') + ..write('description: $description, ') + ..write('priority: $priority') + ..write(')')) + .toString(); + } } class $CategoriesTable extends Categories @@ -773,6 +795,18 @@ class UsersCompanion extends UpdateCompanion { } return map; } + + @override + String toString() { + return (StringBuffer('UsersCompanion(') + ..write('id: $id, ') + ..write('name: $name, ') + ..write('isAwesome: $isAwesome, ') + ..write('profilePicture: $profilePicture, ') + ..write('creationTime: $creationTime') + ..write(')')) + .toString(); + } } class $UsersTable extends Users with TableInfo<$UsersTable, User> { @@ -1006,6 +1040,15 @@ class SharedTodosCompanion extends UpdateCompanion { } return map; } + + @override + String toString() { + return (StringBuffer('SharedTodosCompanion(') + ..write('todo: $todo, ') + ..write('user: $user') + ..write(')')) + .toString(); + } } class $SharedTodosTable extends SharedTodos @@ -1239,6 +1282,16 @@ class TableWithoutPKCompanion extends UpdateCompanion { } return map; } + + @override + String toString() { + return (StringBuffer('TableWithoutPKCompanion(') + ..write('notReallyAnId: $notReallyAnId, ') + ..write('someFloat: $someFloat, ') + ..write('custom: $custom') + ..write(')')) + .toString(); + } } class $TableWithoutPKTable extends TableWithoutPK @@ -1447,6 +1500,15 @@ class PureDefaultsCompanion extends UpdateCompanion { } return map; } + + @override + String toString() { + return (StringBuffer('PureDefaultsCompanion(') + ..write('id: $id, ') + ..write('txt: $txt') + ..write(')')) + .toString(); + } } class $PureDefaultsTable extends PureDefaults diff --git a/moor_generator/lib/src/writer/tables/update_companion_writer.dart b/moor_generator/lib/src/writer/tables/update_companion_writer.dart index ff881c96..b65c7f00 100644 --- a/moor_generator/lib/src/writer/tables/update_companion_writer.dart +++ b/moor_generator/lib/src/writer/tables/update_companion_writer.dart @@ -23,6 +23,7 @@ class UpdateCompanionWriter { _writeCopyWith(); _writeToColumnsOverride(); + _writeToString(); _buffer.write('}\n'); } @@ -179,4 +180,33 @@ class UpdateCompanionWriter { _buffer.write('return map; \n}\n'); } + + void _writeToString() { + /* + @override + String toString() { + return (StringBuffer('Category(') + ..write('id: $id, ') + ..write('description: $description') + ..write(')')) + .toString(); + */ + + _buffer + ..write('@override\nString toString() {\n') + ..write('return (StringBuffer(' + "'${table.getNameForCompanionClass(scope.options)}(')"); + + for (var i = 0; i < table.columns.length; i++) { + final column = table.columns[i]; + final dartGetterName = column.dartGetterName; + + _buffer.write("..write('$dartGetterName: \$$dartGetterName"); + if (i != table.columns.length - 1) _buffer.write(', '); + + _buffer.write("')"); + } + + _buffer..write("..write(')')).toString();")..write('\}\n'); + } }