From 8fc3902955ac396c04f8f888e001b7f8d6bcfbcb Mon Sep 17 00:00:00 2001 From: Tobe O Date: Mon, 8 Apr 2019 15:02:27 -0400 Subject: [PATCH] Use inflection2 --- angel_orm_generator/CHANGELOG.md | 2 +- .../lib/src/orm_build_context.dart | 2 +- .../lib/src/orm_generator.dart | 3 +- angel_orm_generator/pubspec.yaml | 7 +- .../build.yaml | 28 +-- angel_orm_test/lib/src/models/author.g.dart | 29 ++- angel_orm_test/lib/src/models/book.g.dart | 29 ++- angel_orm_test/lib/src/models/car.g.dart | 29 ++- angel_orm_test/lib/src/models/customer.g.dart | 29 ++- angel_orm_test/lib/src/models/foot.g.dart | 33 +++- angel_orm_test/lib/src/models/fruit.g.dart | 29 ++- angel_orm_test/lib/src/models/has_car.g.dart | 29 ++- angel_orm_test/lib/src/models/has_map.dart | 11 +- angel_orm_test/lib/src/models/has_map.g.dart | 29 ++- angel_orm_test/lib/src/models/leg.g.dart | 29 ++- angel_orm_test/lib/src/models/order.g.dart | 29 ++- angel_orm_test/lib/src/models/tree.g.dart | 29 ++- .../lib/src/models/unorthodox.g.dart | 174 +++++++++++++++++- angel_orm_test/lib/src/models/user.g.dart | 87 ++++++++- 19 files changed, 592 insertions(+), 45 deletions(-) rename {angel_orm_generator => angel_orm_test}/build.yaml (58%) diff --git a/angel_orm_generator/CHANGELOG.md b/angel_orm_generator/CHANGELOG.md index db42b016..16e85ce0 100644 --- a/angel_orm_generator/CHANGELOG.md +++ b/angel_orm_generator/CHANGELOG.md @@ -1,4 +1,4 @@ -# 2.0.0-dev.8 +# 2.0.0 * `parse` -> `tryParse` where used. # 2.0.0-dev.7 diff --git a/angel_orm_generator/lib/src/orm_build_context.dart b/angel_orm_generator/lib/src/orm_build_context.dart index f21e6a1a..f22ed271 100644 --- a/angel_orm_generator/lib/src/orm_build_context.dart +++ b/angel_orm_generator/lib/src/orm_build_context.dart @@ -10,7 +10,7 @@ import 'package:angel_serialize_generator/angel_serialize_generator.dart'; import 'package:angel_serialize_generator/build_context.dart'; import 'package:angel_serialize_generator/context.dart'; import 'package:build/build.dart'; -import 'package:inflection/inflection.dart'; +import 'package:inflection2/inflection2.dart'; import 'package:recase/recase.dart'; import 'package:source_gen/source_gen.dart'; diff --git a/angel_orm_generator/lib/src/orm_generator.dart b/angel_orm_generator/lib/src/orm_generator.dart index e0e7deae..fb461591 100644 --- a/angel_orm_generator/lib/src/orm_generator.dart +++ b/angel_orm_generator/lib/src/orm_generator.dart @@ -737,7 +737,8 @@ class OrmGenerator extends GeneratorForAnnotation { var parsedId = prop.property(foreignField.name); if (isSpecialId(foreign, field)) { - parsedId = (refer('int').property('tryParse').call([parsedId])); + parsedId = + (refer('int').property('tryParse').call([parsedId])); } var cond = prop.notEqualTo(literalNull); diff --git a/angel_orm_generator/pubspec.yaml b/angel_orm_generator/pubspec.yaml index e3d6d4a4..d0f583d9 100644 --- a/angel_orm_generator/pubspec.yaml +++ b/angel_orm_generator/pubspec.yaml @@ -1,5 +1,5 @@ name: angel_orm_generator -version: 2.0.0-dev.7 +version: 2.0.0 description: Code generators for Angel's ORM. Generates query builder classes. author: Tobe O homepage: https://github.com/angel-dart/orm @@ -16,10 +16,7 @@ dependencies: build_config: ^0.3.0 code_builder: ^3.0.0 dart_style: ^1.0.0 - inflection: - git: - url: https://github.com/thosakwe/dart-inflection.git - ref: dart2 + inflection2: ^0.4.2 meta: ^1.0.0 path: ^1.0.0 recase: ^2.0.0 diff --git a/angel_orm_generator/build.yaml b/angel_orm_test/build.yaml similarity index 58% rename from angel_orm_generator/build.yaml rename to angel_orm_test/build.yaml index ef954f9b..36867678 100644 --- a/angel_orm_generator/build.yaml +++ b/angel_orm_test/build.yaml @@ -21,22 +21,22 @@ builders: targets: _standalone: sources: - - test/models/author.dart - - test/models/car.dart - - test/models/customer.dart - - test/models/foot.dart - - test/models/fruit.dart - - test/models/has_map.dart - - test/models/role.dart - - test/models/unorthodox.dart + - lib/src/models/author.dart + - lib/src/models/car.dart + - lib/src/models/customer.dart + - lib/src/models/foot.dart + - lib/src/models/fruit.dart + - lib/src/models/has_map.dart + - lib/src/models/role.dart + - lib/src/models/unorthodox.dart $default: dependencies: - angel_serialize_generator - :_standalone sources: - - test/models/book.dart - - test/models/has_car.dart - - test/models/leg.dart - - test/models/order.dart - - test/models/tree.dart - - test/models/user.dart \ No newline at end of file + - lib/src/models/book.dart + - lib/src/models/has_car.dart + - lib/src/models/leg.dart + - lib/src/models/order.dart + - lib/src/models/tree.dart + - lib/src/models/user.dart \ No newline at end of file diff --git a/angel_orm_test/lib/src/models/author.g.dart b/angel_orm_test/lib/src/models/author.g.dart index 7f83df61..a7560ad9 100644 --- a/angel_orm_test/lib/src/models/author.g.dart +++ b/angel_orm_test/lib/src/models/author.g.dart @@ -178,6 +178,11 @@ class Author extends _Author { return hashObjects([id, name, createdAt, updatedAt]); } + @override + String toString() { + return "Author(id=$id, name=$name, createdAt=$createdAt, updatedAt=$updatedAt)"; + } + Map toJson() { return AuthorSerializer.toMap(this); } @@ -187,7 +192,29 @@ class Author extends _Author { // SerializerGenerator // ************************************************************************** -abstract class AuthorSerializer { +const AuthorSerializer authorSerializer = const AuthorSerializer(); + +class AuthorEncoder extends Converter { + const AuthorEncoder(); + + @override + Map convert(Author model) => AuthorSerializer.toMap(model); +} + +class AuthorDecoder extends Converter { + const AuthorDecoder(); + + @override + Author convert(Map map) => AuthorSerializer.fromMap(map); +} + +class AuthorSerializer extends Codec { + const AuthorSerializer(); + + @override + get encoder => const AuthorEncoder(); + @override + get decoder => const AuthorDecoder(); static Author fromMap(Map map) { return new Author( id: map['id'] as String, diff --git a/angel_orm_test/lib/src/models/book.g.dart b/angel_orm_test/lib/src/models/book.g.dart index cbf349ed..6a29dbb6 100644 --- a/angel_orm_test/lib/src/models/book.g.dart +++ b/angel_orm_test/lib/src/models/book.g.dart @@ -243,6 +243,11 @@ class Book extends _Book { return hashObjects([id, author, partnerAuthor, name, createdAt, updatedAt]); } + @override + String toString() { + return "Book(id=$id, author=$author, partnerAuthor=$partnerAuthor, name=$name, createdAt=$createdAt, updatedAt=$updatedAt)"; + } + Map toJson() { return BookSerializer.toMap(this); } @@ -252,7 +257,29 @@ class Book extends _Book { // SerializerGenerator // ************************************************************************** -abstract class BookSerializer { +const BookSerializer bookSerializer = const BookSerializer(); + +class BookEncoder extends Converter { + const BookEncoder(); + + @override + Map convert(Book model) => BookSerializer.toMap(model); +} + +class BookDecoder extends Converter { + const BookDecoder(); + + @override + Book convert(Map map) => BookSerializer.fromMap(map); +} + +class BookSerializer extends Codec { + const BookSerializer(); + + @override + get encoder => const BookEncoder(); + @override + get decoder => const BookDecoder(); static Book fromMap(Map map) { return new Book( id: map['id'] as String, diff --git a/angel_orm_test/lib/src/models/car.g.dart b/angel_orm_test/lib/src/models/car.g.dart index 945402ad..1610163b 100644 --- a/angel_orm_test/lib/src/models/car.g.dart +++ b/angel_orm_test/lib/src/models/car.g.dart @@ -261,6 +261,11 @@ class Car extends _Car { ]); } + @override + String toString() { + return "Car(id=$id, make=$make, description=$description, familyFriendly=$familyFriendly, recalledAt=$recalledAt, createdAt=$createdAt, updatedAt=$updatedAt)"; + } + Map toJson() { return CarSerializer.toMap(this); } @@ -270,7 +275,29 @@ class Car extends _Car { // SerializerGenerator // ************************************************************************** -abstract class CarSerializer { +const CarSerializer carSerializer = const CarSerializer(); + +class CarEncoder extends Converter { + const CarEncoder(); + + @override + Map convert(Car model) => CarSerializer.toMap(model); +} + +class CarDecoder extends Converter { + const CarDecoder(); + + @override + Car convert(Map map) => CarSerializer.fromMap(map); +} + +class CarSerializer extends Codec { + const CarSerializer(); + + @override + get encoder => const CarEncoder(); + @override + get decoder => const CarDecoder(); static Car fromMap(Map map) { return new Car( id: map['id'] as String, diff --git a/angel_orm_test/lib/src/models/customer.g.dart b/angel_orm_test/lib/src/models/customer.g.dart index f246c189..486133e1 100644 --- a/angel_orm_test/lib/src/models/customer.g.dart +++ b/angel_orm_test/lib/src/models/customer.g.dart @@ -159,6 +159,11 @@ class Customer extends _Customer { return hashObjects([id, createdAt, updatedAt]); } + @override + String toString() { + return "Customer(id=$id, createdAt=$createdAt, updatedAt=$updatedAt)"; + } + Map toJson() { return CustomerSerializer.toMap(this); } @@ -168,7 +173,29 @@ class Customer extends _Customer { // SerializerGenerator // ************************************************************************** -abstract class CustomerSerializer { +const CustomerSerializer customerSerializer = const CustomerSerializer(); + +class CustomerEncoder extends Converter { + const CustomerEncoder(); + + @override + Map convert(Customer model) => CustomerSerializer.toMap(model); +} + +class CustomerDecoder extends Converter { + const CustomerDecoder(); + + @override + Customer convert(Map map) => CustomerSerializer.fromMap(map); +} + +class CustomerSerializer extends Codec { + const CustomerSerializer(); + + @override + get encoder => const CustomerEncoder(); + @override + get decoder => const CustomerDecoder(); static Customer fromMap(Map map) { return new Customer( id: map['id'] as String, diff --git a/angel_orm_test/lib/src/models/foot.g.dart b/angel_orm_test/lib/src/models/foot.g.dart index c23b674b..8e78cd27 100644 --- a/angel_orm_test/lib/src/models/foot.g.dart +++ b/angel_orm_test/lib/src/models/foot.g.dart @@ -70,7 +70,7 @@ class FootQuery extends Query { var model = Foot( id: row[0].toString(), legId: (row[1] as int), - nToes: double.parse(row[2].toString()), + nToes: double.tryParse(row[2].toString()), createdAt: (row[3] as DateTime), updatedAt: (row[4] as DateTime)); return model; @@ -123,7 +123,7 @@ class FootQueryValues extends MapQueryValues { set legId(int value) => values['leg_id'] = value; double get nToes { - return double.parse((values['n_toes'] as String)); + return double.tryParse((values['n_toes'] as String)); } set nToes(double value) => values['n_toes'] = value.toString(); @@ -196,6 +196,11 @@ class Foot extends _Foot { return hashObjects([id, legId, nToes, createdAt, updatedAt]); } + @override + String toString() { + return "Foot(id=$id, legId=$legId, nToes=$nToes, createdAt=$createdAt, updatedAt=$updatedAt)"; + } + Map toJson() { return FootSerializer.toMap(this); } @@ -205,7 +210,29 @@ class Foot extends _Foot { // SerializerGenerator // ************************************************************************** -abstract class FootSerializer { +const FootSerializer footSerializer = const FootSerializer(); + +class FootEncoder extends Converter { + const FootEncoder(); + + @override + Map convert(Foot model) => FootSerializer.toMap(model); +} + +class FootDecoder extends Converter { + const FootDecoder(); + + @override + Foot convert(Map map) => FootSerializer.fromMap(map); +} + +class FootSerializer extends Codec { + const FootSerializer(); + + @override + get encoder => const FootEncoder(); + @override + get decoder => const FootDecoder(); static Foot fromMap(Map map) { return new Foot( id: map['id'] as String, diff --git a/angel_orm_test/lib/src/models/fruit.g.dart b/angel_orm_test/lib/src/models/fruit.g.dart index cb34d70a..115d589f 100644 --- a/angel_orm_test/lib/src/models/fruit.g.dart +++ b/angel_orm_test/lib/src/models/fruit.g.dart @@ -197,6 +197,11 @@ class Fruit extends _Fruit { return hashObjects([id, treeId, commonName, createdAt, updatedAt]); } + @override + String toString() { + return "Fruit(id=$id, treeId=$treeId, commonName=$commonName, createdAt=$createdAt, updatedAt=$updatedAt)"; + } + Map toJson() { return FruitSerializer.toMap(this); } @@ -206,7 +211,29 @@ class Fruit extends _Fruit { // SerializerGenerator // ************************************************************************** -abstract class FruitSerializer { +const FruitSerializer fruitSerializer = const FruitSerializer(); + +class FruitEncoder extends Converter { + const FruitEncoder(); + + @override + Map convert(Fruit model) => FruitSerializer.toMap(model); +} + +class FruitDecoder extends Converter { + const FruitDecoder(); + + @override + Fruit convert(Map map) => FruitSerializer.fromMap(map); +} + +class FruitSerializer extends Codec { + const FruitSerializer(); + + @override + get encoder => const FruitEncoder(); + @override + get decoder => const FruitDecoder(); static Fruit fromMap(Map map) { return new Fruit( id: map['id'] as String, diff --git a/angel_orm_test/lib/src/models/has_car.g.dart b/angel_orm_test/lib/src/models/has_car.g.dart index 340cdcae..7886c6e5 100644 --- a/angel_orm_test/lib/src/models/has_car.g.dart +++ b/angel_orm_test/lib/src/models/has_car.g.dart @@ -176,6 +176,11 @@ class HasCar extends _HasCar { return hashObjects([id, type, createdAt, updatedAt]); } + @override + String toString() { + return "HasCar(id=$id, type=$type, createdAt=$createdAt, updatedAt=$updatedAt)"; + } + Map toJson() { return HasCarSerializer.toMap(this); } @@ -185,7 +190,29 @@ class HasCar extends _HasCar { // SerializerGenerator // ************************************************************************** -abstract class HasCarSerializer { +const HasCarSerializer hasCarSerializer = const HasCarSerializer(); + +class HasCarEncoder extends Converter { + const HasCarEncoder(); + + @override + Map convert(HasCar model) => HasCarSerializer.toMap(model); +} + +class HasCarDecoder extends Converter { + const HasCarDecoder(); + + @override + HasCar convert(Map map) => HasCarSerializer.fromMap(map); +} + +class HasCarSerializer extends Codec { + const HasCarSerializer(); + + @override + get encoder => const HasCarEncoder(); + @override + get decoder => const HasCarDecoder(); static HasCar fromMap(Map map) { if (map['type'] == null) { throw new FormatException("Missing required field 'type' on HasCar."); diff --git a/angel_orm_test/lib/src/models/has_map.dart b/angel_orm_test/lib/src/models/has_map.dart index e2d42840..8414de94 100644 --- a/angel_orm_test/lib/src/models/has_map.dart +++ b/angel_orm_test/lib/src/models/has_map.dart @@ -1,15 +1,24 @@ import 'dart:convert'; import 'package:angel_migration/angel_migration.dart'; -import 'package:angel_model/angel_model.dart'; import 'package:angel_orm/angel_orm.dart'; import 'package:angel_serialize/angel_serialize.dart'; import 'package:collection/collection.dart'; part 'has_map.g.dart'; +String _boolToCustom(bool v) => v ? 'yes' : 'no'; +bool _customToBool(v) => v == 'yes'; + @orm @serializable abstract class _HasMap { Map get value; List get list; + + // TODO: Support custom serializers + // @SerializableField( + // serializer: #_boolToCustom, + // deserializer: #_customToBool, + // serializesTo: String) + // bool get customBool; } diff --git a/angel_orm_test/lib/src/models/has_map.g.dart b/angel_orm_test/lib/src/models/has_map.g.dart index 0a662e5d..3452403f 100644 --- a/angel_orm_test/lib/src/models/has_map.g.dart +++ b/angel_orm_test/lib/src/models/has_map.g.dart @@ -145,6 +145,11 @@ class HasMap implements _HasMap { return hashObjects([value, list]); } + @override + String toString() { + return "HasMap(value=$value, list=$list)"; + } + Map toJson() { return HasMapSerializer.toMap(this); } @@ -154,7 +159,29 @@ class HasMap implements _HasMap { // SerializerGenerator // ************************************************************************** -abstract class HasMapSerializer { +const HasMapSerializer hasMapSerializer = const HasMapSerializer(); + +class HasMapEncoder extends Converter { + const HasMapEncoder(); + + @override + Map convert(HasMap model) => HasMapSerializer.toMap(model); +} + +class HasMapDecoder extends Converter { + const HasMapDecoder(); + + @override + HasMap convert(Map map) => HasMapSerializer.fromMap(map); +} + +class HasMapSerializer extends Codec { + const HasMapSerializer(); + + @override + get encoder => const HasMapEncoder(); + @override + get decoder => const HasMapDecoder(); static HasMap fromMap(Map map) { return new HasMap( value: map['value'] is Map diff --git a/angel_orm_test/lib/src/models/leg.g.dart b/angel_orm_test/lib/src/models/leg.g.dart index 243bcbfb..db929e7f 100644 --- a/angel_orm_test/lib/src/models/leg.g.dart +++ b/angel_orm_test/lib/src/models/leg.g.dart @@ -197,6 +197,11 @@ class Leg extends _Leg { return hashObjects([id, foot, name, createdAt, updatedAt]); } + @override + String toString() { + return "Leg(id=$id, foot=$foot, name=$name, createdAt=$createdAt, updatedAt=$updatedAt)"; + } + Map toJson() { return LegSerializer.toMap(this); } @@ -206,7 +211,29 @@ class Leg extends _Leg { // SerializerGenerator // ************************************************************************** -abstract class LegSerializer { +const LegSerializer legSerializer = const LegSerializer(); + +class LegEncoder extends Converter { + const LegEncoder(); + + @override + Map convert(Leg model) => LegSerializer.toMap(model); +} + +class LegDecoder extends Converter { + const LegDecoder(); + + @override + Leg convert(Map map) => LegSerializer.fromMap(map); +} + +class LegSerializer extends Codec { + const LegSerializer(); + + @override + get encoder => const LegEncoder(); + @override + get decoder => const LegDecoder(); static Leg fromMap(Map map) { return new Leg( id: map['id'] as String, diff --git a/angel_orm_test/lib/src/models/order.g.dart b/angel_orm_test/lib/src/models/order.g.dart index 170eaf5a..8fec0eff 100644 --- a/angel_orm_test/lib/src/models/order.g.dart +++ b/angel_orm_test/lib/src/models/order.g.dart @@ -262,6 +262,11 @@ class Order extends _Order { [id, customer, employeeId, orderDate, shipperId, createdAt, updatedAt]); } + @override + String toString() { + return "Order(id=$id, customer=$customer, employeeId=$employeeId, orderDate=$orderDate, shipperId=$shipperId, createdAt=$createdAt, updatedAt=$updatedAt)"; + } + Map toJson() { return OrderSerializer.toMap(this); } @@ -271,7 +276,29 @@ class Order extends _Order { // SerializerGenerator // ************************************************************************** -abstract class OrderSerializer { +const OrderSerializer orderSerializer = const OrderSerializer(); + +class OrderEncoder extends Converter { + const OrderEncoder(); + + @override + Map convert(Order model) => OrderSerializer.toMap(model); +} + +class OrderDecoder extends Converter { + const OrderDecoder(); + + @override + Order convert(Map map) => OrderSerializer.fromMap(map); +} + +class OrderSerializer extends Codec { + const OrderSerializer(); + + @override + get encoder => const OrderEncoder(); + @override + get decoder => const OrderDecoder(); static Order fromMap(Map map) { return new Order( id: map['id'] as String, diff --git a/angel_orm_test/lib/src/models/tree.g.dart b/angel_orm_test/lib/src/models/tree.g.dart index bfb22e0a..853c7f7f 100644 --- a/angel_orm_test/lib/src/models/tree.g.dart +++ b/angel_orm_test/lib/src/models/tree.g.dart @@ -260,6 +260,11 @@ class Tree extends _Tree { return hashObjects([id, rings, fruits, createdAt, updatedAt]); } + @override + String toString() { + return "Tree(id=$id, rings=$rings, fruits=$fruits, createdAt=$createdAt, updatedAt=$updatedAt)"; + } + Map toJson() { return TreeSerializer.toMap(this); } @@ -269,7 +274,29 @@ class Tree extends _Tree { // SerializerGenerator // ************************************************************************** -abstract class TreeSerializer { +const TreeSerializer treeSerializer = const TreeSerializer(); + +class TreeEncoder extends Converter { + const TreeEncoder(); + + @override + Map convert(Tree model) => TreeSerializer.toMap(model); +} + +class TreeDecoder extends Converter { + const TreeDecoder(); + + @override + Tree convert(Map map) => TreeSerializer.fromMap(map); +} + +class TreeSerializer extends Codec { + const TreeSerializer(); + + @override + get encoder => const TreeEncoder(); + @override + get decoder => const TreeDecoder(); static Tree fromMap(Map map) { return new Tree( id: map['id'] as String, diff --git a/angel_orm_test/lib/src/models/unorthodox.g.dart b/angel_orm_test/lib/src/models/unorthodox.g.dart index 6a19d955..efcaeb38 100644 --- a/angel_orm_test/lib/src/models/unorthodox.g.dart +++ b/angel_orm_test/lib/src/models/unorthodox.g.dart @@ -839,6 +839,11 @@ class Unorthodox implements _Unorthodox { return hashObjects([name]); } + @override + String toString() { + return "Unorthodox(name=$name)"; + } + Map toJson() { return UnorthodoxSerializer.toMap(this); } @@ -898,6 +903,11 @@ class WeirdJoin implements _WeirdJoin { return hashObjects([id, unorthodox, song, numbas, foos]); } + @override + String toString() { + return "WeirdJoin(id=$id, unorthodox=$unorthodox, song=$song, numbas=$numbas, foos=$foos)"; + } + Map toJson() { return WeirdJoinSerializer.toMap(this); } @@ -950,6 +960,11 @@ class Song extends _Song { return hashObjects([id, weirdJoinId, title, createdAt, updatedAt]); } + @override + String toString() { + return "Song(id=$id, weirdJoinId=$weirdJoinId, title=$title, createdAt=$createdAt, updatedAt=$updatedAt)"; + } + Map toJson() { return SongSerializer.toMap(this); } @@ -978,6 +993,11 @@ class Numba extends _Numba { return hashObjects([i, parent]); } + @override + String toString() { + return "Numba(i=$i, parent=$parent)"; + } + Map toJson() { return NumbaSerializer.toMap(this); } @@ -1010,6 +1030,11 @@ class Foo implements _Foo { return hashObjects([bar, weirdJoins]); } + @override + String toString() { + return "Foo(bar=$bar, weirdJoins=$weirdJoins)"; + } + Map toJson() { return FooSerializer.toMap(this); } @@ -1041,6 +1066,11 @@ class FooPivot implements _FooPivot { return hashObjects([weirdJoin, foo]); } + @override + String toString() { + return "FooPivot(weirdJoin=$weirdJoin, foo=$foo)"; + } + Map toJson() { return FooPivotSerializer.toMap(this); } @@ -1050,7 +1080,29 @@ class FooPivot implements _FooPivot { // SerializerGenerator // ************************************************************************** -abstract class UnorthodoxSerializer { +const UnorthodoxSerializer unorthodoxSerializer = const UnorthodoxSerializer(); + +class UnorthodoxEncoder extends Converter { + const UnorthodoxEncoder(); + + @override + Map convert(Unorthodox model) => UnorthodoxSerializer.toMap(model); +} + +class UnorthodoxDecoder extends Converter { + const UnorthodoxDecoder(); + + @override + Unorthodox convert(Map map) => UnorthodoxSerializer.fromMap(map); +} + +class UnorthodoxSerializer extends Codec { + const UnorthodoxSerializer(); + + @override + get encoder => const UnorthodoxEncoder(); + @override + get decoder => const UnorthodoxDecoder(); static Unorthodox fromMap(Map map) { return new Unorthodox(name: map['name'] as String); } @@ -1069,7 +1121,29 @@ abstract class UnorthodoxFields { static const String name = 'name'; } -abstract class WeirdJoinSerializer { +const WeirdJoinSerializer weirdJoinSerializer = const WeirdJoinSerializer(); + +class WeirdJoinEncoder extends Converter { + const WeirdJoinEncoder(); + + @override + Map convert(WeirdJoin model) => WeirdJoinSerializer.toMap(model); +} + +class WeirdJoinDecoder extends Converter { + const WeirdJoinDecoder(); + + @override + WeirdJoin convert(Map map) => WeirdJoinSerializer.fromMap(map); +} + +class WeirdJoinSerializer extends Codec { + const WeirdJoinSerializer(); + + @override + get encoder => const WeirdJoinEncoder(); + @override + get decoder => const WeirdJoinDecoder(); static WeirdJoin fromMap(Map map) { return new WeirdJoin( id: map['id'] as int, @@ -1127,7 +1201,29 @@ abstract class WeirdJoinFields { static const String foos = 'foos'; } -abstract class SongSerializer { +const SongSerializer songSerializer = const SongSerializer(); + +class SongEncoder extends Converter { + const SongEncoder(); + + @override + Map convert(Song model) => SongSerializer.toMap(model); +} + +class SongDecoder extends Converter { + const SongDecoder(); + + @override + Song convert(Map map) => SongSerializer.fromMap(map); +} + +class SongSerializer extends Codec { + const SongSerializer(); + + @override + get encoder => const SongEncoder(); + @override + get decoder => const SongDecoder(); static Song fromMap(Map map) { return new Song( id: map['id'] as String, @@ -1179,7 +1275,29 @@ abstract class SongFields { static const String updatedAt = 'updated_at'; } -abstract class NumbaSerializer { +const NumbaSerializer numbaSerializer = const NumbaSerializer(); + +class NumbaEncoder extends Converter { + const NumbaEncoder(); + + @override + Map convert(Numba model) => NumbaSerializer.toMap(model); +} + +class NumbaDecoder extends Converter { + const NumbaDecoder(); + + @override + Numba convert(Map map) => NumbaSerializer.fromMap(map); +} + +class NumbaSerializer extends Codec { + const NumbaSerializer(); + + @override + get encoder => const NumbaEncoder(); + @override + get decoder => const NumbaDecoder(); static Numba fromMap(Map map) { return new Numba(i: map['i'] as int, parent: map['parent'] as int); } @@ -1200,7 +1318,29 @@ abstract class NumbaFields { static const String parent = 'parent'; } -abstract class FooSerializer { +const FooSerializer fooSerializer = const FooSerializer(); + +class FooEncoder extends Converter { + const FooEncoder(); + + @override + Map convert(Foo model) => FooSerializer.toMap(model); +} + +class FooDecoder extends Converter { + const FooDecoder(); + + @override + Foo convert(Map map) => FooSerializer.fromMap(map); +} + +class FooSerializer extends Codec { + const FooSerializer(); + + @override + get encoder => const FooEncoder(); + @override + get decoder => const FooDecoder(); static Foo fromMap(Map map) { return new Foo( bar: map['bar'] as String, @@ -1232,7 +1372,29 @@ abstract class FooFields { static const String weirdJoins = 'weird_joins'; } -abstract class FooPivotSerializer { +const FooPivotSerializer fooPivotSerializer = const FooPivotSerializer(); + +class FooPivotEncoder extends Converter { + const FooPivotEncoder(); + + @override + Map convert(FooPivot model) => FooPivotSerializer.toMap(model); +} + +class FooPivotDecoder extends Converter { + const FooPivotDecoder(); + + @override + FooPivot convert(Map map) => FooPivotSerializer.fromMap(map); +} + +class FooPivotSerializer extends Codec { + const FooPivotSerializer(); + + @override + get encoder => const FooPivotEncoder(); + @override + get decoder => const FooPivotDecoder(); static FooPivot fromMap(Map map) { return new FooPivot( weirdJoin: map['weird_join'] != null diff --git a/angel_orm_test/lib/src/models/user.g.dart b/angel_orm_test/lib/src/models/user.g.dart index 0cf4a651..85f6eb16 100644 --- a/angel_orm_test/lib/src/models/user.g.dart +++ b/angel_orm_test/lib/src/models/user.g.dart @@ -635,6 +635,11 @@ class User extends _User { [id, username, password, email, roles, createdAt, updatedAt]); } + @override + String toString() { + return "User(id=$id, username=$username, password=$password, email=$email, roles=$roles, createdAt=$createdAt, updatedAt=$updatedAt)"; + } + Map toJson() { return UserSerializer.toMap(this); } @@ -663,6 +668,11 @@ class RoleUser implements _RoleUser { return hashObjects([role, user]); } + @override + String toString() { + return "RoleUser(role=$role, user=$user)"; + } + Map toJson() { return RoleUserSerializer.toMap(this); } @@ -717,6 +727,11 @@ class Role extends _Role { return hashObjects([id, name, users, createdAt, updatedAt]); } + @override + String toString() { + return "Role(id=$id, name=$name, users=$users, createdAt=$createdAt, updatedAt=$updatedAt)"; + } + Map toJson() { return RoleSerializer.toMap(this); } @@ -726,7 +741,29 @@ class Role extends _Role { // SerializerGenerator // ************************************************************************** -abstract class UserSerializer { +const UserSerializer userSerializer = const UserSerializer(); + +class UserEncoder extends Converter { + const UserEncoder(); + + @override + Map convert(User model) => UserSerializer.toMap(model); +} + +class UserDecoder extends Converter { + const UserDecoder(); + + @override + User convert(Map map) => UserSerializer.fromMap(map); +} + +class UserSerializer extends Codec { + const UserSerializer(); + + @override + get encoder => const UserEncoder(); + @override + get decoder => const UserDecoder(); static User fromMap(Map map) { return new User( id: map['id'] as String, @@ -793,7 +830,29 @@ abstract class UserFields { static const String updatedAt = 'updated_at'; } -abstract class RoleUserSerializer { +const RoleUserSerializer roleUserSerializer = const RoleUserSerializer(); + +class RoleUserEncoder extends Converter { + const RoleUserEncoder(); + + @override + Map convert(RoleUser model) => RoleUserSerializer.toMap(model); +} + +class RoleUserDecoder extends Converter { + const RoleUserDecoder(); + + @override + RoleUser convert(Map map) => RoleUserSerializer.fromMap(map); +} + +class RoleUserSerializer extends Codec { + const RoleUserSerializer(); + + @override + get encoder => const RoleUserEncoder(); + @override + get decoder => const RoleUserDecoder(); static RoleUser fromMap(Map map) { return new RoleUser( role: map['role'] != null @@ -823,7 +882,29 @@ abstract class RoleUserFields { static const String user = 'user'; } -abstract class RoleSerializer { +const RoleSerializer roleSerializer = const RoleSerializer(); + +class RoleEncoder extends Converter { + const RoleEncoder(); + + @override + Map convert(Role model) => RoleSerializer.toMap(model); +} + +class RoleDecoder extends Converter { + const RoleDecoder(); + + @override + Role convert(Map map) => RoleSerializer.fromMap(map); +} + +class RoleSerializer extends Codec { + const RoleSerializer(); + + @override + get encoder => const RoleEncoder(); + @override + get decoder => const RoleDecoder(); static Role fromMap(Map map) { return new Role( id: map['id'] as String,