Read tableName for OrmBuildContext

This commit is contained in:
Tobe O 2018-08-24 09:42:09 -04:00
parent 3f55473164
commit 2ba124c12e
23 changed files with 1334 additions and 2 deletions

View file

@ -6,6 +6,8 @@ import 'package:angel_orm/angel_orm.dart';
import 'package:angel_serialize_generator/build_context.dart'; import 'package:angel_serialize_generator/build_context.dart';
import 'package:angel_serialize_generator/context.dart'; import 'package:angel_serialize_generator/context.dart';
import 'package:build/build.dart'; import 'package:build/build.dart';
import 'package:inflection/inflection.dart';
import 'package:recase/recase.dart';
import 'package:source_gen/source_gen.dart'; import 'package:source_gen/source_gen.dart';
import 'readers.dart'; import 'readers.dart';
@ -21,7 +23,12 @@ Future<OrmBuildContext> buildOrmContext(
var buildCtx = await buildContext(clazz, annotation, buildStep, resolver, var buildCtx = await buildContext(clazz, annotation, buildStep, resolver,
autoSnakeCaseNames, autoIdAndDateFields); autoSnakeCaseNames, autoIdAndDateFields);
var ormAnnotation = reviveORMAnnotation(annotation); 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 // Read all fields
for (var field in buildCtx.fields) { for (var field in buildCtx.fields) {
@ -107,10 +114,11 @@ Column reviveColumn(ConstantReader cr) {
class OrmBuildContext { class OrmBuildContext {
final BuildContext buildContext; final BuildContext buildContext;
final ORM ormAnnotation; final ORM ormAnnotation;
final String tableName;
final Map<String, Column> columns = {}; final Map<String, Column> columns = {};
OrmBuildContext(this.buildContext, this.ormAnnotation); OrmBuildContext(this.buildContext, this.ormAnnotation, this.tableName);
} }
class _ColumnType implements ColumnType { class _ColumnType implements ColumnType {

View file

@ -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<String, dynamic> toJson() {
return AuthorSerializer.toMap(this);
}
}

View file

@ -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<String, dynamic> 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<String> allFields = const <String>[
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';
}

View file

@ -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<String, dynamic> toJson() {
return BookSerializer.toMap(this);
}
}

View file

@ -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<String, dynamic> 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<String> allFields = const <String>[
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';
}

View file

@ -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<String, dynamic> toJson() {
return CarSerializer.toMap(this);
}
}

View file

@ -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<String, dynamic> 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<String> allFields = const <String>[
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';
}

View file

@ -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<String, dynamic> toJson() {
return CustomerSerializer.toMap(this);
}
}

View file

@ -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<String, dynamic> 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<String> allFields = const <String>[
id,
createdAt,
updatedAt
];
static const String id = 'id';
static const String createdAt = 'created_at';
static const String updatedAt = 'updated_at';
}

View file

@ -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<String, dynamic> toJson() {
return FootSerializer.toMap(this);
}
}

View file

@ -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<String, dynamic> 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<String> allFields = const <String>[
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';
}

View file

@ -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<String, dynamic> toJson() {
return FruitSerializer.toMap(this);
}
}

View file

@ -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<String, dynamic> 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<String> allFields = const <String>[
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';
}

View file

@ -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<String, dynamic> toJson() {
return LegSerializer.toMap(this);
}
}

View file

@ -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<String, dynamic> 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<String> allFields = const <String>[
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';
}

View file

@ -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<String, dynamic> toJson() {
return OrderSerializer.toMap(this);
}
}

View file

@ -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<String, dynamic> 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<String> allFields = const <String>[
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';
}

View file

@ -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<String, dynamic> toJson() {
return RoleSerializer.toMap(this);
}
}

View file

@ -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<String, dynamic> 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<String> allFields = const <String>[
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';
}

View file

@ -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<dynamic> fruits,
this.createdAt,
this.updatedAt})
: this.fruits = new List.unmodifiable(fruits ?? []);
@override
final String id;
@override
final int rings;
@override
final List<dynamic> fruits;
@override
final DateTime createdAt;
@override
final DateTime updatedAt;
Tree copyWith(
{String id,
int rings,
List<dynamic> 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<dynamic>(const DefaultEquality())
.equals(other.fruits, fruits) &&
other.createdAt == createdAt &&
other.updatedAt == updatedAt;
}
Map<String, dynamic> toJson() {
return TreeSerializer.toMap(this);
}
}

View file

@ -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<dynamic>,
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<String, dynamic> 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<String> allFields = const <String>[
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';
}

View file

@ -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<dynamic> 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<dynamic> roles;
@override
final DateTime createdAt;
@override
final DateTime updatedAt;
User copyWith(
{String id,
String username,
String password,
String email,
List<dynamic> 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<dynamic>(const DefaultEquality())
.equals(other.roles, roles) &&
other.createdAt == createdAt &&
other.updatedAt == updatedAt;
}
Map<String, dynamic> toJson() {
return UserSerializer.toMap(this);
}
}

View file

@ -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<dynamic>,
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<String, dynamic> 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<String> allFields = const <String>[
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';
}