From 2ba124c12e9c19bd61f21ea868197ae5730f0ee2 Mon Sep 17 00:00:00 2001 From: Tobe O Date: Fri, 24 Aug 2018 09:42:09 -0400 Subject: [PATCH] Read tableName for OrmBuildContext --- .../lib/src/orm_build_context.dart | 12 ++- angel_orm_generator/test/models/author.g.dart | 45 +++++++++++ .../test/models/author.serializer.g.dart | 54 +++++++++++++ angel_orm_generator/test/models/book.g.dart | 73 ++++++++++++++++++ .../test/models/book.serializer.g.dart | 69 +++++++++++++++++ angel_orm_generator/test/models/car.g.dart | 73 ++++++++++++++++++ .../test/models/car.serializer.g.dart | 73 ++++++++++++++++++ .../test/models/customer.g.dart | 39 ++++++++++ .../test/models/customer.serializer.g.dart | 49 ++++++++++++ angel_orm_generator/test/models/foot.g.dart | 54 +++++++++++++ .../test/models/foot.serializer.g.dart | 59 +++++++++++++++ angel_orm_generator/test/models/fruit.g.dart | 55 ++++++++++++++ .../test/models/fruit.serializer.g.dart | 59 +++++++++++++++ angel_orm_generator/test/models/leg.g.dart | 54 +++++++++++++ .../test/models/leg.serializer.g.dart | 59 +++++++++++++++ angel_orm_generator/test/models/order.g.dart | 73 ++++++++++++++++++ .../test/models/order.serializer.g.dart | 73 ++++++++++++++++++ angel_orm_generator/test/models/role.g.dart | 45 +++++++++++ .../test/models/role.serializer.g.dart | 54 +++++++++++++ angel_orm_generator/test/models/tree.g.dart | 61 +++++++++++++++ .../test/models/tree.serializer.g.dart | 59 +++++++++++++++ angel_orm_generator/test/models/user.g.dart | 75 +++++++++++++++++++ .../test/models/user.serializer.g.dart | 69 +++++++++++++++++ 23 files changed, 1334 insertions(+), 2 deletions(-) create mode 100644 angel_orm_generator/test/models/author.g.dart create mode 100644 angel_orm_generator/test/models/author.serializer.g.dart create mode 100644 angel_orm_generator/test/models/book.g.dart create mode 100644 angel_orm_generator/test/models/book.serializer.g.dart create mode 100644 angel_orm_generator/test/models/car.g.dart create mode 100644 angel_orm_generator/test/models/car.serializer.g.dart create mode 100644 angel_orm_generator/test/models/customer.g.dart create mode 100644 angel_orm_generator/test/models/customer.serializer.g.dart create mode 100644 angel_orm_generator/test/models/foot.g.dart create mode 100644 angel_orm_generator/test/models/foot.serializer.g.dart create mode 100644 angel_orm_generator/test/models/fruit.g.dart create mode 100644 angel_orm_generator/test/models/fruit.serializer.g.dart create mode 100644 angel_orm_generator/test/models/leg.g.dart create mode 100644 angel_orm_generator/test/models/leg.serializer.g.dart create mode 100644 angel_orm_generator/test/models/order.g.dart create mode 100644 angel_orm_generator/test/models/order.serializer.g.dart create mode 100644 angel_orm_generator/test/models/role.g.dart create mode 100644 angel_orm_generator/test/models/role.serializer.g.dart create mode 100644 angel_orm_generator/test/models/tree.g.dart create mode 100644 angel_orm_generator/test/models/tree.serializer.g.dart create mode 100644 angel_orm_generator/test/models/user.g.dart create mode 100644 angel_orm_generator/test/models/user.serializer.g.dart diff --git a/angel_orm_generator/lib/src/orm_build_context.dart b/angel_orm_generator/lib/src/orm_build_context.dart index f87b0f2d..6f3b763a 100644 --- a/angel_orm_generator/lib/src/orm_build_context.dart +++ b/angel_orm_generator/lib/src/orm_build_context.dart @@ -6,6 +6,8 @@ import 'package:angel_orm/angel_orm.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:recase/recase.dart'; import 'package:source_gen/source_gen.dart'; import 'readers.dart'; @@ -21,7 +23,12 @@ Future buildOrmContext( var buildCtx = await buildContext(clazz, annotation, buildStep, resolver, autoSnakeCaseNames, autoIdAndDateFields); var ormAnnotation = reviveORMAnnotation(annotation); - var ctx = new OrmBuildContext(buildCtx, ormAnnotation); + var ctx = new OrmBuildContext( + buildCtx, + ormAnnotation, + (ormAnnotation.tableName?.isNotEmpty == true) + ? ormAnnotation.tableName + : pluralize(new ReCase(clazz.name).snakeCase)); // Read all fields for (var field in buildCtx.fields) { @@ -107,10 +114,11 @@ Column reviveColumn(ConstantReader cr) { class OrmBuildContext { final BuildContext buildContext; final ORM ormAnnotation; + final String tableName; final Map columns = {}; - OrmBuildContext(this.buildContext, this.ormAnnotation); + OrmBuildContext(this.buildContext, this.ormAnnotation, this.tableName); } class _ColumnType implements ColumnType { diff --git a/angel_orm_generator/test/models/author.g.dart b/angel_orm_generator/test/models/author.g.dart new file mode 100644 index 00000000..1f4abf5f --- /dev/null +++ b/angel_orm_generator/test/models/author.g.dart @@ -0,0 +1,45 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of angel_orm.generator.models.author; + +// ************************************************************************** +// JsonModelGenerator +// ************************************************************************** + +@generatedSerializable +class Author extends _Author { + Author({this.id, this.name, this.createdAt, this.updatedAt}); + + @override + final String id; + + @override + final String name; + + @override + final DateTime createdAt; + + @override + final DateTime updatedAt; + + Author copyWith( + {String id, String name, DateTime createdAt, DateTime updatedAt}) { + return new Author( + id: id ?? this.id, + name: name ?? this.name, + createdAt: createdAt ?? this.createdAt, + updatedAt: updatedAt ?? this.updatedAt); + } + + bool operator ==(other) { + return other is _Author && + other.id == id && + other.name == name && + other.createdAt == createdAt && + other.updatedAt == updatedAt; + } + + Map toJson() { + return AuthorSerializer.toMap(this); + } +} diff --git a/angel_orm_generator/test/models/author.serializer.g.dart b/angel_orm_generator/test/models/author.serializer.g.dart new file mode 100644 index 00000000..0ffae031 --- /dev/null +++ b/angel_orm_generator/test/models/author.serializer.g.dart @@ -0,0 +1,54 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of angel_orm.generator.models.author; + +// ************************************************************************** +// SerializerGenerator +// ************************************************************************** + +abstract class AuthorSerializer { + static Author fromMap(Map map) { + return new Author( + id: map['id'] as String, + name: map['name'] as String, + createdAt: map['created_at'] != null + ? (map['created_at'] is DateTime + ? (map['created_at'] as DateTime) + : DateTime.parse(map['created_at'].toString())) + : null, + updatedAt: map['updated_at'] != null + ? (map['updated_at'] is DateTime + ? (map['updated_at'] as DateTime) + : DateTime.parse(map['updated_at'].toString())) + : null); + } + + static Map toMap(Author model) { + if (model == null) { + return null; + } + return { + 'id': model.id, + 'name': model.name, + 'created_at': model.createdAt?.toIso8601String(), + 'updated_at': model.updatedAt?.toIso8601String() + }; + } +} + +abstract class AuthorFields { + static const List allFields = const [ + id, + name, + createdAt, + updatedAt + ]; + + static const String id = 'id'; + + static const String name = 'name'; + + static const String createdAt = 'created_at'; + + static const String updatedAt = 'updated_at'; +} diff --git a/angel_orm_generator/test/models/book.g.dart b/angel_orm_generator/test/models/book.g.dart new file mode 100644 index 00000000..72fc7961 --- /dev/null +++ b/angel_orm_generator/test/models/book.g.dart @@ -0,0 +1,73 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of angel_orm.generator.models.book; + +// ************************************************************************** +// JsonModelGenerator +// ************************************************************************** + +@generatedSerializable +class Book extends _Book { + Book( + {this.id, + this.author, + this.partnerAuthor, + this.authorId, + this.name, + this.createdAt, + this.updatedAt}); + + @override + final String id; + + @override + final dynamic author; + + @override + final dynamic partnerAuthor; + + @override + final int authorId; + + @override + final String name; + + @override + final DateTime createdAt; + + @override + final DateTime updatedAt; + + Book copyWith( + {String id, + dynamic author, + dynamic partnerAuthor, + int authorId, + String name, + DateTime createdAt, + DateTime updatedAt}) { + return new Book( + id: id ?? this.id, + author: author ?? this.author, + partnerAuthor: partnerAuthor ?? this.partnerAuthor, + authorId: authorId ?? this.authorId, + name: name ?? this.name, + createdAt: createdAt ?? this.createdAt, + updatedAt: updatedAt ?? this.updatedAt); + } + + bool operator ==(other) { + return other is _Book && + other.id == id && + other.author == author && + other.partnerAuthor == partnerAuthor && + other.authorId == authorId && + other.name == name && + other.createdAt == createdAt && + other.updatedAt == updatedAt; + } + + Map toJson() { + return BookSerializer.toMap(this); + } +} diff --git a/angel_orm_generator/test/models/book.serializer.g.dart b/angel_orm_generator/test/models/book.serializer.g.dart new file mode 100644 index 00000000..1fd8e599 --- /dev/null +++ b/angel_orm_generator/test/models/book.serializer.g.dart @@ -0,0 +1,69 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of angel_orm.generator.models.book; + +// ************************************************************************** +// SerializerGenerator +// ************************************************************************** + +abstract class BookSerializer { + static Book fromMap(Map map) { + return new Book( + id: map['id'] as String, + author: map['author'] as dynamic, + partnerAuthor: map['partner_author'] as dynamic, + authorId: map['author_id'] as int, + name: map['name'] as String, + createdAt: map['created_at'] != null + ? (map['created_at'] is DateTime + ? (map['created_at'] as DateTime) + : DateTime.parse(map['created_at'].toString())) + : null, + updatedAt: map['updated_at'] != null + ? (map['updated_at'] is DateTime + ? (map['updated_at'] as DateTime) + : DateTime.parse(map['updated_at'].toString())) + : null); + } + + static Map toMap(Book model) { + if (model == null) { + return null; + } + return { + 'id': model.id, + 'author': model.author, + 'partner_author': model.partnerAuthor, + 'author_id': model.authorId, + 'name': model.name, + 'created_at': model.createdAt?.toIso8601String(), + 'updated_at': model.updatedAt?.toIso8601String() + }; + } +} + +abstract class BookFields { + static const List allFields = const [ + id, + author, + partnerAuthor, + authorId, + name, + createdAt, + updatedAt + ]; + + static const String id = 'id'; + + static const String author = 'author'; + + static const String partnerAuthor = 'partner_author'; + + static const String authorId = 'author_id'; + + static const String name = 'name'; + + static const String createdAt = 'created_at'; + + static const String updatedAt = 'updated_at'; +} diff --git a/angel_orm_generator/test/models/car.g.dart b/angel_orm_generator/test/models/car.g.dart new file mode 100644 index 00000000..c4f53c6b --- /dev/null +++ b/angel_orm_generator/test/models/car.g.dart @@ -0,0 +1,73 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of angel_orm.generator.models.car; + +// ************************************************************************** +// JsonModelGenerator +// ************************************************************************** + +@generatedSerializable +class Car extends _Car { + Car( + {this.id, + this.make, + this.description, + this.familyFriendly, + this.recalledAt, + this.createdAt, + this.updatedAt}); + + @override + final String id; + + @override + final String make; + + @override + final String description; + + @override + final bool familyFriendly; + + @override + final DateTime recalledAt; + + @override + final DateTime createdAt; + + @override + final DateTime updatedAt; + + Car copyWith( + {String id, + String make, + String description, + bool familyFriendly, + DateTime recalledAt, + DateTime createdAt, + DateTime updatedAt}) { + return new Car( + id: id ?? this.id, + make: make ?? this.make, + description: description ?? this.description, + familyFriendly: familyFriendly ?? this.familyFriendly, + recalledAt: recalledAt ?? this.recalledAt, + createdAt: createdAt ?? this.createdAt, + updatedAt: updatedAt ?? this.updatedAt); + } + + bool operator ==(other) { + return other is _Car && + other.id == id && + other.make == make && + other.description == description && + other.familyFriendly == familyFriendly && + other.recalledAt == recalledAt && + other.createdAt == createdAt && + other.updatedAt == updatedAt; + } + + Map toJson() { + return CarSerializer.toMap(this); + } +} diff --git a/angel_orm_generator/test/models/car.serializer.g.dart b/angel_orm_generator/test/models/car.serializer.g.dart new file mode 100644 index 00000000..6ed45642 --- /dev/null +++ b/angel_orm_generator/test/models/car.serializer.g.dart @@ -0,0 +1,73 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of angel_orm.generator.models.car; + +// ************************************************************************** +// SerializerGenerator +// ************************************************************************** + +abstract class CarSerializer { + static Car fromMap(Map map) { + return new Car( + id: map['id'] as String, + make: map['make'] as String, + description: map['description'] as String, + familyFriendly: map['family_friendly'] as bool, + recalledAt: map['recalled_at'] != null + ? (map['recalled_at'] is DateTime + ? (map['recalled_at'] as DateTime) + : DateTime.parse(map['recalled_at'].toString())) + : null, + createdAt: map['created_at'] != null + ? (map['created_at'] is DateTime + ? (map['created_at'] as DateTime) + : DateTime.parse(map['created_at'].toString())) + : null, + updatedAt: map['updated_at'] != null + ? (map['updated_at'] is DateTime + ? (map['updated_at'] as DateTime) + : DateTime.parse(map['updated_at'].toString())) + : null); + } + + static Map toMap(Car model) { + if (model == null) { + return null; + } + return { + 'id': model.id, + 'make': model.make, + 'description': model.description, + 'family_friendly': model.familyFriendly, + 'recalled_at': model.recalledAt?.toIso8601String(), + 'created_at': model.createdAt?.toIso8601String(), + 'updated_at': model.updatedAt?.toIso8601String() + }; + } +} + +abstract class CarFields { + static const List allFields = const [ + id, + make, + description, + familyFriendly, + recalledAt, + createdAt, + updatedAt + ]; + + static const String id = 'id'; + + static const String make = 'make'; + + static const String description = 'description'; + + static const String familyFriendly = 'family_friendly'; + + static const String recalledAt = 'recalled_at'; + + static const String createdAt = 'created_at'; + + static const String updatedAt = 'updated_at'; +} diff --git a/angel_orm_generator/test/models/customer.g.dart b/angel_orm_generator/test/models/customer.g.dart new file mode 100644 index 00000000..b9938637 --- /dev/null +++ b/angel_orm_generator/test/models/customer.g.dart @@ -0,0 +1,39 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of angel_orm_generator.test.models.customer; + +// ************************************************************************** +// JsonModelGenerator +// ************************************************************************** + +@generatedSerializable +class Customer extends _Customer { + Customer({this.id, this.createdAt, this.updatedAt}); + + @override + final String id; + + @override + final DateTime createdAt; + + @override + final DateTime updatedAt; + + Customer copyWith({String id, DateTime createdAt, DateTime updatedAt}) { + return new Customer( + id: id ?? this.id, + createdAt: createdAt ?? this.createdAt, + updatedAt: updatedAt ?? this.updatedAt); + } + + bool operator ==(other) { + return other is _Customer && + other.id == id && + other.createdAt == createdAt && + other.updatedAt == updatedAt; + } + + Map toJson() { + return CustomerSerializer.toMap(this); + } +} diff --git a/angel_orm_generator/test/models/customer.serializer.g.dart b/angel_orm_generator/test/models/customer.serializer.g.dart new file mode 100644 index 00000000..7a7a9fab --- /dev/null +++ b/angel_orm_generator/test/models/customer.serializer.g.dart @@ -0,0 +1,49 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of angel_orm_generator.test.models.customer; + +// ************************************************************************** +// SerializerGenerator +// ************************************************************************** + +abstract class CustomerSerializer { + static Customer fromMap(Map map) { + return new Customer( + id: map['id'] as String, + createdAt: map['created_at'] != null + ? (map['created_at'] is DateTime + ? (map['created_at'] as DateTime) + : DateTime.parse(map['created_at'].toString())) + : null, + updatedAt: map['updated_at'] != null + ? (map['updated_at'] is DateTime + ? (map['updated_at'] as DateTime) + : DateTime.parse(map['updated_at'].toString())) + : null); + } + + static Map toMap(Customer model) { + if (model == null) { + return null; + } + return { + 'id': model.id, + 'created_at': model.createdAt?.toIso8601String(), + 'updated_at': model.updatedAt?.toIso8601String() + }; + } +} + +abstract class CustomerFields { + static const List allFields = const [ + id, + createdAt, + updatedAt + ]; + + static const String id = 'id'; + + static const String createdAt = 'created_at'; + + static const String updatedAt = 'updated_at'; +} diff --git a/angel_orm_generator/test/models/foot.g.dart b/angel_orm_generator/test/models/foot.g.dart new file mode 100644 index 00000000..6147fc76 --- /dev/null +++ b/angel_orm_generator/test/models/foot.g.dart @@ -0,0 +1,54 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of angel_orm_generator.test.models.foot; + +// ************************************************************************** +// JsonModelGenerator +// ************************************************************************** + +@generatedSerializable +class Foot extends _Foot { + Foot({this.id, this.legId, this.nToes, this.createdAt, this.updatedAt}); + + @override + final String id; + + @override + final int legId; + + @override + final int nToes; + + @override + final DateTime createdAt; + + @override + final DateTime updatedAt; + + Foot copyWith( + {String id, + int legId, + int nToes, + DateTime createdAt, + DateTime updatedAt}) { + return new Foot( + id: id ?? this.id, + legId: legId ?? this.legId, + nToes: nToes ?? this.nToes, + createdAt: createdAt ?? this.createdAt, + updatedAt: updatedAt ?? this.updatedAt); + } + + bool operator ==(other) { + return other is _Foot && + other.id == id && + other.legId == legId && + other.nToes == nToes && + other.createdAt == createdAt && + other.updatedAt == updatedAt; + } + + Map toJson() { + return FootSerializer.toMap(this); + } +} diff --git a/angel_orm_generator/test/models/foot.serializer.g.dart b/angel_orm_generator/test/models/foot.serializer.g.dart new file mode 100644 index 00000000..6e273e62 --- /dev/null +++ b/angel_orm_generator/test/models/foot.serializer.g.dart @@ -0,0 +1,59 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of angel_orm_generator.test.models.foot; + +// ************************************************************************** +// SerializerGenerator +// ************************************************************************** + +abstract class FootSerializer { + static Foot fromMap(Map map) { + return new Foot( + id: map['id'] as String, + legId: map['leg_id'] as int, + nToes: map['n_toes'] as int, + createdAt: map['created_at'] != null + ? (map['created_at'] is DateTime + ? (map['created_at'] as DateTime) + : DateTime.parse(map['created_at'].toString())) + : null, + updatedAt: map['updated_at'] != null + ? (map['updated_at'] is DateTime + ? (map['updated_at'] as DateTime) + : DateTime.parse(map['updated_at'].toString())) + : null); + } + + static Map toMap(Foot model) { + if (model == null) { + return null; + } + return { + 'id': model.id, + 'leg_id': model.legId, + 'n_toes': model.nToes, + 'created_at': model.createdAt?.toIso8601String(), + 'updated_at': model.updatedAt?.toIso8601String() + }; + } +} + +abstract class FootFields { + static const List allFields = const [ + id, + legId, + nToes, + createdAt, + updatedAt + ]; + + static const String id = 'id'; + + static const String legId = 'leg_id'; + + static const String nToes = 'n_toes'; + + static const String createdAt = 'created_at'; + + static const String updatedAt = 'updated_at'; +} diff --git a/angel_orm_generator/test/models/fruit.g.dart b/angel_orm_generator/test/models/fruit.g.dart new file mode 100644 index 00000000..71521cf5 --- /dev/null +++ b/angel_orm_generator/test/models/fruit.g.dart @@ -0,0 +1,55 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of angel_orm_generator.test.models.fruit; + +// ************************************************************************** +// JsonModelGenerator +// ************************************************************************** + +@generatedSerializable +class Fruit extends _Fruit { + Fruit( + {this.id, this.treeId, this.commonName, this.createdAt, this.updatedAt}); + + @override + final String id; + + @override + final int treeId; + + @override + final String commonName; + + @override + final DateTime createdAt; + + @override + final DateTime updatedAt; + + Fruit copyWith( + {String id, + int treeId, + String commonName, + DateTime createdAt, + DateTime updatedAt}) { + return new Fruit( + id: id ?? this.id, + treeId: treeId ?? this.treeId, + commonName: commonName ?? this.commonName, + createdAt: createdAt ?? this.createdAt, + updatedAt: updatedAt ?? this.updatedAt); + } + + bool operator ==(other) { + return other is _Fruit && + other.id == id && + other.treeId == treeId && + other.commonName == commonName && + other.createdAt == createdAt && + other.updatedAt == updatedAt; + } + + Map toJson() { + return FruitSerializer.toMap(this); + } +} diff --git a/angel_orm_generator/test/models/fruit.serializer.g.dart b/angel_orm_generator/test/models/fruit.serializer.g.dart new file mode 100644 index 00000000..264d6635 --- /dev/null +++ b/angel_orm_generator/test/models/fruit.serializer.g.dart @@ -0,0 +1,59 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of angel_orm_generator.test.models.fruit; + +// ************************************************************************** +// SerializerGenerator +// ************************************************************************** + +abstract class FruitSerializer { + static Fruit fromMap(Map map) { + return new Fruit( + id: map['id'] as String, + treeId: map['tree_id'] as int, + commonName: map['common_name'] as String, + createdAt: map['created_at'] != null + ? (map['created_at'] is DateTime + ? (map['created_at'] as DateTime) + : DateTime.parse(map['created_at'].toString())) + : null, + updatedAt: map['updated_at'] != null + ? (map['updated_at'] is DateTime + ? (map['updated_at'] as DateTime) + : DateTime.parse(map['updated_at'].toString())) + : null); + } + + static Map toMap(Fruit model) { + if (model == null) { + return null; + } + return { + 'id': model.id, + 'tree_id': model.treeId, + 'common_name': model.commonName, + 'created_at': model.createdAt?.toIso8601String(), + 'updated_at': model.updatedAt?.toIso8601String() + }; + } +} + +abstract class FruitFields { + static const List allFields = const [ + id, + treeId, + commonName, + createdAt, + updatedAt + ]; + + static const String id = 'id'; + + static const String treeId = 'tree_id'; + + static const String commonName = 'common_name'; + + static const String createdAt = 'created_at'; + + static const String updatedAt = 'updated_at'; +} diff --git a/angel_orm_generator/test/models/leg.g.dart b/angel_orm_generator/test/models/leg.g.dart new file mode 100644 index 00000000..386a68b7 --- /dev/null +++ b/angel_orm_generator/test/models/leg.g.dart @@ -0,0 +1,54 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of angel_orm_generator.test.models.leg; + +// ************************************************************************** +// JsonModelGenerator +// ************************************************************************** + +@generatedSerializable +class Leg extends _Leg { + Leg({this.id, this.foot, this.name, this.createdAt, this.updatedAt}); + + @override + final String id; + + @override + final dynamic foot; + + @override + final String name; + + @override + final DateTime createdAt; + + @override + final DateTime updatedAt; + + Leg copyWith( + {String id, + dynamic foot, + String name, + DateTime createdAt, + DateTime updatedAt}) { + return new Leg( + id: id ?? this.id, + foot: foot ?? this.foot, + name: name ?? this.name, + createdAt: createdAt ?? this.createdAt, + updatedAt: updatedAt ?? this.updatedAt); + } + + bool operator ==(other) { + return other is _Leg && + other.id == id && + other.foot == foot && + other.name == name && + other.createdAt == createdAt && + other.updatedAt == updatedAt; + } + + Map toJson() { + return LegSerializer.toMap(this); + } +} diff --git a/angel_orm_generator/test/models/leg.serializer.g.dart b/angel_orm_generator/test/models/leg.serializer.g.dart new file mode 100644 index 00000000..8f2c0732 --- /dev/null +++ b/angel_orm_generator/test/models/leg.serializer.g.dart @@ -0,0 +1,59 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of angel_orm_generator.test.models.leg; + +// ************************************************************************** +// SerializerGenerator +// ************************************************************************** + +abstract class LegSerializer { + static Leg fromMap(Map map) { + return new Leg( + id: map['id'] as String, + foot: map['foot'] as dynamic, + name: map['name'] as String, + createdAt: map['created_at'] != null + ? (map['created_at'] is DateTime + ? (map['created_at'] as DateTime) + : DateTime.parse(map['created_at'].toString())) + : null, + updatedAt: map['updated_at'] != null + ? (map['updated_at'] is DateTime + ? (map['updated_at'] as DateTime) + : DateTime.parse(map['updated_at'].toString())) + : null); + } + + static Map toMap(Leg model) { + if (model == null) { + return null; + } + return { + 'id': model.id, + 'foot': model.foot, + 'name': model.name, + 'created_at': model.createdAt?.toIso8601String(), + 'updated_at': model.updatedAt?.toIso8601String() + }; + } +} + +abstract class LegFields { + static const List allFields = const [ + id, + foot, + name, + createdAt, + updatedAt + ]; + + static const String id = 'id'; + + static const String foot = 'foot'; + + static const String name = 'name'; + + static const String createdAt = 'created_at'; + + static const String updatedAt = 'updated_at'; +} diff --git a/angel_orm_generator/test/models/order.g.dart b/angel_orm_generator/test/models/order.g.dart new file mode 100644 index 00000000..76b0adba --- /dev/null +++ b/angel_orm_generator/test/models/order.g.dart @@ -0,0 +1,73 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of angel_orm_generator.test.models.order; + +// ************************************************************************** +// JsonModelGenerator +// ************************************************************************** + +@generatedSerializable +class Order extends _Order { + Order( + {this.id, + this.customerId, + this.employeeId, + this.orderDate, + this.shipperId, + this.createdAt, + this.updatedAt}); + + @override + final String id; + + @override + final int customerId; + + @override + final int employeeId; + + @override + final DateTime orderDate; + + @override + final int shipperId; + + @override + final DateTime createdAt; + + @override + final DateTime updatedAt; + + Order copyWith( + {String id, + int customerId, + int employeeId, + DateTime orderDate, + int shipperId, + DateTime createdAt, + DateTime updatedAt}) { + return new Order( + id: id ?? this.id, + customerId: customerId ?? this.customerId, + employeeId: employeeId ?? this.employeeId, + orderDate: orderDate ?? this.orderDate, + shipperId: shipperId ?? this.shipperId, + createdAt: createdAt ?? this.createdAt, + updatedAt: updatedAt ?? this.updatedAt); + } + + bool operator ==(other) { + return other is _Order && + other.id == id && + other.customerId == customerId && + other.employeeId == employeeId && + other.orderDate == orderDate && + other.shipperId == shipperId && + other.createdAt == createdAt && + other.updatedAt == updatedAt; + } + + Map toJson() { + return OrderSerializer.toMap(this); + } +} diff --git a/angel_orm_generator/test/models/order.serializer.g.dart b/angel_orm_generator/test/models/order.serializer.g.dart new file mode 100644 index 00000000..03e4a5b8 --- /dev/null +++ b/angel_orm_generator/test/models/order.serializer.g.dart @@ -0,0 +1,73 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of angel_orm_generator.test.models.order; + +// ************************************************************************** +// SerializerGenerator +// ************************************************************************** + +abstract class OrderSerializer { + static Order fromMap(Map map) { + return new Order( + id: map['id'] as String, + customerId: map['customer_id'] as int, + employeeId: map['employee_id'] as int, + orderDate: map['order_date'] != null + ? (map['order_date'] is DateTime + ? (map['order_date'] as DateTime) + : DateTime.parse(map['order_date'].toString())) + : null, + shipperId: map['shipper_id'] as int, + createdAt: map['created_at'] != null + ? (map['created_at'] is DateTime + ? (map['created_at'] as DateTime) + : DateTime.parse(map['created_at'].toString())) + : null, + updatedAt: map['updated_at'] != null + ? (map['updated_at'] is DateTime + ? (map['updated_at'] as DateTime) + : DateTime.parse(map['updated_at'].toString())) + : null); + } + + static Map toMap(Order model) { + if (model == null) { + return null; + } + return { + 'id': model.id, + 'customer_id': model.customerId, + 'employee_id': model.employeeId, + 'order_date': model.orderDate?.toIso8601String(), + 'shipper_id': model.shipperId, + 'created_at': model.createdAt?.toIso8601String(), + 'updated_at': model.updatedAt?.toIso8601String() + }; + } +} + +abstract class OrderFields { + static const List allFields = const [ + id, + customerId, + employeeId, + orderDate, + shipperId, + createdAt, + updatedAt + ]; + + static const String id = 'id'; + + static const String customerId = 'customer_id'; + + static const String employeeId = 'employee_id'; + + static const String orderDate = 'order_date'; + + static const String shipperId = 'shipper_id'; + + static const String createdAt = 'created_at'; + + static const String updatedAt = 'updated_at'; +} diff --git a/angel_orm_generator/test/models/role.g.dart b/angel_orm_generator/test/models/role.g.dart new file mode 100644 index 00000000..f2ef978e --- /dev/null +++ b/angel_orm_generator/test/models/role.g.dart @@ -0,0 +1,45 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of angel_orm_generator.test.models.role; + +// ************************************************************************** +// JsonModelGenerator +// ************************************************************************** + +@generatedSerializable +class Role extends _Role { + Role({this.id, this.name, this.createdAt, this.updatedAt}); + + @override + final String id; + + @override + final String name; + + @override + final DateTime createdAt; + + @override + final DateTime updatedAt; + + Role copyWith( + {String id, String name, DateTime createdAt, DateTime updatedAt}) { + return new Role( + id: id ?? this.id, + name: name ?? this.name, + createdAt: createdAt ?? this.createdAt, + updatedAt: updatedAt ?? this.updatedAt); + } + + bool operator ==(other) { + return other is _Role && + other.id == id && + other.name == name && + other.createdAt == createdAt && + other.updatedAt == updatedAt; + } + + Map toJson() { + return RoleSerializer.toMap(this); + } +} diff --git a/angel_orm_generator/test/models/role.serializer.g.dart b/angel_orm_generator/test/models/role.serializer.g.dart new file mode 100644 index 00000000..60aeda1a --- /dev/null +++ b/angel_orm_generator/test/models/role.serializer.g.dart @@ -0,0 +1,54 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of angel_orm_generator.test.models.role; + +// ************************************************************************** +// SerializerGenerator +// ************************************************************************** + +abstract class RoleSerializer { + static Role fromMap(Map map) { + return new Role( + id: map['id'] as String, + name: map['name'] as String, + createdAt: map['created_at'] != null + ? (map['created_at'] is DateTime + ? (map['created_at'] as DateTime) + : DateTime.parse(map['created_at'].toString())) + : null, + updatedAt: map['updated_at'] != null + ? (map['updated_at'] is DateTime + ? (map['updated_at'] as DateTime) + : DateTime.parse(map['updated_at'].toString())) + : null); + } + + static Map toMap(Role model) { + if (model == null) { + return null; + } + return { + 'id': model.id, + 'name': model.name, + 'created_at': model.createdAt?.toIso8601String(), + 'updated_at': model.updatedAt?.toIso8601String() + }; + } +} + +abstract class RoleFields { + static const List allFields = const [ + id, + name, + createdAt, + updatedAt + ]; + + static const String id = 'id'; + + static const String name = 'name'; + + static const String createdAt = 'created_at'; + + static const String updatedAt = 'updated_at'; +} diff --git a/angel_orm_generator/test/models/tree.g.dart b/angel_orm_generator/test/models/tree.g.dart new file mode 100644 index 00000000..2e3b5542 --- /dev/null +++ b/angel_orm_generator/test/models/tree.g.dart @@ -0,0 +1,61 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of angel_orm_generator.test.models.tree; + +// ************************************************************************** +// JsonModelGenerator +// ************************************************************************** + +@generatedSerializable +class Tree extends _Tree { + Tree( + {this.id, + this.rings, + List fruits, + this.createdAt, + this.updatedAt}) + : this.fruits = new List.unmodifiable(fruits ?? []); + + @override + final String id; + + @override + final int rings; + + @override + final List fruits; + + @override + final DateTime createdAt; + + @override + final DateTime updatedAt; + + Tree copyWith( + {String id, + int rings, + List fruits, + DateTime createdAt, + DateTime updatedAt}) { + return new Tree( + id: id ?? this.id, + rings: rings ?? this.rings, + fruits: fruits ?? this.fruits, + createdAt: createdAt ?? this.createdAt, + updatedAt: updatedAt ?? this.updatedAt); + } + + bool operator ==(other) { + return other is _Tree && + other.id == id && + other.rings == rings && + const ListEquality(const DefaultEquality()) + .equals(other.fruits, fruits) && + other.createdAt == createdAt && + other.updatedAt == updatedAt; + } + + Map toJson() { + return TreeSerializer.toMap(this); + } +} diff --git a/angel_orm_generator/test/models/tree.serializer.g.dart b/angel_orm_generator/test/models/tree.serializer.g.dart new file mode 100644 index 00000000..bca42347 --- /dev/null +++ b/angel_orm_generator/test/models/tree.serializer.g.dart @@ -0,0 +1,59 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of angel_orm_generator.test.models.tree; + +// ************************************************************************** +// SerializerGenerator +// ************************************************************************** + +abstract class TreeSerializer { + static Tree fromMap(Map map) { + return new Tree( + id: map['id'] as String, + rings: map['rings'] as int, + fruits: map['fruits'] as List, + createdAt: map['created_at'] != null + ? (map['created_at'] is DateTime + ? (map['created_at'] as DateTime) + : DateTime.parse(map['created_at'].toString())) + : null, + updatedAt: map['updated_at'] != null + ? (map['updated_at'] is DateTime + ? (map['updated_at'] as DateTime) + : DateTime.parse(map['updated_at'].toString())) + : null); + } + + static Map toMap(Tree model) { + if (model == null) { + return null; + } + return { + 'id': model.id, + 'rings': model.rings, + 'fruits': model.fruits, + 'created_at': model.createdAt?.toIso8601String(), + 'updated_at': model.updatedAt?.toIso8601String() + }; + } +} + +abstract class TreeFields { + static const List allFields = const [ + id, + rings, + fruits, + createdAt, + updatedAt + ]; + + static const String id = 'id'; + + static const String rings = 'rings'; + + static const String fruits = 'fruits'; + + static const String createdAt = 'created_at'; + + static const String updatedAt = 'updated_at'; +} diff --git a/angel_orm_generator/test/models/user.g.dart b/angel_orm_generator/test/models/user.g.dart new file mode 100644 index 00000000..82b96a87 --- /dev/null +++ b/angel_orm_generator/test/models/user.g.dart @@ -0,0 +1,75 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of angel_orm_generator.test.models.user; + +// ************************************************************************** +// JsonModelGenerator +// ************************************************************************** + +@generatedSerializable +class User extends _User { + User( + {this.id, + this.username, + this.password, + this.email, + List roles, + this.createdAt, + this.updatedAt}) + : this.roles = new List.unmodifiable(roles ?? []); + + @override + final String id; + + @override + final String username; + + @override + final String password; + + @override + final String email; + + @override + final List roles; + + @override + final DateTime createdAt; + + @override + final DateTime updatedAt; + + User copyWith( + {String id, + String username, + String password, + String email, + List roles, + DateTime createdAt, + DateTime updatedAt}) { + return new User( + id: id ?? this.id, + username: username ?? this.username, + password: password ?? this.password, + email: email ?? this.email, + roles: roles ?? this.roles, + createdAt: createdAt ?? this.createdAt, + updatedAt: updatedAt ?? this.updatedAt); + } + + bool operator ==(other) { + return other is _User && + other.id == id && + other.username == username && + other.password == password && + other.email == email && + const ListEquality(const DefaultEquality()) + .equals(other.roles, roles) && + other.createdAt == createdAt && + other.updatedAt == updatedAt; + } + + Map toJson() { + return UserSerializer.toMap(this); + } +} diff --git a/angel_orm_generator/test/models/user.serializer.g.dart b/angel_orm_generator/test/models/user.serializer.g.dart new file mode 100644 index 00000000..f5bfa44d --- /dev/null +++ b/angel_orm_generator/test/models/user.serializer.g.dart @@ -0,0 +1,69 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of angel_orm_generator.test.models.user; + +// ************************************************************************** +// SerializerGenerator +// ************************************************************************** + +abstract class UserSerializer { + static User fromMap(Map map) { + return new User( + id: map['id'] as String, + username: map['username'] as String, + password: map['password'] as String, + email: map['email'] as String, + roles: map['roles'] as List, + createdAt: map['created_at'] != null + ? (map['created_at'] is DateTime + ? (map['created_at'] as DateTime) + : DateTime.parse(map['created_at'].toString())) + : null, + updatedAt: map['updated_at'] != null + ? (map['updated_at'] is DateTime + ? (map['updated_at'] as DateTime) + : DateTime.parse(map['updated_at'].toString())) + : null); + } + + static Map toMap(User model) { + if (model == null) { + return null; + } + return { + 'id': model.id, + 'username': model.username, + 'password': model.password, + 'email': model.email, + 'roles': model.roles, + 'created_at': model.createdAt?.toIso8601String(), + 'updated_at': model.updatedAt?.toIso8601String() + }; + } +} + +abstract class UserFields { + static const List allFields = const [ + id, + username, + password, + email, + roles, + createdAt, + updatedAt + ]; + + static const String id = 'id'; + + static const String username = 'username'; + + static const String password = 'password'; + + static const String email = 'email'; + + static const String roles = 'roles'; + + static const String createdAt = 'created_at'; + + static const String updatedAt = 'updated_at'; +}