Pass parent in constructor
This commit is contained in:
parent
ee30c3c9f8
commit
44abb49dd8
11 changed files with 6533 additions and 0 deletions
|
@ -268,6 +268,7 @@ class OrmGenerator extends GeneratorForAnnotation<Orm> {
|
|||
..type = TypeReference((b) => b
|
||||
..symbol = 'Set'
|
||||
..types.add(refer('String')))))
|
||||
..initializers.add(Code('super(parent: parent)'))
|
||||
..body = Block((b) {
|
||||
b.statements.addAll([
|
||||
Code('trampoline ??= Set();'),
|
||||
|
|
606
angel_orm_test/lib/src/models/book.g.dart
Normal file
606
angel_orm_test/lib/src/models/book.g.dart
Normal file
|
@ -0,0 +1,606 @@
|
|||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of angel_orm.generator.models.book;
|
||||
|
||||
// **************************************************************************
|
||||
// MigrationGenerator
|
||||
// **************************************************************************
|
||||
|
||||
class BookMigration extends Migration {
|
||||
@override
|
||||
up(Schema schema) {
|
||||
schema.create('books', (table) {
|
||||
table.serial('id')..primaryKey();
|
||||
table.timeStamp('created_at');
|
||||
table.timeStamp('updated_at');
|
||||
table.varChar('name');
|
||||
table
|
||||
.declare('author_id', ColumnType('serial'))
|
||||
.references('authors', 'id');
|
||||
table
|
||||
.declare('partner_author_id', ColumnType('serial'))
|
||||
.references('authors', 'id');
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
down(Schema schema) {
|
||||
schema.drop('books');
|
||||
}
|
||||
}
|
||||
|
||||
class AuthorMigration extends Migration {
|
||||
@override
|
||||
up(Schema schema) {
|
||||
schema.create('authors', (table) {
|
||||
table.serial('id')..primaryKey();
|
||||
table.timeStamp('created_at');
|
||||
table.timeStamp('updated_at');
|
||||
table.varChar('name', length: 255)..defaultsTo('Tobe Osakwe');
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
down(Schema schema) {
|
||||
schema.drop('authors');
|
||||
}
|
||||
}
|
||||
|
||||
// **************************************************************************
|
||||
// OrmGenerator
|
||||
// **************************************************************************
|
||||
|
||||
class BookQuery extends Query<Book, BookQueryWhere> {
|
||||
BookQuery({Query parent, Set<String> trampoline}) : super(parent: parent) {
|
||||
trampoline ??= Set();
|
||||
trampoline.add(tableName);
|
||||
_where = BookQueryWhere(this);
|
||||
leftJoin(_author = AuthorQuery(trampoline: trampoline, parent: this),
|
||||
'author_id', 'id',
|
||||
additionalFields: const ['id', 'created_at', 'updated_at', 'name'],
|
||||
trampoline: trampoline);
|
||||
leftJoin(_partnerAuthor = AuthorQuery(trampoline: trampoline, parent: this),
|
||||
'partner_author_id', 'id',
|
||||
additionalFields: const ['id', 'created_at', 'updated_at', 'name'],
|
||||
trampoline: trampoline);
|
||||
}
|
||||
|
||||
@override
|
||||
final BookQueryValues values = BookQueryValues();
|
||||
|
||||
BookQueryWhere _where;
|
||||
|
||||
AuthorQuery _author;
|
||||
|
||||
AuthorQuery _partnerAuthor;
|
||||
|
||||
@override
|
||||
get casts {
|
||||
return {};
|
||||
}
|
||||
|
||||
@override
|
||||
get tableName {
|
||||
return 'books';
|
||||
}
|
||||
|
||||
@override
|
||||
get fields {
|
||||
return const [
|
||||
'id',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'author_id',
|
||||
'partner_author_id',
|
||||
'name'
|
||||
];
|
||||
}
|
||||
|
||||
@override
|
||||
BookQueryWhere get where {
|
||||
return _where;
|
||||
}
|
||||
|
||||
@override
|
||||
BookQueryWhere newWhereClause() {
|
||||
return BookQueryWhere(this);
|
||||
}
|
||||
|
||||
static Book parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
var model = Book(
|
||||
id: row[0].toString(),
|
||||
createdAt: (row[1] as DateTime),
|
||||
updatedAt: (row[2] as DateTime),
|
||||
name: (row[5] as String));
|
||||
if (row.length > 6) {
|
||||
model = model.copyWith(
|
||||
author: AuthorQuery.parseRow(row.skip(6).take(4).toList()));
|
||||
}
|
||||
if (row.length > 10) {
|
||||
model = model.copyWith(
|
||||
partnerAuthor: AuthorQuery.parseRow(row.skip(10).take(4).toList()));
|
||||
}
|
||||
return model;
|
||||
}
|
||||
|
||||
@override
|
||||
deserialize(List row) {
|
||||
return parseRow(row);
|
||||
}
|
||||
|
||||
AuthorQuery get author {
|
||||
return _author;
|
||||
}
|
||||
|
||||
AuthorQuery get partnerAuthor {
|
||||
return _partnerAuthor;
|
||||
}
|
||||
}
|
||||
|
||||
class BookQueryWhere extends QueryWhere {
|
||||
BookQueryWhere(BookQuery query)
|
||||
: id = NumericSqlExpressionBuilder<int>(query, 'id'),
|
||||
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
|
||||
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'),
|
||||
authorId = NumericSqlExpressionBuilder<int>(query, 'author_id'),
|
||||
partnerAuthorId =
|
||||
NumericSqlExpressionBuilder<int>(query, 'partner_author_id'),
|
||||
name = StringSqlExpressionBuilder(query, 'name');
|
||||
|
||||
final NumericSqlExpressionBuilder<int> id;
|
||||
|
||||
final DateTimeSqlExpressionBuilder createdAt;
|
||||
|
||||
final DateTimeSqlExpressionBuilder updatedAt;
|
||||
|
||||
final NumericSqlExpressionBuilder<int> authorId;
|
||||
|
||||
final NumericSqlExpressionBuilder<int> partnerAuthorId;
|
||||
|
||||
final StringSqlExpressionBuilder name;
|
||||
|
||||
@override
|
||||
get expressionBuilders {
|
||||
return [id, createdAt, updatedAt, authorId, partnerAuthorId, name];
|
||||
}
|
||||
}
|
||||
|
||||
class BookQueryValues extends MapQueryValues {
|
||||
@override
|
||||
get casts {
|
||||
return {};
|
||||
}
|
||||
|
||||
String get id {
|
||||
return (values['id'] as String);
|
||||
}
|
||||
|
||||
set id(String value) => values['id'] = value;
|
||||
DateTime get createdAt {
|
||||
return (values['created_at'] as DateTime);
|
||||
}
|
||||
|
||||
set createdAt(DateTime value) => values['created_at'] = value;
|
||||
DateTime get updatedAt {
|
||||
return (values['updated_at'] as DateTime);
|
||||
}
|
||||
|
||||
set updatedAt(DateTime value) => values['updated_at'] = value;
|
||||
int get authorId {
|
||||
return (values['author_id'] as int);
|
||||
}
|
||||
|
||||
set authorId(int value) => values['author_id'] = value;
|
||||
int get partnerAuthorId {
|
||||
return (values['partner_author_id'] as int);
|
||||
}
|
||||
|
||||
set partnerAuthorId(int value) => values['partner_author_id'] = value;
|
||||
String get name {
|
||||
return (values['name'] as String);
|
||||
}
|
||||
|
||||
set name(String value) => values['name'] = value;
|
||||
void copyFrom(Book model) {
|
||||
createdAt = model.createdAt;
|
||||
updatedAt = model.updatedAt;
|
||||
name = model.name;
|
||||
if (model.author != null) {
|
||||
values['author_id'] = model.author.id;
|
||||
}
|
||||
if (model.partnerAuthor != null) {
|
||||
values['partner_author_id'] = model.partnerAuthor.id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AuthorQuery extends Query<Author, AuthorQueryWhere> {
|
||||
AuthorQuery({Query parent, Set<String> trampoline}) : super(parent: parent) {
|
||||
trampoline ??= Set();
|
||||
trampoline.add(tableName);
|
||||
_where = AuthorQueryWhere(this);
|
||||
}
|
||||
|
||||
@override
|
||||
final AuthorQueryValues values = AuthorQueryValues();
|
||||
|
||||
AuthorQueryWhere _where;
|
||||
|
||||
@override
|
||||
get casts {
|
||||
return {};
|
||||
}
|
||||
|
||||
@override
|
||||
get tableName {
|
||||
return 'authors';
|
||||
}
|
||||
|
||||
@override
|
||||
get fields {
|
||||
return const ['id', 'created_at', 'updated_at', 'name'];
|
||||
}
|
||||
|
||||
@override
|
||||
AuthorQueryWhere get where {
|
||||
return _where;
|
||||
}
|
||||
|
||||
@override
|
||||
AuthorQueryWhere newWhereClause() {
|
||||
return AuthorQueryWhere(this);
|
||||
}
|
||||
|
||||
static Author parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
var model = Author(
|
||||
id: row[0].toString(),
|
||||
createdAt: (row[1] as DateTime),
|
||||
updatedAt: (row[2] as DateTime),
|
||||
name: (row[3] as String));
|
||||
return model;
|
||||
}
|
||||
|
||||
@override
|
||||
deserialize(List row) {
|
||||
return parseRow(row);
|
||||
}
|
||||
}
|
||||
|
||||
class AuthorQueryWhere extends QueryWhere {
|
||||
AuthorQueryWhere(AuthorQuery query)
|
||||
: id = NumericSqlExpressionBuilder<int>(query, 'id'),
|
||||
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
|
||||
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'),
|
||||
name = StringSqlExpressionBuilder(query, 'name');
|
||||
|
||||
final NumericSqlExpressionBuilder<int> id;
|
||||
|
||||
final DateTimeSqlExpressionBuilder createdAt;
|
||||
|
||||
final DateTimeSqlExpressionBuilder updatedAt;
|
||||
|
||||
final StringSqlExpressionBuilder name;
|
||||
|
||||
@override
|
||||
get expressionBuilders {
|
||||
return [id, createdAt, updatedAt, name];
|
||||
}
|
||||
}
|
||||
|
||||
class AuthorQueryValues extends MapQueryValues {
|
||||
@override
|
||||
get casts {
|
||||
return {};
|
||||
}
|
||||
|
||||
String get id {
|
||||
return (values['id'] as String);
|
||||
}
|
||||
|
||||
set id(String value) => values['id'] = value;
|
||||
DateTime get createdAt {
|
||||
return (values['created_at'] as DateTime);
|
||||
}
|
||||
|
||||
set createdAt(DateTime value) => values['created_at'] = value;
|
||||
DateTime get updatedAt {
|
||||
return (values['updated_at'] as DateTime);
|
||||
}
|
||||
|
||||
set updatedAt(DateTime value) => values['updated_at'] = value;
|
||||
String get name {
|
||||
return (values['name'] as String);
|
||||
}
|
||||
|
||||
set name(String value) => values['name'] = value;
|
||||
void copyFrom(Author model) {
|
||||
createdAt = model.createdAt;
|
||||
updatedAt = model.updatedAt;
|
||||
name = model.name;
|
||||
}
|
||||
}
|
||||
|
||||
// **************************************************************************
|
||||
// JsonModelGenerator
|
||||
// **************************************************************************
|
||||
|
||||
@generatedSerializable
|
||||
class Book extends _Book {
|
||||
Book(
|
||||
{this.id,
|
||||
this.createdAt,
|
||||
this.updatedAt,
|
||||
this.author,
|
||||
this.partnerAuthor,
|
||||
this.name});
|
||||
|
||||
/// A unique identifier corresponding to this item.
|
||||
@override
|
||||
String id;
|
||||
|
||||
/// The time at which this item was created.
|
||||
@override
|
||||
DateTime createdAt;
|
||||
|
||||
/// The last time at which this item was updated.
|
||||
@override
|
||||
DateTime updatedAt;
|
||||
|
||||
@override
|
||||
_Author author;
|
||||
|
||||
@override
|
||||
_Author partnerAuthor;
|
||||
|
||||
@override
|
||||
String name;
|
||||
|
||||
Book copyWith(
|
||||
{String id,
|
||||
DateTime createdAt,
|
||||
DateTime updatedAt,
|
||||
_Author author,
|
||||
_Author partnerAuthor,
|
||||
String name}) {
|
||||
return Book(
|
||||
id: id ?? this.id,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
updatedAt: updatedAt ?? this.updatedAt,
|
||||
author: author ?? this.author,
|
||||
partnerAuthor: partnerAuthor ?? this.partnerAuthor,
|
||||
name: name ?? this.name);
|
||||
}
|
||||
|
||||
bool operator ==(other) {
|
||||
return other is _Book &&
|
||||
other.id == id &&
|
||||
other.createdAt == createdAt &&
|
||||
other.updatedAt == updatedAt &&
|
||||
other.author == author &&
|
||||
other.partnerAuthor == partnerAuthor &&
|
||||
other.name == name;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return hashObjects([id, createdAt, updatedAt, author, partnerAuthor, name]);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return "Book(id=$id, createdAt=$createdAt, updatedAt=$updatedAt, author=$author, partnerAuthor=$partnerAuthor, name=$name)";
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return BookSerializer.toMap(this);
|
||||
}
|
||||
}
|
||||
|
||||
@generatedSerializable
|
||||
class Author extends _Author {
|
||||
Author({this.id, this.createdAt, this.updatedAt, this.name = 'Tobe Osakwe'});
|
||||
|
||||
/// A unique identifier corresponding to this item.
|
||||
@override
|
||||
String id;
|
||||
|
||||
/// The time at which this item was created.
|
||||
@override
|
||||
DateTime createdAt;
|
||||
|
||||
/// The last time at which this item was updated.
|
||||
@override
|
||||
DateTime updatedAt;
|
||||
|
||||
@override
|
||||
final String name;
|
||||
|
||||
Author copyWith(
|
||||
{String id, DateTime createdAt, DateTime updatedAt, String name}) {
|
||||
return Author(
|
||||
id: id ?? this.id,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
updatedAt: updatedAt ?? this.updatedAt,
|
||||
name: name ?? this.name);
|
||||
}
|
||||
|
||||
bool operator ==(other) {
|
||||
return other is _Author &&
|
||||
other.id == id &&
|
||||
other.createdAt == createdAt &&
|
||||
other.updatedAt == updatedAt &&
|
||||
other.name == name;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return hashObjects([id, createdAt, updatedAt, name]);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return "Author(id=$id, createdAt=$createdAt, updatedAt=$updatedAt, name=$name)";
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return AuthorSerializer.toMap(this);
|
||||
}
|
||||
}
|
||||
|
||||
// **************************************************************************
|
||||
// SerializerGenerator
|
||||
// **************************************************************************
|
||||
|
||||
const BookSerializer bookSerializer = BookSerializer();
|
||||
|
||||
class BookEncoder extends Converter<Book, Map> {
|
||||
const BookEncoder();
|
||||
|
||||
@override
|
||||
Map convert(Book model) => BookSerializer.toMap(model);
|
||||
}
|
||||
|
||||
class BookDecoder extends Converter<Map, Book> {
|
||||
const BookDecoder();
|
||||
|
||||
@override
|
||||
Book convert(Map map) => BookSerializer.fromMap(map);
|
||||
}
|
||||
|
||||
class BookSerializer extends Codec<Book, Map> {
|
||||
const BookSerializer();
|
||||
|
||||
@override
|
||||
get encoder => const BookEncoder();
|
||||
@override
|
||||
get decoder => const BookDecoder();
|
||||
static Book fromMap(Map map) {
|
||||
return Book(
|
||||
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,
|
||||
author: map['author'] != null
|
||||
? AuthorSerializer.fromMap(map['author'] as Map)
|
||||
: null,
|
||||
partnerAuthor: map['partner_author'] != null
|
||||
? AuthorSerializer.fromMap(map['partner_author'] as Map)
|
||||
: null,
|
||||
name: map['name'] as String);
|
||||
}
|
||||
|
||||
static Map<String, dynamic> toMap(_Book model) {
|
||||
if (model == null) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
'id': model.id,
|
||||
'created_at': model.createdAt?.toIso8601String(),
|
||||
'updated_at': model.updatedAt?.toIso8601String(),
|
||||
'author': AuthorSerializer.toMap(model.author),
|
||||
'partner_author': AuthorSerializer.toMap(model.partnerAuthor),
|
||||
'name': model.name
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
abstract class BookFields {
|
||||
static const List<String> allFields = <String>[
|
||||
id,
|
||||
createdAt,
|
||||
updatedAt,
|
||||
author,
|
||||
partnerAuthor,
|
||||
name
|
||||
];
|
||||
|
||||
static const String id = 'id';
|
||||
|
||||
static const String createdAt = 'created_at';
|
||||
|
||||
static const String updatedAt = 'updated_at';
|
||||
|
||||
static const String author = 'author';
|
||||
|
||||
static const String partnerAuthor = 'partner_author';
|
||||
|
||||
static const String name = 'name';
|
||||
}
|
||||
|
||||
const AuthorSerializer authorSerializer = AuthorSerializer();
|
||||
|
||||
class AuthorEncoder extends Converter<Author, Map> {
|
||||
const AuthorEncoder();
|
||||
|
||||
@override
|
||||
Map convert(Author model) => AuthorSerializer.toMap(model);
|
||||
}
|
||||
|
||||
class AuthorDecoder extends Converter<Map, Author> {
|
||||
const AuthorDecoder();
|
||||
|
||||
@override
|
||||
Author convert(Map map) => AuthorSerializer.fromMap(map);
|
||||
}
|
||||
|
||||
class AuthorSerializer extends Codec<Author, Map> {
|
||||
const AuthorSerializer();
|
||||
|
||||
@override
|
||||
get encoder => const AuthorEncoder();
|
||||
@override
|
||||
get decoder => const AuthorDecoder();
|
||||
static Author fromMap(Map map) {
|
||||
return Author(
|
||||
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,
|
||||
name: map['name'] as String ?? 'Tobe Osakwe');
|
||||
}
|
||||
|
||||
static Map<String, dynamic> toMap(_Author model) {
|
||||
if (model == null) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
'id': model.id,
|
||||
'created_at': model.createdAt?.toIso8601String(),
|
||||
'updated_at': model.updatedAt?.toIso8601String(),
|
||||
'name': model.name
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
abstract class AuthorFields {
|
||||
static const List<String> allFields = <String>[
|
||||
id,
|
||||
createdAt,
|
||||
updatedAt,
|
||||
name
|
||||
];
|
||||
|
||||
static const String id = 'id';
|
||||
|
||||
static const String createdAt = 'created_at';
|
||||
|
||||
static const String updatedAt = 'updated_at';
|
||||
|
||||
static const String name = 'name';
|
||||
}
|
367
angel_orm_test/lib/src/models/car.g.dart
Normal file
367
angel_orm_test/lib/src/models/car.g.dart
Normal file
|
@ -0,0 +1,367 @@
|
|||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of angel_orm.generator.models.car;
|
||||
|
||||
// **************************************************************************
|
||||
// MigrationGenerator
|
||||
// **************************************************************************
|
||||
|
||||
class CarMigration extends Migration {
|
||||
@override
|
||||
up(Schema schema) {
|
||||
schema.create('cars', (table) {
|
||||
table.serial('id')..primaryKey();
|
||||
table.timeStamp('created_at');
|
||||
table.timeStamp('updated_at');
|
||||
table.varChar('make');
|
||||
table.varChar('description');
|
||||
table.boolean('family_friendly');
|
||||
table.timeStamp('recalled_at');
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
down(Schema schema) {
|
||||
schema.drop('cars');
|
||||
}
|
||||
}
|
||||
|
||||
// **************************************************************************
|
||||
// OrmGenerator
|
||||
// **************************************************************************
|
||||
|
||||
class CarQuery extends Query<Car, CarQueryWhere> {
|
||||
CarQuery({Query parent, Set<String> trampoline}) : super(parent: parent) {
|
||||
trampoline ??= Set();
|
||||
trampoline.add(tableName);
|
||||
_where = CarQueryWhere(this);
|
||||
}
|
||||
|
||||
@override
|
||||
final CarQueryValues values = CarQueryValues();
|
||||
|
||||
CarQueryWhere _where;
|
||||
|
||||
@override
|
||||
get casts {
|
||||
return {};
|
||||
}
|
||||
|
||||
@override
|
||||
get tableName {
|
||||
return 'cars';
|
||||
}
|
||||
|
||||
@override
|
||||
get fields {
|
||||
return const [
|
||||
'id',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'make',
|
||||
'description',
|
||||
'family_friendly',
|
||||
'recalled_at'
|
||||
];
|
||||
}
|
||||
|
||||
@override
|
||||
CarQueryWhere get where {
|
||||
return _where;
|
||||
}
|
||||
|
||||
@override
|
||||
CarQueryWhere newWhereClause() {
|
||||
return CarQueryWhere(this);
|
||||
}
|
||||
|
||||
static Car parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
var model = Car(
|
||||
id: row[0].toString(),
|
||||
createdAt: (row[1] as DateTime),
|
||||
updatedAt: (row[2] as DateTime),
|
||||
make: (row[3] as String),
|
||||
description: (row[4] as String),
|
||||
familyFriendly: (row[5] as bool),
|
||||
recalledAt: (row[6] as DateTime));
|
||||
return model;
|
||||
}
|
||||
|
||||
@override
|
||||
deserialize(List row) {
|
||||
return parseRow(row);
|
||||
}
|
||||
}
|
||||
|
||||
class CarQueryWhere extends QueryWhere {
|
||||
CarQueryWhere(CarQuery query)
|
||||
: id = NumericSqlExpressionBuilder<int>(query, 'id'),
|
||||
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
|
||||
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'),
|
||||
make = StringSqlExpressionBuilder(query, 'make'),
|
||||
description = StringSqlExpressionBuilder(query, 'description'),
|
||||
familyFriendly = BooleanSqlExpressionBuilder(query, 'family_friendly'),
|
||||
recalledAt = DateTimeSqlExpressionBuilder(query, 'recalled_at');
|
||||
|
||||
final NumericSqlExpressionBuilder<int> id;
|
||||
|
||||
final DateTimeSqlExpressionBuilder createdAt;
|
||||
|
||||
final DateTimeSqlExpressionBuilder updatedAt;
|
||||
|
||||
final StringSqlExpressionBuilder make;
|
||||
|
||||
final StringSqlExpressionBuilder description;
|
||||
|
||||
final BooleanSqlExpressionBuilder familyFriendly;
|
||||
|
||||
final DateTimeSqlExpressionBuilder recalledAt;
|
||||
|
||||
@override
|
||||
get expressionBuilders {
|
||||
return [
|
||||
id,
|
||||
createdAt,
|
||||
updatedAt,
|
||||
make,
|
||||
description,
|
||||
familyFriendly,
|
||||
recalledAt
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
class CarQueryValues extends MapQueryValues {
|
||||
@override
|
||||
get casts {
|
||||
return {};
|
||||
}
|
||||
|
||||
String get id {
|
||||
return (values['id'] as String);
|
||||
}
|
||||
|
||||
set id(String value) => values['id'] = value;
|
||||
DateTime get createdAt {
|
||||
return (values['created_at'] as DateTime);
|
||||
}
|
||||
|
||||
set createdAt(DateTime value) => values['created_at'] = value;
|
||||
DateTime get updatedAt {
|
||||
return (values['updated_at'] as DateTime);
|
||||
}
|
||||
|
||||
set updatedAt(DateTime value) => values['updated_at'] = value;
|
||||
String get make {
|
||||
return (values['make'] as String);
|
||||
}
|
||||
|
||||
set make(String value) => values['make'] = value;
|
||||
String get description {
|
||||
return (values['description'] as String);
|
||||
}
|
||||
|
||||
set description(String value) => values['description'] = value;
|
||||
bool get familyFriendly {
|
||||
return (values['family_friendly'] as bool);
|
||||
}
|
||||
|
||||
set familyFriendly(bool value) => values['family_friendly'] = value;
|
||||
DateTime get recalledAt {
|
||||
return (values['recalled_at'] as DateTime);
|
||||
}
|
||||
|
||||
set recalledAt(DateTime value) => values['recalled_at'] = value;
|
||||
void copyFrom(Car model) {
|
||||
createdAt = model.createdAt;
|
||||
updatedAt = model.updatedAt;
|
||||
make = model.make;
|
||||
description = model.description;
|
||||
familyFriendly = model.familyFriendly;
|
||||
recalledAt = model.recalledAt;
|
||||
}
|
||||
}
|
||||
|
||||
// **************************************************************************
|
||||
// JsonModelGenerator
|
||||
// **************************************************************************
|
||||
|
||||
@generatedSerializable
|
||||
class Car extends _Car {
|
||||
Car(
|
||||
{this.id,
|
||||
this.createdAt,
|
||||
this.updatedAt,
|
||||
this.make,
|
||||
this.description,
|
||||
this.familyFriendly,
|
||||
this.recalledAt});
|
||||
|
||||
/// A unique identifier corresponding to this item.
|
||||
@override
|
||||
String id;
|
||||
|
||||
/// The time at which this item was created.
|
||||
@override
|
||||
DateTime createdAt;
|
||||
|
||||
/// The last time at which this item was updated.
|
||||
@override
|
||||
DateTime updatedAt;
|
||||
|
||||
@override
|
||||
String make;
|
||||
|
||||
@override
|
||||
String description;
|
||||
|
||||
@override
|
||||
bool familyFriendly;
|
||||
|
||||
@override
|
||||
DateTime recalledAt;
|
||||
|
||||
Car copyWith(
|
||||
{String id,
|
||||
DateTime createdAt,
|
||||
DateTime updatedAt,
|
||||
String make,
|
||||
String description,
|
||||
bool familyFriendly,
|
||||
DateTime recalledAt}) {
|
||||
return Car(
|
||||
id: id ?? this.id,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
updatedAt: updatedAt ?? this.updatedAt,
|
||||
make: make ?? this.make,
|
||||
description: description ?? this.description,
|
||||
familyFriendly: familyFriendly ?? this.familyFriendly,
|
||||
recalledAt: recalledAt ?? this.recalledAt);
|
||||
}
|
||||
|
||||
bool operator ==(other) {
|
||||
return other is _Car &&
|
||||
other.id == id &&
|
||||
other.createdAt == createdAt &&
|
||||
other.updatedAt == updatedAt &&
|
||||
other.make == make &&
|
||||
other.description == description &&
|
||||
other.familyFriendly == familyFriendly &&
|
||||
other.recalledAt == recalledAt;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return hashObjects([
|
||||
id,
|
||||
createdAt,
|
||||
updatedAt,
|
||||
make,
|
||||
description,
|
||||
familyFriendly,
|
||||
recalledAt
|
||||
]);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return "Car(id=$id, createdAt=$createdAt, updatedAt=$updatedAt, make=$make, description=$description, familyFriendly=$familyFriendly, recalledAt=$recalledAt)";
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return CarSerializer.toMap(this);
|
||||
}
|
||||
}
|
||||
|
||||
// **************************************************************************
|
||||
// SerializerGenerator
|
||||
// **************************************************************************
|
||||
|
||||
const CarSerializer carSerializer = CarSerializer();
|
||||
|
||||
class CarEncoder extends Converter<Car, Map> {
|
||||
const CarEncoder();
|
||||
|
||||
@override
|
||||
Map convert(Car model) => CarSerializer.toMap(model);
|
||||
}
|
||||
|
||||
class CarDecoder extends Converter<Map, Car> {
|
||||
const CarDecoder();
|
||||
|
||||
@override
|
||||
Car convert(Map map) => CarSerializer.fromMap(map);
|
||||
}
|
||||
|
||||
class CarSerializer extends Codec<Car, Map> {
|
||||
const CarSerializer();
|
||||
|
||||
@override
|
||||
get encoder => const CarEncoder();
|
||||
@override
|
||||
get decoder => const CarDecoder();
|
||||
static Car fromMap(Map map) {
|
||||
return Car(
|
||||
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,
|
||||
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);
|
||||
}
|
||||
|
||||
static Map<String, dynamic> toMap(_Car model) {
|
||||
if (model == null) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
'id': model.id,
|
||||
'created_at': model.createdAt?.toIso8601String(),
|
||||
'updated_at': model.updatedAt?.toIso8601String(),
|
||||
'make': model.make,
|
||||
'description': model.description,
|
||||
'family_friendly': model.familyFriendly,
|
||||
'recalled_at': model.recalledAt?.toIso8601String()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
abstract class CarFields {
|
||||
static const List<String> allFields = <String>[
|
||||
id,
|
||||
createdAt,
|
||||
updatedAt,
|
||||
make,
|
||||
description,
|
||||
familyFriendly,
|
||||
recalledAt
|
||||
];
|
||||
|
||||
static const String id = 'id';
|
||||
|
||||
static const String createdAt = 'created_at';
|
||||
|
||||
static const String updatedAt = 'updated_at';
|
||||
|
||||
static const String make = 'make';
|
||||
|
||||
static const String description = 'description';
|
||||
|
||||
static const String familyFriendly = 'family_friendly';
|
||||
|
||||
static const String recalledAt = 'recalled_at';
|
||||
}
|
798
angel_orm_test/lib/src/models/email_indexed.g.dart
Normal file
798
angel_orm_test/lib/src/models/email_indexed.g.dart
Normal file
|
@ -0,0 +1,798 @@
|
|||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'email_indexed.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// MigrationGenerator
|
||||
// **************************************************************************
|
||||
|
||||
class RoleMigration extends Migration {
|
||||
@override
|
||||
up(Schema schema) {
|
||||
schema.create('roles', (table) {
|
||||
table.declare('role', ColumnType('varchar'))..primaryKey();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
down(Schema schema) {
|
||||
schema.drop('roles', cascade: true);
|
||||
}
|
||||
}
|
||||
|
||||
class RoleUserMigration extends Migration {
|
||||
@override
|
||||
up(Schema schema) {
|
||||
schema.create('role_users', (table) {
|
||||
table
|
||||
.declare('role_role', ColumnType('varchar'))
|
||||
.references('roles', 'role');
|
||||
table
|
||||
.declare('user_email', ColumnType('varchar'))
|
||||
.references('users', 'email');
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
down(Schema schema) {
|
||||
schema.drop('role_users');
|
||||
}
|
||||
}
|
||||
|
||||
class UserMigration extends Migration {
|
||||
@override
|
||||
up(Schema schema) {
|
||||
schema.create('users', (table) {
|
||||
table.varChar('email')..primaryKey();
|
||||
table.varChar('name');
|
||||
table.varChar('password');
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
down(Schema schema) {
|
||||
schema.drop('users', cascade: true);
|
||||
}
|
||||
}
|
||||
|
||||
// **************************************************************************
|
||||
// OrmGenerator
|
||||
// **************************************************************************
|
||||
|
||||
class RoleQuery extends Query<Role, RoleQueryWhere> {
|
||||
RoleQuery({Query parent, Set<String> trampoline}) : super(parent: parent) {
|
||||
trampoline ??= Set();
|
||||
trampoline.add(tableName);
|
||||
_where = RoleQueryWhere(this);
|
||||
leftJoin(_users = RoleUserQuery(trampoline: trampoline, parent: this),
|
||||
'role', 'role_role',
|
||||
additionalFields: const ['email', 'name', 'password'],
|
||||
trampoline: trampoline);
|
||||
}
|
||||
|
||||
@override
|
||||
final RoleQueryValues values = RoleQueryValues();
|
||||
|
||||
RoleQueryWhere _where;
|
||||
|
||||
RoleUserQuery _users;
|
||||
|
||||
@override
|
||||
get casts {
|
||||
return {};
|
||||
}
|
||||
|
||||
@override
|
||||
get tableName {
|
||||
return 'roles';
|
||||
}
|
||||
|
||||
@override
|
||||
get fields {
|
||||
return const ['role'];
|
||||
}
|
||||
|
||||
@override
|
||||
RoleQueryWhere get where {
|
||||
return _where;
|
||||
}
|
||||
|
||||
@override
|
||||
RoleQueryWhere newWhereClause() {
|
||||
return RoleQueryWhere(this);
|
||||
}
|
||||
|
||||
static Role parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
var model = Role(role: (row[0] as String));
|
||||
if (row.length > 1) {
|
||||
model = model.copyWith(
|
||||
users: [UserQuery.parseRow(row.skip(1).take(3).toList())]
|
||||
.where((x) => x != null)
|
||||
.toList());
|
||||
}
|
||||
return model;
|
||||
}
|
||||
|
||||
@override
|
||||
deserialize(List row) {
|
||||
return parseRow(row);
|
||||
}
|
||||
|
||||
RoleUserQuery get users {
|
||||
return _users;
|
||||
}
|
||||
|
||||
@override
|
||||
bool canCompile(trampoline) {
|
||||
return (!(trampoline.contains('roles') &&
|
||||
trampoline.contains('role_users')));
|
||||
}
|
||||
|
||||
@override
|
||||
get(QueryExecutor executor) {
|
||||
return super.get(executor).then((result) {
|
||||
return result.fold<List<Role>>([], (out, model) {
|
||||
var idx = out.indexWhere((m) => m.role == model.role);
|
||||
|
||||
if (idx == -1) {
|
||||
return out..add(model);
|
||||
} else {
|
||||
var l = out[idx];
|
||||
return out
|
||||
..[idx] = l.copyWith(
|
||||
users: List<_User>.from(l.users ?? [])
|
||||
..addAll(model.users ?? []));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
update(QueryExecutor executor) {
|
||||
return super.update(executor).then((result) {
|
||||
return result.fold<List<Role>>([], (out, model) {
|
||||
var idx = out.indexWhere((m) => m.role == model.role);
|
||||
|
||||
if (idx == -1) {
|
||||
return out..add(model);
|
||||
} else {
|
||||
var l = out[idx];
|
||||
return out
|
||||
..[idx] = l.copyWith(
|
||||
users: List<_User>.from(l.users ?? [])
|
||||
..addAll(model.users ?? []));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
delete(QueryExecutor executor) {
|
||||
return super.delete(executor).then((result) {
|
||||
return result.fold<List<Role>>([], (out, model) {
|
||||
var idx = out.indexWhere((m) => m.role == model.role);
|
||||
|
||||
if (idx == -1) {
|
||||
return out..add(model);
|
||||
} else {
|
||||
var l = out[idx];
|
||||
return out
|
||||
..[idx] = l.copyWith(
|
||||
users: List<_User>.from(l.users ?? [])
|
||||
..addAll(model.users ?? []));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class RoleQueryWhere extends QueryWhere {
|
||||
RoleQueryWhere(RoleQuery query)
|
||||
: role = StringSqlExpressionBuilder(query, 'role');
|
||||
|
||||
final StringSqlExpressionBuilder role;
|
||||
|
||||
@override
|
||||
get expressionBuilders {
|
||||
return [role];
|
||||
}
|
||||
}
|
||||
|
||||
class RoleQueryValues extends MapQueryValues {
|
||||
@override
|
||||
get casts {
|
||||
return {};
|
||||
}
|
||||
|
||||
String get role {
|
||||
return (values['role'] as String);
|
||||
}
|
||||
|
||||
set role(String value) => values['role'] = value;
|
||||
void copyFrom(Role model) {
|
||||
role = model.role;
|
||||
}
|
||||
}
|
||||
|
||||
class RoleUserQuery extends Query<RoleUser, RoleUserQueryWhere> {
|
||||
RoleUserQuery({Query parent, Set<String> trampoline})
|
||||
: super(parent: parent) {
|
||||
trampoline ??= Set();
|
||||
trampoline.add(tableName);
|
||||
_where = RoleUserQueryWhere(this);
|
||||
leftJoin(_role = RoleQuery(trampoline: trampoline, parent: this),
|
||||
'role_role', 'role',
|
||||
additionalFields: const ['role'], trampoline: trampoline);
|
||||
leftJoin(_user = UserQuery(trampoline: trampoline, parent: this),
|
||||
'user_email', 'email',
|
||||
additionalFields: const ['email', 'name', 'password'],
|
||||
trampoline: trampoline);
|
||||
}
|
||||
|
||||
@override
|
||||
final RoleUserQueryValues values = RoleUserQueryValues();
|
||||
|
||||
RoleUserQueryWhere _where;
|
||||
|
||||
RoleQuery _role;
|
||||
|
||||
UserQuery _user;
|
||||
|
||||
@override
|
||||
get casts {
|
||||
return {};
|
||||
}
|
||||
|
||||
@override
|
||||
get tableName {
|
||||
return 'role_users';
|
||||
}
|
||||
|
||||
@override
|
||||
get fields {
|
||||
return const ['role_role', 'user_email'];
|
||||
}
|
||||
|
||||
@override
|
||||
RoleUserQueryWhere get where {
|
||||
return _where;
|
||||
}
|
||||
|
||||
@override
|
||||
RoleUserQueryWhere newWhereClause() {
|
||||
return RoleUserQueryWhere(this);
|
||||
}
|
||||
|
||||
static RoleUser parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
var model = RoleUser();
|
||||
if (row.length > 2) {
|
||||
model = model.copyWith(
|
||||
role: RoleQuery.parseRow(row.skip(2).take(1).toList()));
|
||||
}
|
||||
if (row.length > 3) {
|
||||
model = model.copyWith(
|
||||
user: UserQuery.parseRow(row.skip(3).take(3).toList()));
|
||||
}
|
||||
return model;
|
||||
}
|
||||
|
||||
@override
|
||||
deserialize(List row) {
|
||||
return parseRow(row);
|
||||
}
|
||||
|
||||
RoleQuery get role {
|
||||
return _role;
|
||||
}
|
||||
|
||||
UserQuery get user {
|
||||
return _user;
|
||||
}
|
||||
}
|
||||
|
||||
class RoleUserQueryWhere extends QueryWhere {
|
||||
RoleUserQueryWhere(RoleUserQuery query)
|
||||
: roleRole = StringSqlExpressionBuilder(query, 'role_role'),
|
||||
userEmail = StringSqlExpressionBuilder(query, 'user_email');
|
||||
|
||||
final StringSqlExpressionBuilder roleRole;
|
||||
|
||||
final StringSqlExpressionBuilder userEmail;
|
||||
|
||||
@override
|
||||
get expressionBuilders {
|
||||
return [roleRole, userEmail];
|
||||
}
|
||||
}
|
||||
|
||||
class RoleUserQueryValues extends MapQueryValues {
|
||||
@override
|
||||
get casts {
|
||||
return {};
|
||||
}
|
||||
|
||||
String get roleRole {
|
||||
return (values['role_role'] as String);
|
||||
}
|
||||
|
||||
set roleRole(String value) => values['role_role'] = value;
|
||||
String get userEmail {
|
||||
return (values['user_email'] as String);
|
||||
}
|
||||
|
||||
set userEmail(String value) => values['user_email'] = value;
|
||||
void copyFrom(RoleUser model) {
|
||||
if (model.role != null) {
|
||||
values['role_role'] = model.role.role;
|
||||
}
|
||||
if (model.user != null) {
|
||||
values['user_email'] = model.user.email;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class UserQuery extends Query<User, UserQueryWhere> {
|
||||
UserQuery({Query parent, Set<String> trampoline}) : super(parent: parent) {
|
||||
trampoline ??= Set();
|
||||
trampoline.add(tableName);
|
||||
_where = UserQueryWhere(this);
|
||||
leftJoin(_roles = RoleUserQuery(trampoline: trampoline, parent: this),
|
||||
'email', 'user_email',
|
||||
additionalFields: const ['role'], trampoline: trampoline);
|
||||
}
|
||||
|
||||
@override
|
||||
final UserQueryValues values = UserQueryValues();
|
||||
|
||||
UserQueryWhere _where;
|
||||
|
||||
RoleUserQuery _roles;
|
||||
|
||||
@override
|
||||
get casts {
|
||||
return {};
|
||||
}
|
||||
|
||||
@override
|
||||
get tableName {
|
||||
return 'users';
|
||||
}
|
||||
|
||||
@override
|
||||
get fields {
|
||||
return const ['email', 'name', 'password'];
|
||||
}
|
||||
|
||||
@override
|
||||
UserQueryWhere get where {
|
||||
return _where;
|
||||
}
|
||||
|
||||
@override
|
||||
UserQueryWhere newWhereClause() {
|
||||
return UserQueryWhere(this);
|
||||
}
|
||||
|
||||
static User parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
var model = User(
|
||||
email: (row[0] as String),
|
||||
name: (row[1] as String),
|
||||
password: (row[2] as String));
|
||||
if (row.length > 3) {
|
||||
model = model.copyWith(
|
||||
roles: [RoleQuery.parseRow(row.skip(3).take(1).toList())]
|
||||
.where((x) => x != null)
|
||||
.toList());
|
||||
}
|
||||
return model;
|
||||
}
|
||||
|
||||
@override
|
||||
deserialize(List row) {
|
||||
return parseRow(row);
|
||||
}
|
||||
|
||||
RoleUserQuery get roles {
|
||||
return _roles;
|
||||
}
|
||||
|
||||
@override
|
||||
bool canCompile(trampoline) {
|
||||
return (!(trampoline.contains('users') &&
|
||||
trampoline.contains('role_users')));
|
||||
}
|
||||
|
||||
@override
|
||||
get(QueryExecutor executor) {
|
||||
return super.get(executor).then((result) {
|
||||
return result.fold<List<User>>([], (out, model) {
|
||||
var idx = out.indexWhere((m) => m.email == model.email);
|
||||
|
||||
if (idx == -1) {
|
||||
return out..add(model);
|
||||
} else {
|
||||
var l = out[idx];
|
||||
return out
|
||||
..[idx] = l.copyWith(
|
||||
roles: List<_Role>.from(l.roles ?? [])
|
||||
..addAll(model.roles ?? []));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
update(QueryExecutor executor) {
|
||||
return super.update(executor).then((result) {
|
||||
return result.fold<List<User>>([], (out, model) {
|
||||
var idx = out.indexWhere((m) => m.email == model.email);
|
||||
|
||||
if (idx == -1) {
|
||||
return out..add(model);
|
||||
} else {
|
||||
var l = out[idx];
|
||||
return out
|
||||
..[idx] = l.copyWith(
|
||||
roles: List<_Role>.from(l.roles ?? [])
|
||||
..addAll(model.roles ?? []));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
delete(QueryExecutor executor) {
|
||||
return super.delete(executor).then((result) {
|
||||
return result.fold<List<User>>([], (out, model) {
|
||||
var idx = out.indexWhere((m) => m.email == model.email);
|
||||
|
||||
if (idx == -1) {
|
||||
return out..add(model);
|
||||
} else {
|
||||
var l = out[idx];
|
||||
return out
|
||||
..[idx] = l.copyWith(
|
||||
roles: List<_Role>.from(l.roles ?? [])
|
||||
..addAll(model.roles ?? []));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class UserQueryWhere extends QueryWhere {
|
||||
UserQueryWhere(UserQuery query)
|
||||
: email = StringSqlExpressionBuilder(query, 'email'),
|
||||
name = StringSqlExpressionBuilder(query, 'name'),
|
||||
password = StringSqlExpressionBuilder(query, 'password');
|
||||
|
||||
final StringSqlExpressionBuilder email;
|
||||
|
||||
final StringSqlExpressionBuilder name;
|
||||
|
||||
final StringSqlExpressionBuilder password;
|
||||
|
||||
@override
|
||||
get expressionBuilders {
|
||||
return [email, name, password];
|
||||
}
|
||||
}
|
||||
|
||||
class UserQueryValues extends MapQueryValues {
|
||||
@override
|
||||
get casts {
|
||||
return {};
|
||||
}
|
||||
|
||||
String get email {
|
||||
return (values['email'] as String);
|
||||
}
|
||||
|
||||
set email(String value) => values['email'] = value;
|
||||
String get name {
|
||||
return (values['name'] as String);
|
||||
}
|
||||
|
||||
set name(String value) => values['name'] = value;
|
||||
String get password {
|
||||
return (values['password'] as String);
|
||||
}
|
||||
|
||||
set password(String value) => values['password'] = value;
|
||||
void copyFrom(User model) {
|
||||
email = model.email;
|
||||
name = model.name;
|
||||
password = model.password;
|
||||
}
|
||||
}
|
||||
|
||||
// **************************************************************************
|
||||
// JsonModelGenerator
|
||||
// **************************************************************************
|
||||
|
||||
@generatedSerializable
|
||||
class Role implements _Role {
|
||||
const Role({this.role, this.users});
|
||||
|
||||
@override
|
||||
final String role;
|
||||
|
||||
@override
|
||||
final List<_User> users;
|
||||
|
||||
Role copyWith({String role, List<_User> users}) {
|
||||
return Role(role: role ?? this.role, users: users ?? this.users);
|
||||
}
|
||||
|
||||
bool operator ==(other) {
|
||||
return other is _Role &&
|
||||
other.role == role &&
|
||||
ListEquality<_User>(DefaultEquality<_User>())
|
||||
.equals(other.users, users);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return hashObjects([role, users]);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return "Role(role=$role, users=$users)";
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return RoleSerializer.toMap(this);
|
||||
}
|
||||
}
|
||||
|
||||
@generatedSerializable
|
||||
class RoleUser implements _RoleUser {
|
||||
const RoleUser({this.role, this.user});
|
||||
|
||||
@override
|
||||
final _Role role;
|
||||
|
||||
@override
|
||||
final _User user;
|
||||
|
||||
RoleUser copyWith({_Role role, _User user}) {
|
||||
return RoleUser(role: role ?? this.role, user: user ?? this.user);
|
||||
}
|
||||
|
||||
bool operator ==(other) {
|
||||
return other is _RoleUser && other.role == role && other.user == user;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return hashObjects([role, user]);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return "RoleUser(role=$role, user=$user)";
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return RoleUserSerializer.toMap(this);
|
||||
}
|
||||
}
|
||||
|
||||
@generatedSerializable
|
||||
class User implements _User {
|
||||
const User({this.email, this.name, this.password, this.roles});
|
||||
|
||||
@override
|
||||
final String email;
|
||||
|
||||
@override
|
||||
final String name;
|
||||
|
||||
@override
|
||||
final String password;
|
||||
|
||||
@override
|
||||
final List<_Role> roles;
|
||||
|
||||
User copyWith(
|
||||
{String email, String name, String password, List<_Role> roles}) {
|
||||
return User(
|
||||
email: email ?? this.email,
|
||||
name: name ?? this.name,
|
||||
password: password ?? this.password,
|
||||
roles: roles ?? this.roles);
|
||||
}
|
||||
|
||||
bool operator ==(other) {
|
||||
return other is _User &&
|
||||
other.email == email &&
|
||||
other.name == name &&
|
||||
other.password == password &&
|
||||
ListEquality<_Role>(DefaultEquality<_Role>())
|
||||
.equals(other.roles, roles);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return hashObjects([email, name, password, roles]);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return "User(email=$email, name=$name, password=$password, roles=$roles)";
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return UserSerializer.toMap(this);
|
||||
}
|
||||
}
|
||||
|
||||
// **************************************************************************
|
||||
// SerializerGenerator
|
||||
// **************************************************************************
|
||||
|
||||
const RoleSerializer roleSerializer = RoleSerializer();
|
||||
|
||||
class RoleEncoder extends Converter<Role, Map> {
|
||||
const RoleEncoder();
|
||||
|
||||
@override
|
||||
Map convert(Role model) => RoleSerializer.toMap(model);
|
||||
}
|
||||
|
||||
class RoleDecoder extends Converter<Map, Role> {
|
||||
const RoleDecoder();
|
||||
|
||||
@override
|
||||
Role convert(Map map) => RoleSerializer.fromMap(map);
|
||||
}
|
||||
|
||||
class RoleSerializer extends Codec<Role, Map> {
|
||||
const RoleSerializer();
|
||||
|
||||
@override
|
||||
get encoder => const RoleEncoder();
|
||||
@override
|
||||
get decoder => const RoleDecoder();
|
||||
static Role fromMap(Map map) {
|
||||
return Role(
|
||||
role: map['role'] as String,
|
||||
users: map['users'] is Iterable
|
||||
? List.unmodifiable(((map['users'] as Iterable).whereType<Map>())
|
||||
.map(UserSerializer.fromMap))
|
||||
: null);
|
||||
}
|
||||
|
||||
static Map<String, dynamic> toMap(_Role model) {
|
||||
if (model == null) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
'role': model.role,
|
||||
'users': model.users?.map((m) => UserSerializer.toMap(m))?.toList()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
abstract class RoleFields {
|
||||
static const List<String> allFields = <String>[role, users];
|
||||
|
||||
static const String role = 'role';
|
||||
|
||||
static const String users = 'users';
|
||||
}
|
||||
|
||||
const RoleUserSerializer roleUserSerializer = RoleUserSerializer();
|
||||
|
||||
class RoleUserEncoder extends Converter<RoleUser, Map> {
|
||||
const RoleUserEncoder();
|
||||
|
||||
@override
|
||||
Map convert(RoleUser model) => RoleUserSerializer.toMap(model);
|
||||
}
|
||||
|
||||
class RoleUserDecoder extends Converter<Map, RoleUser> {
|
||||
const RoleUserDecoder();
|
||||
|
||||
@override
|
||||
RoleUser convert(Map map) => RoleUserSerializer.fromMap(map);
|
||||
}
|
||||
|
||||
class RoleUserSerializer extends Codec<RoleUser, Map> {
|
||||
const RoleUserSerializer();
|
||||
|
||||
@override
|
||||
get encoder => const RoleUserEncoder();
|
||||
@override
|
||||
get decoder => const RoleUserDecoder();
|
||||
static RoleUser fromMap(Map map) {
|
||||
return RoleUser(
|
||||
role: map['role'] != null
|
||||
? RoleSerializer.fromMap(map['role'] as Map)
|
||||
: null,
|
||||
user: map['user'] != null
|
||||
? UserSerializer.fromMap(map['user'] as Map)
|
||||
: null);
|
||||
}
|
||||
|
||||
static Map<String, dynamic> toMap(_RoleUser model) {
|
||||
if (model == null) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
'role': RoleSerializer.toMap(model.role),
|
||||
'user': UserSerializer.toMap(model.user)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
abstract class RoleUserFields {
|
||||
static const List<String> allFields = <String>[role, user];
|
||||
|
||||
static const String role = 'role';
|
||||
|
||||
static const String user = 'user';
|
||||
}
|
||||
|
||||
const UserSerializer userSerializer = UserSerializer();
|
||||
|
||||
class UserEncoder extends Converter<User, Map> {
|
||||
const UserEncoder();
|
||||
|
||||
@override
|
||||
Map convert(User model) => UserSerializer.toMap(model);
|
||||
}
|
||||
|
||||
class UserDecoder extends Converter<Map, User> {
|
||||
const UserDecoder();
|
||||
|
||||
@override
|
||||
User convert(Map map) => UserSerializer.fromMap(map);
|
||||
}
|
||||
|
||||
class UserSerializer extends Codec<User, Map> {
|
||||
const UserSerializer();
|
||||
|
||||
@override
|
||||
get encoder => const UserEncoder();
|
||||
@override
|
||||
get decoder => const UserDecoder();
|
||||
static User fromMap(Map map) {
|
||||
return User(
|
||||
email: map['email'] as String,
|
||||
name: map['name'] as String,
|
||||
password: map['password'] as String,
|
||||
roles: map['roles'] is Iterable
|
||||
? List.unmodifiable(((map['roles'] as Iterable).whereType<Map>())
|
||||
.map(RoleSerializer.fromMap))
|
||||
: null);
|
||||
}
|
||||
|
||||
static Map<String, dynamic> toMap(_User model) {
|
||||
if (model == null) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
'email': model.email,
|
||||
'name': model.name,
|
||||
'password': model.password,
|
||||
'roles': model.roles?.map((m) => RoleSerializer.toMap(m))?.toList()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
abstract class UserFields {
|
||||
static const List<String> allFields = <String>[email, name, password, roles];
|
||||
|
||||
static const String email = 'email';
|
||||
|
||||
static const String name = 'name';
|
||||
|
||||
static const String password = 'password';
|
||||
|
||||
static const String roles = 'roles';
|
||||
}
|
275
angel_orm_test/lib/src/models/has_car.g.dart
Normal file
275
angel_orm_test/lib/src/models/has_car.g.dart
Normal file
|
@ -0,0 +1,275 @@
|
|||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'has_car.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// MigrationGenerator
|
||||
// **************************************************************************
|
||||
|
||||
class HasCarMigration extends Migration {
|
||||
@override
|
||||
up(Schema schema) {
|
||||
schema.create('has_cars', (table) {
|
||||
table.serial('id')..primaryKey();
|
||||
table.timeStamp('created_at');
|
||||
table.timeStamp('updated_at');
|
||||
table.integer('type');
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
down(Schema schema) {
|
||||
schema.drop('has_cars');
|
||||
}
|
||||
}
|
||||
|
||||
// **************************************************************************
|
||||
// OrmGenerator
|
||||
// **************************************************************************
|
||||
|
||||
class HasCarQuery extends Query<HasCar, HasCarQueryWhere> {
|
||||
HasCarQuery({Query parent, Set<String> trampoline}) : super(parent: parent) {
|
||||
trampoline ??= Set();
|
||||
trampoline.add(tableName);
|
||||
_where = HasCarQueryWhere(this);
|
||||
}
|
||||
|
||||
@override
|
||||
final HasCarQueryValues values = HasCarQueryValues();
|
||||
|
||||
HasCarQueryWhere _where;
|
||||
|
||||
@override
|
||||
get casts {
|
||||
return {};
|
||||
}
|
||||
|
||||
@override
|
||||
get tableName {
|
||||
return 'has_cars';
|
||||
}
|
||||
|
||||
@override
|
||||
get fields {
|
||||
return const ['id', 'created_at', 'updated_at', 'type'];
|
||||
}
|
||||
|
||||
@override
|
||||
HasCarQueryWhere get where {
|
||||
return _where;
|
||||
}
|
||||
|
||||
@override
|
||||
HasCarQueryWhere newWhereClause() {
|
||||
return HasCarQueryWhere(this);
|
||||
}
|
||||
|
||||
static HasCar parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
var model = HasCar(
|
||||
id: row[0].toString(),
|
||||
createdAt: (row[1] as DateTime),
|
||||
updatedAt: (row[2] as DateTime),
|
||||
type: row[3] == null ? null : CarType.values[(row[3] as int)]);
|
||||
return model;
|
||||
}
|
||||
|
||||
@override
|
||||
deserialize(List row) {
|
||||
return parseRow(row);
|
||||
}
|
||||
}
|
||||
|
||||
class HasCarQueryWhere extends QueryWhere {
|
||||
HasCarQueryWhere(HasCarQuery query)
|
||||
: id = NumericSqlExpressionBuilder<int>(query, 'id'),
|
||||
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
|
||||
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'),
|
||||
type = EnumSqlExpressionBuilder<CarType>(query, 'type', (v) => v.index);
|
||||
|
||||
final NumericSqlExpressionBuilder<int> id;
|
||||
|
||||
final DateTimeSqlExpressionBuilder createdAt;
|
||||
|
||||
final DateTimeSqlExpressionBuilder updatedAt;
|
||||
|
||||
final EnumSqlExpressionBuilder<CarType> type;
|
||||
|
||||
@override
|
||||
get expressionBuilders {
|
||||
return [id, createdAt, updatedAt, type];
|
||||
}
|
||||
}
|
||||
|
||||
class HasCarQueryValues extends MapQueryValues {
|
||||
@override
|
||||
get casts {
|
||||
return {};
|
||||
}
|
||||
|
||||
String get id {
|
||||
return (values['id'] as String);
|
||||
}
|
||||
|
||||
set id(String value) => values['id'] = value;
|
||||
DateTime get createdAt {
|
||||
return (values['created_at'] as DateTime);
|
||||
}
|
||||
|
||||
set createdAt(DateTime value) => values['created_at'] = value;
|
||||
DateTime get updatedAt {
|
||||
return (values['updated_at'] as DateTime);
|
||||
}
|
||||
|
||||
set updatedAt(DateTime value) => values['updated_at'] = value;
|
||||
CarType get type {
|
||||
return CarType.values[(values['type'] as int)];
|
||||
}
|
||||
|
||||
set type(CarType value) => values['type'] = value?.index;
|
||||
void copyFrom(HasCar model) {
|
||||
createdAt = model.createdAt;
|
||||
updatedAt = model.updatedAt;
|
||||
type = model.type;
|
||||
}
|
||||
}
|
||||
|
||||
// **************************************************************************
|
||||
// JsonModelGenerator
|
||||
// **************************************************************************
|
||||
|
||||
@generatedSerializable
|
||||
class HasCar extends _HasCar {
|
||||
HasCar({this.id, this.createdAt, this.updatedAt, this.type = CarType.sedan});
|
||||
|
||||
/// A unique identifier corresponding to this item.
|
||||
@override
|
||||
String id;
|
||||
|
||||
/// The time at which this item was created.
|
||||
@override
|
||||
DateTime createdAt;
|
||||
|
||||
/// The last time at which this item was updated.
|
||||
@override
|
||||
DateTime updatedAt;
|
||||
|
||||
@override
|
||||
final CarType type;
|
||||
|
||||
HasCar copyWith(
|
||||
{String id, DateTime createdAt, DateTime updatedAt, CarType type}) {
|
||||
return HasCar(
|
||||
id: id ?? this.id,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
updatedAt: updatedAt ?? this.updatedAt,
|
||||
type: type ?? this.type);
|
||||
}
|
||||
|
||||
bool operator ==(other) {
|
||||
return other is _HasCar &&
|
||||
other.id == id &&
|
||||
other.createdAt == createdAt &&
|
||||
other.updatedAt == updatedAt &&
|
||||
other.type == type;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return hashObjects([id, createdAt, updatedAt, type]);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return "HasCar(id=$id, createdAt=$createdAt, updatedAt=$updatedAt, type=$type)";
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return HasCarSerializer.toMap(this);
|
||||
}
|
||||
}
|
||||
|
||||
// **************************************************************************
|
||||
// SerializerGenerator
|
||||
// **************************************************************************
|
||||
|
||||
const HasCarSerializer hasCarSerializer = HasCarSerializer();
|
||||
|
||||
class HasCarEncoder extends Converter<HasCar, Map> {
|
||||
const HasCarEncoder();
|
||||
|
||||
@override
|
||||
Map convert(HasCar model) => HasCarSerializer.toMap(model);
|
||||
}
|
||||
|
||||
class HasCarDecoder extends Converter<Map, HasCar> {
|
||||
const HasCarDecoder();
|
||||
|
||||
@override
|
||||
HasCar convert(Map map) => HasCarSerializer.fromMap(map);
|
||||
}
|
||||
|
||||
class HasCarSerializer extends Codec<HasCar, Map> {
|
||||
const HasCarSerializer();
|
||||
|
||||
@override
|
||||
get encoder => const HasCarEncoder();
|
||||
@override
|
||||
get decoder => const HasCarDecoder();
|
||||
static HasCar fromMap(Map map) {
|
||||
if (map['type'] == null) {
|
||||
throw FormatException("Missing required field 'type' on HasCar.");
|
||||
}
|
||||
|
||||
return HasCar(
|
||||
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,
|
||||
type: map['type'] is CarType
|
||||
? (map['type'] as CarType)
|
||||
: (map['type'] is int
|
||||
? CarType.values[map['type'] as int]
|
||||
: CarType.sedan));
|
||||
}
|
||||
|
||||
static Map<String, dynamic> toMap(_HasCar model) {
|
||||
if (model == null) {
|
||||
return null;
|
||||
}
|
||||
if (model.type == null) {
|
||||
throw FormatException("Missing required field 'type' on HasCar.");
|
||||
}
|
||||
|
||||
return {
|
||||
'id': model.id,
|
||||
'created_at': model.createdAt?.toIso8601String(),
|
||||
'updated_at': model.updatedAt?.toIso8601String(),
|
||||
'type': model.type == null ? null : CarType.values.indexOf(model.type)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
abstract class HasCarFields {
|
||||
static const List<String> allFields = <String>[
|
||||
id,
|
||||
createdAt,
|
||||
updatedAt,
|
||||
type
|
||||
];
|
||||
|
||||
static const String id = 'id';
|
||||
|
||||
static const String createdAt = 'created_at';
|
||||
|
||||
static const String updatedAt = 'updated_at';
|
||||
|
||||
static const String type = 'type';
|
||||
}
|
208
angel_orm_test/lib/src/models/has_map.g.dart
Normal file
208
angel_orm_test/lib/src/models/has_map.g.dart
Normal file
|
@ -0,0 +1,208 @@
|
|||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'has_map.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// MigrationGenerator
|
||||
// **************************************************************************
|
||||
|
||||
class HasMapMigration extends Migration {
|
||||
@override
|
||||
up(Schema schema) {
|
||||
schema.create('has_maps', (table) {
|
||||
table.declare('value', ColumnType('jsonb'));
|
||||
table.declare('list', ColumnType('jsonb'));
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
down(Schema schema) {
|
||||
schema.drop('has_maps');
|
||||
}
|
||||
}
|
||||
|
||||
// **************************************************************************
|
||||
// OrmGenerator
|
||||
// **************************************************************************
|
||||
|
||||
class HasMapQuery extends Query<HasMap, HasMapQueryWhere> {
|
||||
HasMapQuery({Query parent, Set<String> trampoline}) : super(parent: parent) {
|
||||
trampoline ??= Set();
|
||||
trampoline.add(tableName);
|
||||
_where = HasMapQueryWhere(this);
|
||||
}
|
||||
|
||||
@override
|
||||
final HasMapQueryValues values = HasMapQueryValues();
|
||||
|
||||
HasMapQueryWhere _where;
|
||||
|
||||
@override
|
||||
get casts {
|
||||
return {};
|
||||
}
|
||||
|
||||
@override
|
||||
get tableName {
|
||||
return 'has_maps';
|
||||
}
|
||||
|
||||
@override
|
||||
get fields {
|
||||
return const ['value', 'list'];
|
||||
}
|
||||
|
||||
@override
|
||||
HasMapQueryWhere get where {
|
||||
return _where;
|
||||
}
|
||||
|
||||
@override
|
||||
HasMapQueryWhere newWhereClause() {
|
||||
return HasMapQueryWhere(this);
|
||||
}
|
||||
|
||||
static HasMap parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
var model = HasMap(
|
||||
value: (row[0] as Map<dynamic, dynamic>),
|
||||
list: (row[1] as List<dynamic>));
|
||||
return model;
|
||||
}
|
||||
|
||||
@override
|
||||
deserialize(List row) {
|
||||
return parseRow(row);
|
||||
}
|
||||
}
|
||||
|
||||
class HasMapQueryWhere extends QueryWhere {
|
||||
HasMapQueryWhere(HasMapQuery query)
|
||||
: value = MapSqlExpressionBuilder(query, 'value'),
|
||||
list = ListSqlExpressionBuilder(query, 'list');
|
||||
|
||||
final MapSqlExpressionBuilder value;
|
||||
|
||||
final ListSqlExpressionBuilder list;
|
||||
|
||||
@override
|
||||
get expressionBuilders {
|
||||
return [value, list];
|
||||
}
|
||||
}
|
||||
|
||||
class HasMapQueryValues extends MapQueryValues {
|
||||
@override
|
||||
get casts {
|
||||
return {'list': 'jsonb'};
|
||||
}
|
||||
|
||||
Map<dynamic, dynamic> get value {
|
||||
return (values['value'] as Map<dynamic, dynamic>);
|
||||
}
|
||||
|
||||
set value(Map<dynamic, dynamic> value) => values['value'] = value;
|
||||
List<dynamic> get list {
|
||||
return (json.decode((values['list'] as String)) as List);
|
||||
}
|
||||
|
||||
set list(List<dynamic> value) => values['list'] = json.encode(value);
|
||||
void copyFrom(HasMap model) {
|
||||
value = model.value;
|
||||
list = model.list;
|
||||
}
|
||||
}
|
||||
|
||||
// **************************************************************************
|
||||
// JsonModelGenerator
|
||||
// **************************************************************************
|
||||
|
||||
@generatedSerializable
|
||||
class HasMap implements _HasMap {
|
||||
const HasMap({this.value, this.list});
|
||||
|
||||
@override
|
||||
final Map<dynamic, dynamic> value;
|
||||
|
||||
@override
|
||||
final List<dynamic> list;
|
||||
|
||||
HasMap copyWith({Map<dynamic, dynamic> value, List<dynamic> list}) {
|
||||
return HasMap(value: value ?? this.value, list: list ?? this.list);
|
||||
}
|
||||
|
||||
bool operator ==(other) {
|
||||
return other is _HasMap &&
|
||||
MapEquality<dynamic, dynamic>(
|
||||
keys: DefaultEquality(), values: DefaultEquality())
|
||||
.equals(other.value, value) &&
|
||||
ListEquality<dynamic>(DefaultEquality()).equals(other.list, list);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return hashObjects([value, list]);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return "HasMap(value=$value, list=$list)";
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return HasMapSerializer.toMap(this);
|
||||
}
|
||||
}
|
||||
|
||||
// **************************************************************************
|
||||
// SerializerGenerator
|
||||
// **************************************************************************
|
||||
|
||||
const HasMapSerializer hasMapSerializer = HasMapSerializer();
|
||||
|
||||
class HasMapEncoder extends Converter<HasMap, Map> {
|
||||
const HasMapEncoder();
|
||||
|
||||
@override
|
||||
Map convert(HasMap model) => HasMapSerializer.toMap(model);
|
||||
}
|
||||
|
||||
class HasMapDecoder extends Converter<Map, HasMap> {
|
||||
const HasMapDecoder();
|
||||
|
||||
@override
|
||||
HasMap convert(Map map) => HasMapSerializer.fromMap(map);
|
||||
}
|
||||
|
||||
class HasMapSerializer extends Codec<HasMap, Map> {
|
||||
const HasMapSerializer();
|
||||
|
||||
@override
|
||||
get encoder => const HasMapEncoder();
|
||||
@override
|
||||
get decoder => const HasMapDecoder();
|
||||
static HasMap fromMap(Map map) {
|
||||
return HasMap(
|
||||
value: map['value'] is Map
|
||||
? (map['value'] as Map).cast<dynamic, dynamic>()
|
||||
: null,
|
||||
list: map['list'] is Iterable
|
||||
? (map['list'] as Iterable).cast<dynamic>().toList()
|
||||
: null);
|
||||
}
|
||||
|
||||
static Map<String, dynamic> toMap(_HasMap model) {
|
||||
if (model == null) {
|
||||
return null;
|
||||
}
|
||||
return {'value': model.value, 'list': model.list};
|
||||
}
|
||||
}
|
||||
|
||||
abstract class HasMapFields {
|
||||
static const List<String> allFields = <String>[value, list];
|
||||
|
||||
static const String value = 'value';
|
||||
|
||||
static const String list = 'list';
|
||||
}
|
568
angel_orm_test/lib/src/models/leg.g.dart
Normal file
568
angel_orm_test/lib/src/models/leg.g.dart
Normal file
|
@ -0,0 +1,568 @@
|
|||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of angel_orm_generator.test.models.leg;
|
||||
|
||||
// **************************************************************************
|
||||
// MigrationGenerator
|
||||
// **************************************************************************
|
||||
|
||||
class LegMigration extends Migration {
|
||||
@override
|
||||
up(Schema schema) {
|
||||
schema.create('legs', (table) {
|
||||
table.serial('id')..primaryKey();
|
||||
table.timeStamp('created_at');
|
||||
table.timeStamp('updated_at');
|
||||
table.varChar('name');
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
down(Schema schema) {
|
||||
schema.drop('legs', cascade: true);
|
||||
}
|
||||
}
|
||||
|
||||
class FootMigration extends Migration {
|
||||
@override
|
||||
up(Schema schema) {
|
||||
schema.create('feet', (table) {
|
||||
table.serial('id')..primaryKey();
|
||||
table.timeStamp('created_at');
|
||||
table.timeStamp('updated_at');
|
||||
table.integer('leg_id');
|
||||
table.declare('n_toes', ColumnType('decimal'));
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
down(Schema schema) {
|
||||
schema.drop('feet');
|
||||
}
|
||||
}
|
||||
|
||||
// **************************************************************************
|
||||
// OrmGenerator
|
||||
// **************************************************************************
|
||||
|
||||
class LegQuery extends Query<Leg, LegQueryWhere> {
|
||||
LegQuery({Query parent, Set<String> trampoline}) : super(parent: parent) {
|
||||
trampoline ??= Set();
|
||||
trampoline.add(tableName);
|
||||
_where = LegQueryWhere(this);
|
||||
leftJoin(
|
||||
_foot = FootQuery(trampoline: trampoline, parent: this), 'id', 'leg_id',
|
||||
additionalFields: const [
|
||||
'id',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'leg_id',
|
||||
'n_toes'
|
||||
],
|
||||
trampoline: trampoline);
|
||||
}
|
||||
|
||||
@override
|
||||
final LegQueryValues values = LegQueryValues();
|
||||
|
||||
LegQueryWhere _where;
|
||||
|
||||
FootQuery _foot;
|
||||
|
||||
@override
|
||||
get casts {
|
||||
return {};
|
||||
}
|
||||
|
||||
@override
|
||||
get tableName {
|
||||
return 'legs';
|
||||
}
|
||||
|
||||
@override
|
||||
get fields {
|
||||
return const ['id', 'created_at', 'updated_at', 'name'];
|
||||
}
|
||||
|
||||
@override
|
||||
LegQueryWhere get where {
|
||||
return _where;
|
||||
}
|
||||
|
||||
@override
|
||||
LegQueryWhere newWhereClause() {
|
||||
return LegQueryWhere(this);
|
||||
}
|
||||
|
||||
static Leg parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
var model = Leg(
|
||||
id: row[0].toString(),
|
||||
createdAt: (row[1] as DateTime),
|
||||
updatedAt: (row[2] as DateTime),
|
||||
name: (row[3] as String));
|
||||
if (row.length > 4) {
|
||||
model = model.copyWith(
|
||||
foot: FootQuery.parseRow(row.skip(4).take(5).toList()));
|
||||
}
|
||||
return model;
|
||||
}
|
||||
|
||||
@override
|
||||
deserialize(List row) {
|
||||
return parseRow(row);
|
||||
}
|
||||
|
||||
FootQuery get foot {
|
||||
return _foot;
|
||||
}
|
||||
}
|
||||
|
||||
class LegQueryWhere extends QueryWhere {
|
||||
LegQueryWhere(LegQuery query)
|
||||
: id = NumericSqlExpressionBuilder<int>(query, 'id'),
|
||||
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
|
||||
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'),
|
||||
name = StringSqlExpressionBuilder(query, 'name');
|
||||
|
||||
final NumericSqlExpressionBuilder<int> id;
|
||||
|
||||
final DateTimeSqlExpressionBuilder createdAt;
|
||||
|
||||
final DateTimeSqlExpressionBuilder updatedAt;
|
||||
|
||||
final StringSqlExpressionBuilder name;
|
||||
|
||||
@override
|
||||
get expressionBuilders {
|
||||
return [id, createdAt, updatedAt, name];
|
||||
}
|
||||
}
|
||||
|
||||
class LegQueryValues extends MapQueryValues {
|
||||
@override
|
||||
get casts {
|
||||
return {};
|
||||
}
|
||||
|
||||
String get id {
|
||||
return (values['id'] as String);
|
||||
}
|
||||
|
||||
set id(String value) => values['id'] = value;
|
||||
DateTime get createdAt {
|
||||
return (values['created_at'] as DateTime);
|
||||
}
|
||||
|
||||
set createdAt(DateTime value) => values['created_at'] = value;
|
||||
DateTime get updatedAt {
|
||||
return (values['updated_at'] as DateTime);
|
||||
}
|
||||
|
||||
set updatedAt(DateTime value) => values['updated_at'] = value;
|
||||
String get name {
|
||||
return (values['name'] as String);
|
||||
}
|
||||
|
||||
set name(String value) => values['name'] = value;
|
||||
void copyFrom(Leg model) {
|
||||
createdAt = model.createdAt;
|
||||
updatedAt = model.updatedAt;
|
||||
name = model.name;
|
||||
}
|
||||
}
|
||||
|
||||
class FootQuery extends Query<Foot, FootQueryWhere> {
|
||||
FootQuery({Query parent, Set<String> trampoline}) : super(parent: parent) {
|
||||
trampoline ??= Set();
|
||||
trampoline.add(tableName);
|
||||
_where = FootQueryWhere(this);
|
||||
}
|
||||
|
||||
@override
|
||||
final FootQueryValues values = FootQueryValues();
|
||||
|
||||
FootQueryWhere _where;
|
||||
|
||||
@override
|
||||
get casts {
|
||||
return {'n_toes': 'text'};
|
||||
}
|
||||
|
||||
@override
|
||||
get tableName {
|
||||
return 'feet';
|
||||
}
|
||||
|
||||
@override
|
||||
get fields {
|
||||
return const ['id', 'created_at', 'updated_at', 'leg_id', 'n_toes'];
|
||||
}
|
||||
|
||||
@override
|
||||
FootQueryWhere get where {
|
||||
return _where;
|
||||
}
|
||||
|
||||
@override
|
||||
FootQueryWhere newWhereClause() {
|
||||
return FootQueryWhere(this);
|
||||
}
|
||||
|
||||
static Foot parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
var model = Foot(
|
||||
id: row[0].toString(),
|
||||
createdAt: (row[1] as DateTime),
|
||||
updatedAt: (row[2] as DateTime),
|
||||
legId: (row[3] as int),
|
||||
nToes: double.tryParse(row[4].toString()));
|
||||
return model;
|
||||
}
|
||||
|
||||
@override
|
||||
deserialize(List row) {
|
||||
return parseRow(row);
|
||||
}
|
||||
}
|
||||
|
||||
class FootQueryWhere extends QueryWhere {
|
||||
FootQueryWhere(FootQuery query)
|
||||
: id = NumericSqlExpressionBuilder<int>(query, 'id'),
|
||||
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
|
||||
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'),
|
||||
legId = NumericSqlExpressionBuilder<int>(query, 'leg_id'),
|
||||
nToes = NumericSqlExpressionBuilder<double>(query, 'n_toes');
|
||||
|
||||
final NumericSqlExpressionBuilder<int> id;
|
||||
|
||||
final DateTimeSqlExpressionBuilder createdAt;
|
||||
|
||||
final DateTimeSqlExpressionBuilder updatedAt;
|
||||
|
||||
final NumericSqlExpressionBuilder<int> legId;
|
||||
|
||||
final NumericSqlExpressionBuilder<double> nToes;
|
||||
|
||||
@override
|
||||
get expressionBuilders {
|
||||
return [id, createdAt, updatedAt, legId, nToes];
|
||||
}
|
||||
}
|
||||
|
||||
class FootQueryValues extends MapQueryValues {
|
||||
@override
|
||||
get casts {
|
||||
return {'n_toes': 'decimal'};
|
||||
}
|
||||
|
||||
String get id {
|
||||
return (values['id'] as String);
|
||||
}
|
||||
|
||||
set id(String value) => values['id'] = value;
|
||||
DateTime get createdAt {
|
||||
return (values['created_at'] as DateTime);
|
||||
}
|
||||
|
||||
set createdAt(DateTime value) => values['created_at'] = value;
|
||||
DateTime get updatedAt {
|
||||
return (values['updated_at'] as DateTime);
|
||||
}
|
||||
|
||||
set updatedAt(DateTime value) => values['updated_at'] = value;
|
||||
int get legId {
|
||||
return (values['leg_id'] as int);
|
||||
}
|
||||
|
||||
set legId(int value) => values['leg_id'] = value;
|
||||
double get nToes {
|
||||
return double.tryParse((values['n_toes'] as String));
|
||||
}
|
||||
|
||||
set nToes(double value) => values['n_toes'] = value.toString();
|
||||
void copyFrom(Foot model) {
|
||||
createdAt = model.createdAt;
|
||||
updatedAt = model.updatedAt;
|
||||
legId = model.legId;
|
||||
nToes = model.nToes;
|
||||
}
|
||||
}
|
||||
|
||||
// **************************************************************************
|
||||
// JsonModelGenerator
|
||||
// **************************************************************************
|
||||
|
||||
@generatedSerializable
|
||||
class Leg extends _Leg {
|
||||
Leg({this.id, this.createdAt, this.updatedAt, this.foot, this.name});
|
||||
|
||||
/// A unique identifier corresponding to this item.
|
||||
@override
|
||||
String id;
|
||||
|
||||
/// The time at which this item was created.
|
||||
@override
|
||||
DateTime createdAt;
|
||||
|
||||
/// The last time at which this item was updated.
|
||||
@override
|
||||
DateTime updatedAt;
|
||||
|
||||
@override
|
||||
_Foot foot;
|
||||
|
||||
@override
|
||||
String name;
|
||||
|
||||
Leg copyWith(
|
||||
{String id,
|
||||
DateTime createdAt,
|
||||
DateTime updatedAt,
|
||||
_Foot foot,
|
||||
String name}) {
|
||||
return Leg(
|
||||
id: id ?? this.id,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
updatedAt: updatedAt ?? this.updatedAt,
|
||||
foot: foot ?? this.foot,
|
||||
name: name ?? this.name);
|
||||
}
|
||||
|
||||
bool operator ==(other) {
|
||||
return other is _Leg &&
|
||||
other.id == id &&
|
||||
other.createdAt == createdAt &&
|
||||
other.updatedAt == updatedAt &&
|
||||
other.foot == foot &&
|
||||
other.name == name;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return hashObjects([id, createdAt, updatedAt, foot, name]);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return "Leg(id=$id, createdAt=$createdAt, updatedAt=$updatedAt, foot=$foot, name=$name)";
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return LegSerializer.toMap(this);
|
||||
}
|
||||
}
|
||||
|
||||
@generatedSerializable
|
||||
class Foot extends _Foot {
|
||||
Foot({this.id, this.createdAt, this.updatedAt, this.legId, this.nToes});
|
||||
|
||||
/// A unique identifier corresponding to this item.
|
||||
@override
|
||||
String id;
|
||||
|
||||
/// The time at which this item was created.
|
||||
@override
|
||||
DateTime createdAt;
|
||||
|
||||
/// The last time at which this item was updated.
|
||||
@override
|
||||
DateTime updatedAt;
|
||||
|
||||
@override
|
||||
int legId;
|
||||
|
||||
@override
|
||||
double nToes;
|
||||
|
||||
Foot copyWith(
|
||||
{String id,
|
||||
DateTime createdAt,
|
||||
DateTime updatedAt,
|
||||
int legId,
|
||||
double nToes}) {
|
||||
return Foot(
|
||||
id: id ?? this.id,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
updatedAt: updatedAt ?? this.updatedAt,
|
||||
legId: legId ?? this.legId,
|
||||
nToes: nToes ?? this.nToes);
|
||||
}
|
||||
|
||||
bool operator ==(other) {
|
||||
return other is _Foot &&
|
||||
other.id == id &&
|
||||
other.createdAt == createdAt &&
|
||||
other.updatedAt == updatedAt &&
|
||||
other.legId == legId &&
|
||||
other.nToes == nToes;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return hashObjects([id, createdAt, updatedAt, legId, nToes]);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return "Foot(id=$id, createdAt=$createdAt, updatedAt=$updatedAt, legId=$legId, nToes=$nToes)";
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return FootSerializer.toMap(this);
|
||||
}
|
||||
}
|
||||
|
||||
// **************************************************************************
|
||||
// SerializerGenerator
|
||||
// **************************************************************************
|
||||
|
||||
const LegSerializer legSerializer = LegSerializer();
|
||||
|
||||
class LegEncoder extends Converter<Leg, Map> {
|
||||
const LegEncoder();
|
||||
|
||||
@override
|
||||
Map convert(Leg model) => LegSerializer.toMap(model);
|
||||
}
|
||||
|
||||
class LegDecoder extends Converter<Map, Leg> {
|
||||
const LegDecoder();
|
||||
|
||||
@override
|
||||
Leg convert(Map map) => LegSerializer.fromMap(map);
|
||||
}
|
||||
|
||||
class LegSerializer extends Codec<Leg, Map> {
|
||||
const LegSerializer();
|
||||
|
||||
@override
|
||||
get encoder => const LegEncoder();
|
||||
@override
|
||||
get decoder => const LegDecoder();
|
||||
static Leg fromMap(Map map) {
|
||||
return Leg(
|
||||
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,
|
||||
foot: map['foot'] != null
|
||||
? FootSerializer.fromMap(map['foot'] as Map)
|
||||
: null,
|
||||
name: map['name'] as String);
|
||||
}
|
||||
|
||||
static Map<String, dynamic> toMap(_Leg model) {
|
||||
if (model == null) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
'id': model.id,
|
||||
'created_at': model.createdAt?.toIso8601String(),
|
||||
'updated_at': model.updatedAt?.toIso8601String(),
|
||||
'foot': FootSerializer.toMap(model.foot),
|
||||
'name': model.name
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
abstract class LegFields {
|
||||
static const List<String> allFields = <String>[
|
||||
id,
|
||||
createdAt,
|
||||
updatedAt,
|
||||
foot,
|
||||
name
|
||||
];
|
||||
|
||||
static const String id = 'id';
|
||||
|
||||
static const String createdAt = 'created_at';
|
||||
|
||||
static const String updatedAt = 'updated_at';
|
||||
|
||||
static const String foot = 'foot';
|
||||
|
||||
static const String name = 'name';
|
||||
}
|
||||
|
||||
const FootSerializer footSerializer = FootSerializer();
|
||||
|
||||
class FootEncoder extends Converter<Foot, Map> {
|
||||
const FootEncoder();
|
||||
|
||||
@override
|
||||
Map convert(Foot model) => FootSerializer.toMap(model);
|
||||
}
|
||||
|
||||
class FootDecoder extends Converter<Map, Foot> {
|
||||
const FootDecoder();
|
||||
|
||||
@override
|
||||
Foot convert(Map map) => FootSerializer.fromMap(map);
|
||||
}
|
||||
|
||||
class FootSerializer extends Codec<Foot, Map> {
|
||||
const FootSerializer();
|
||||
|
||||
@override
|
||||
get encoder => const FootEncoder();
|
||||
@override
|
||||
get decoder => const FootDecoder();
|
||||
static Foot fromMap(Map map) {
|
||||
return Foot(
|
||||
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,
|
||||
legId: map['leg_id'] as int,
|
||||
nToes: map['n_toes'] as double);
|
||||
}
|
||||
|
||||
static Map<String, dynamic> toMap(_Foot model) {
|
||||
if (model == null) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
'id': model.id,
|
||||
'created_at': model.createdAt?.toIso8601String(),
|
||||
'updated_at': model.updatedAt?.toIso8601String(),
|
||||
'leg_id': model.legId,
|
||||
'n_toes': model.nToes
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
abstract class FootFields {
|
||||
static const List<String> allFields = <String>[
|
||||
id,
|
||||
createdAt,
|
||||
updatedAt,
|
||||
legId,
|
||||
nToes
|
||||
];
|
||||
|
||||
static const String id = 'id';
|
||||
|
||||
static const String createdAt = 'created_at';
|
||||
|
||||
static const String updatedAt = 'updated_at';
|
||||
|
||||
static const String legId = 'leg_id';
|
||||
|
||||
static const String nToes = 'n_toes';
|
||||
}
|
598
angel_orm_test/lib/src/models/order.g.dart
Normal file
598
angel_orm_test/lib/src/models/order.g.dart
Normal file
|
@ -0,0 +1,598 @@
|
|||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of angel_orm_generator.test.models.order;
|
||||
|
||||
// **************************************************************************
|
||||
// MigrationGenerator
|
||||
// **************************************************************************
|
||||
|
||||
class OrderMigration extends Migration {
|
||||
@override
|
||||
up(Schema schema) {
|
||||
schema.create('orders', (table) {
|
||||
table.serial('id')..primaryKey();
|
||||
table.timeStamp('created_at');
|
||||
table.timeStamp('updated_at');
|
||||
table.integer('employee_id');
|
||||
table.timeStamp('order_date');
|
||||
table.integer('shipper_id');
|
||||
table
|
||||
.declare('customer_id', ColumnType('serial'))
|
||||
.references('customers', 'id');
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
down(Schema schema) {
|
||||
schema.drop('orders');
|
||||
}
|
||||
}
|
||||
|
||||
class CustomerMigration extends Migration {
|
||||
@override
|
||||
up(Schema schema) {
|
||||
schema.create('customers', (table) {
|
||||
table.serial('id')..primaryKey();
|
||||
table.timeStamp('created_at');
|
||||
table.timeStamp('updated_at');
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
down(Schema schema) {
|
||||
schema.drop('customers');
|
||||
}
|
||||
}
|
||||
|
||||
// **************************************************************************
|
||||
// OrmGenerator
|
||||
// **************************************************************************
|
||||
|
||||
class OrderQuery extends Query<Order, OrderQueryWhere> {
|
||||
OrderQuery({Query parent, Set<String> trampoline}) : super(parent: parent) {
|
||||
trampoline ??= Set();
|
||||
trampoline.add(tableName);
|
||||
_where = OrderQueryWhere(this);
|
||||
leftJoin(_customer = CustomerQuery(trampoline: trampoline, parent: this),
|
||||
'customer_id', 'id',
|
||||
additionalFields: const ['id', 'created_at', 'updated_at'],
|
||||
trampoline: trampoline);
|
||||
}
|
||||
|
||||
@override
|
||||
final OrderQueryValues values = OrderQueryValues();
|
||||
|
||||
OrderQueryWhere _where;
|
||||
|
||||
CustomerQuery _customer;
|
||||
|
||||
@override
|
||||
get casts {
|
||||
return {};
|
||||
}
|
||||
|
||||
@override
|
||||
get tableName {
|
||||
return 'orders';
|
||||
}
|
||||
|
||||
@override
|
||||
get fields {
|
||||
return const [
|
||||
'id',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'customer_id',
|
||||
'employee_id',
|
||||
'order_date',
|
||||
'shipper_id'
|
||||
];
|
||||
}
|
||||
|
||||
@override
|
||||
OrderQueryWhere get where {
|
||||
return _where;
|
||||
}
|
||||
|
||||
@override
|
||||
OrderQueryWhere newWhereClause() {
|
||||
return OrderQueryWhere(this);
|
||||
}
|
||||
|
||||
static Order parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
var model = Order(
|
||||
id: row[0].toString(),
|
||||
createdAt: (row[1] as DateTime),
|
||||
updatedAt: (row[2] as DateTime),
|
||||
employeeId: (row[4] as int),
|
||||
orderDate: (row[5] as DateTime),
|
||||
shipperId: (row[6] as int));
|
||||
if (row.length > 7) {
|
||||
model = model.copyWith(
|
||||
customer: CustomerQuery.parseRow(row.skip(7).take(3).toList()));
|
||||
}
|
||||
return model;
|
||||
}
|
||||
|
||||
@override
|
||||
deserialize(List row) {
|
||||
return parseRow(row);
|
||||
}
|
||||
|
||||
CustomerQuery get customer {
|
||||
return _customer;
|
||||
}
|
||||
}
|
||||
|
||||
class OrderQueryWhere extends QueryWhere {
|
||||
OrderQueryWhere(OrderQuery query)
|
||||
: id = NumericSqlExpressionBuilder<int>(query, 'id'),
|
||||
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
|
||||
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'),
|
||||
customerId = NumericSqlExpressionBuilder<int>(query, 'customer_id'),
|
||||
employeeId = NumericSqlExpressionBuilder<int>(query, 'employee_id'),
|
||||
orderDate = DateTimeSqlExpressionBuilder(query, 'order_date'),
|
||||
shipperId = NumericSqlExpressionBuilder<int>(query, 'shipper_id');
|
||||
|
||||
final NumericSqlExpressionBuilder<int> id;
|
||||
|
||||
final DateTimeSqlExpressionBuilder createdAt;
|
||||
|
||||
final DateTimeSqlExpressionBuilder updatedAt;
|
||||
|
||||
final NumericSqlExpressionBuilder<int> customerId;
|
||||
|
||||
final NumericSqlExpressionBuilder<int> employeeId;
|
||||
|
||||
final DateTimeSqlExpressionBuilder orderDate;
|
||||
|
||||
final NumericSqlExpressionBuilder<int> shipperId;
|
||||
|
||||
@override
|
||||
get expressionBuilders {
|
||||
return [
|
||||
id,
|
||||
createdAt,
|
||||
updatedAt,
|
||||
customerId,
|
||||
employeeId,
|
||||
orderDate,
|
||||
shipperId
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
class OrderQueryValues extends MapQueryValues {
|
||||
@override
|
||||
get casts {
|
||||
return {};
|
||||
}
|
||||
|
||||
String get id {
|
||||
return (values['id'] as String);
|
||||
}
|
||||
|
||||
set id(String value) => values['id'] = value;
|
||||
DateTime get createdAt {
|
||||
return (values['created_at'] as DateTime);
|
||||
}
|
||||
|
||||
set createdAt(DateTime value) => values['created_at'] = value;
|
||||
DateTime get updatedAt {
|
||||
return (values['updated_at'] as DateTime);
|
||||
}
|
||||
|
||||
set updatedAt(DateTime value) => values['updated_at'] = value;
|
||||
int get customerId {
|
||||
return (values['customer_id'] as int);
|
||||
}
|
||||
|
||||
set customerId(int value) => values['customer_id'] = value;
|
||||
int get employeeId {
|
||||
return (values['employee_id'] as int);
|
||||
}
|
||||
|
||||
set employeeId(int value) => values['employee_id'] = value;
|
||||
DateTime get orderDate {
|
||||
return (values['order_date'] as DateTime);
|
||||
}
|
||||
|
||||
set orderDate(DateTime value) => values['order_date'] = value;
|
||||
int get shipperId {
|
||||
return (values['shipper_id'] as int);
|
||||
}
|
||||
|
||||
set shipperId(int value) => values['shipper_id'] = value;
|
||||
void copyFrom(Order model) {
|
||||
createdAt = model.createdAt;
|
||||
updatedAt = model.updatedAt;
|
||||
employeeId = model.employeeId;
|
||||
orderDate = model.orderDate;
|
||||
shipperId = model.shipperId;
|
||||
if (model.customer != null) {
|
||||
values['customer_id'] = model.customer.id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class CustomerQuery extends Query<Customer, CustomerQueryWhere> {
|
||||
CustomerQuery({Query parent, Set<String> trampoline})
|
||||
: super(parent: parent) {
|
||||
trampoline ??= Set();
|
||||
trampoline.add(tableName);
|
||||
_where = CustomerQueryWhere(this);
|
||||
}
|
||||
|
||||
@override
|
||||
final CustomerQueryValues values = CustomerQueryValues();
|
||||
|
||||
CustomerQueryWhere _where;
|
||||
|
||||
@override
|
||||
get casts {
|
||||
return {};
|
||||
}
|
||||
|
||||
@override
|
||||
get tableName {
|
||||
return 'customers';
|
||||
}
|
||||
|
||||
@override
|
||||
get fields {
|
||||
return const ['id', 'created_at', 'updated_at'];
|
||||
}
|
||||
|
||||
@override
|
||||
CustomerQueryWhere get where {
|
||||
return _where;
|
||||
}
|
||||
|
||||
@override
|
||||
CustomerQueryWhere newWhereClause() {
|
||||
return CustomerQueryWhere(this);
|
||||
}
|
||||
|
||||
static Customer parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
var model = Customer(
|
||||
id: row[0].toString(),
|
||||
createdAt: (row[1] as DateTime),
|
||||
updatedAt: (row[2] as DateTime));
|
||||
return model;
|
||||
}
|
||||
|
||||
@override
|
||||
deserialize(List row) {
|
||||
return parseRow(row);
|
||||
}
|
||||
}
|
||||
|
||||
class CustomerQueryWhere extends QueryWhere {
|
||||
CustomerQueryWhere(CustomerQuery query)
|
||||
: id = NumericSqlExpressionBuilder<int>(query, 'id'),
|
||||
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
|
||||
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at');
|
||||
|
||||
final NumericSqlExpressionBuilder<int> id;
|
||||
|
||||
final DateTimeSqlExpressionBuilder createdAt;
|
||||
|
||||
final DateTimeSqlExpressionBuilder updatedAt;
|
||||
|
||||
@override
|
||||
get expressionBuilders {
|
||||
return [id, createdAt, updatedAt];
|
||||
}
|
||||
}
|
||||
|
||||
class CustomerQueryValues extends MapQueryValues {
|
||||
@override
|
||||
get casts {
|
||||
return {};
|
||||
}
|
||||
|
||||
String get id {
|
||||
return (values['id'] as String);
|
||||
}
|
||||
|
||||
set id(String value) => values['id'] = value;
|
||||
DateTime get createdAt {
|
||||
return (values['created_at'] as DateTime);
|
||||
}
|
||||
|
||||
set createdAt(DateTime value) => values['created_at'] = value;
|
||||
DateTime get updatedAt {
|
||||
return (values['updated_at'] as DateTime);
|
||||
}
|
||||
|
||||
set updatedAt(DateTime value) => values['updated_at'] = value;
|
||||
void copyFrom(Customer model) {
|
||||
createdAt = model.createdAt;
|
||||
updatedAt = model.updatedAt;
|
||||
}
|
||||
}
|
||||
|
||||
// **************************************************************************
|
||||
// JsonModelGenerator
|
||||
// **************************************************************************
|
||||
|
||||
@generatedSerializable
|
||||
class Order extends _Order {
|
||||
Order(
|
||||
{this.id,
|
||||
this.createdAt,
|
||||
this.updatedAt,
|
||||
this.customer,
|
||||
this.employeeId,
|
||||
this.orderDate,
|
||||
this.shipperId});
|
||||
|
||||
/// A unique identifier corresponding to this item.
|
||||
@override
|
||||
String id;
|
||||
|
||||
/// The time at which this item was created.
|
||||
@override
|
||||
DateTime createdAt;
|
||||
|
||||
/// The last time at which this item was updated.
|
||||
@override
|
||||
DateTime updatedAt;
|
||||
|
||||
@override
|
||||
final _Customer customer;
|
||||
|
||||
@override
|
||||
final int employeeId;
|
||||
|
||||
@override
|
||||
final DateTime orderDate;
|
||||
|
||||
@override
|
||||
final int shipperId;
|
||||
|
||||
Order copyWith(
|
||||
{String id,
|
||||
DateTime createdAt,
|
||||
DateTime updatedAt,
|
||||
_Customer customer,
|
||||
int employeeId,
|
||||
DateTime orderDate,
|
||||
int shipperId}) {
|
||||
return Order(
|
||||
id: id ?? this.id,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
updatedAt: updatedAt ?? this.updatedAt,
|
||||
customer: customer ?? this.customer,
|
||||
employeeId: employeeId ?? this.employeeId,
|
||||
orderDate: orderDate ?? this.orderDate,
|
||||
shipperId: shipperId ?? this.shipperId);
|
||||
}
|
||||
|
||||
bool operator ==(other) {
|
||||
return other is _Order &&
|
||||
other.id == id &&
|
||||
other.createdAt == createdAt &&
|
||||
other.updatedAt == updatedAt &&
|
||||
other.customer == customer &&
|
||||
other.employeeId == employeeId &&
|
||||
other.orderDate == orderDate &&
|
||||
other.shipperId == shipperId;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return hashObjects(
|
||||
[id, createdAt, updatedAt, customer, employeeId, orderDate, shipperId]);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return "Order(id=$id, createdAt=$createdAt, updatedAt=$updatedAt, customer=$customer, employeeId=$employeeId, orderDate=$orderDate, shipperId=$shipperId)";
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return OrderSerializer.toMap(this);
|
||||
}
|
||||
}
|
||||
|
||||
@generatedSerializable
|
||||
class Customer extends _Customer {
|
||||
Customer({this.id, this.createdAt, this.updatedAt});
|
||||
|
||||
/// A unique identifier corresponding to this item.
|
||||
@override
|
||||
String id;
|
||||
|
||||
/// The time at which this item was created.
|
||||
@override
|
||||
DateTime createdAt;
|
||||
|
||||
/// The last time at which this item was updated.
|
||||
@override
|
||||
DateTime updatedAt;
|
||||
|
||||
Customer copyWith({String id, DateTime createdAt, DateTime updatedAt}) {
|
||||
return 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;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return hashObjects([id, createdAt, updatedAt]);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return "Customer(id=$id, createdAt=$createdAt, updatedAt=$updatedAt)";
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return CustomerSerializer.toMap(this);
|
||||
}
|
||||
}
|
||||
|
||||
// **************************************************************************
|
||||
// SerializerGenerator
|
||||
// **************************************************************************
|
||||
|
||||
const OrderSerializer orderSerializer = OrderSerializer();
|
||||
|
||||
class OrderEncoder extends Converter<Order, Map> {
|
||||
const OrderEncoder();
|
||||
|
||||
@override
|
||||
Map convert(Order model) => OrderSerializer.toMap(model);
|
||||
}
|
||||
|
||||
class OrderDecoder extends Converter<Map, Order> {
|
||||
const OrderDecoder();
|
||||
|
||||
@override
|
||||
Order convert(Map map) => OrderSerializer.fromMap(map);
|
||||
}
|
||||
|
||||
class OrderSerializer extends Codec<Order, Map> {
|
||||
const OrderSerializer();
|
||||
|
||||
@override
|
||||
get encoder => const OrderEncoder();
|
||||
@override
|
||||
get decoder => const OrderDecoder();
|
||||
static Order fromMap(Map map) {
|
||||
return Order(
|
||||
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,
|
||||
customer: map['customer'] != null
|
||||
? CustomerSerializer.fromMap(map['customer'] as Map)
|
||||
: null,
|
||||
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);
|
||||
}
|
||||
|
||||
static Map<String, dynamic> toMap(_Order model) {
|
||||
if (model == null) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
'id': model.id,
|
||||
'created_at': model.createdAt?.toIso8601String(),
|
||||
'updated_at': model.updatedAt?.toIso8601String(),
|
||||
'customer': CustomerSerializer.toMap(model.customer),
|
||||
'employee_id': model.employeeId,
|
||||
'order_date': model.orderDate?.toIso8601String(),
|
||||
'shipper_id': model.shipperId
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
abstract class OrderFields {
|
||||
static const List<String> allFields = <String>[
|
||||
id,
|
||||
createdAt,
|
||||
updatedAt,
|
||||
customer,
|
||||
employeeId,
|
||||
orderDate,
|
||||
shipperId
|
||||
];
|
||||
|
||||
static const String id = 'id';
|
||||
|
||||
static const String createdAt = 'created_at';
|
||||
|
||||
static const String updatedAt = 'updated_at';
|
||||
|
||||
static const String customer = 'customer';
|
||||
|
||||
static const String employeeId = 'employee_id';
|
||||
|
||||
static const String orderDate = 'order_date';
|
||||
|
||||
static const String shipperId = 'shipper_id';
|
||||
}
|
||||
|
||||
const CustomerSerializer customerSerializer = CustomerSerializer();
|
||||
|
||||
class CustomerEncoder extends Converter<Customer, Map> {
|
||||
const CustomerEncoder();
|
||||
|
||||
@override
|
||||
Map convert(Customer model) => CustomerSerializer.toMap(model);
|
||||
}
|
||||
|
||||
class CustomerDecoder extends Converter<Map, Customer> {
|
||||
const CustomerDecoder();
|
||||
|
||||
@override
|
||||
Customer convert(Map map) => CustomerSerializer.fromMap(map);
|
||||
}
|
||||
|
||||
class CustomerSerializer extends Codec<Customer, Map> {
|
||||
const CustomerSerializer();
|
||||
|
||||
@override
|
||||
get encoder => const CustomerEncoder();
|
||||
@override
|
||||
get decoder => const CustomerDecoder();
|
||||
static Customer fromMap(Map map) {
|
||||
return 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 = <String>[id, createdAt, updatedAt];
|
||||
|
||||
static const String id = 'id';
|
||||
|
||||
static const String createdAt = 'created_at';
|
||||
|
||||
static const String updatedAt = 'updated_at';
|
||||
}
|
636
angel_orm_test/lib/src/models/tree.g.dart
Normal file
636
angel_orm_test/lib/src/models/tree.g.dart
Normal file
|
@ -0,0 +1,636 @@
|
|||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of angel_orm_generator.test.models.tree;
|
||||
|
||||
// **************************************************************************
|
||||
// MigrationGenerator
|
||||
// **************************************************************************
|
||||
|
||||
class TreeMigration extends Migration {
|
||||
@override
|
||||
up(Schema schema) {
|
||||
schema.create('trees', (table) {
|
||||
table.serial('id')..primaryKey();
|
||||
table.timeStamp('created_at');
|
||||
table.timeStamp('updated_at');
|
||||
table.declare('rings', ColumnType('smallint'));
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
down(Schema schema) {
|
||||
schema.drop('trees', cascade: true);
|
||||
}
|
||||
}
|
||||
|
||||
class FruitMigration extends Migration {
|
||||
@override
|
||||
up(Schema schema) {
|
||||
schema.create('fruits', (table) {
|
||||
table.serial('id')..primaryKey();
|
||||
table.timeStamp('created_at');
|
||||
table.timeStamp('updated_at');
|
||||
table.integer('tree_id');
|
||||
table.varChar('common_name');
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
down(Schema schema) {
|
||||
schema.drop('fruits');
|
||||
}
|
||||
}
|
||||
|
||||
// **************************************************************************
|
||||
// OrmGenerator
|
||||
// **************************************************************************
|
||||
|
||||
class TreeQuery extends Query<Tree, TreeQueryWhere> {
|
||||
TreeQuery({Query parent, Set<String> trampoline}) : super(parent: parent) {
|
||||
trampoline ??= Set();
|
||||
trampoline.add(tableName);
|
||||
_where = TreeQueryWhere(this);
|
||||
leftJoin(_fruits = FruitQuery(trampoline: trampoline, parent: this), 'id',
|
||||
'tree_id',
|
||||
additionalFields: const [
|
||||
'id',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'tree_id',
|
||||
'common_name'
|
||||
],
|
||||
trampoline: trampoline);
|
||||
}
|
||||
|
||||
@override
|
||||
final TreeQueryValues values = TreeQueryValues();
|
||||
|
||||
TreeQueryWhere _where;
|
||||
|
||||
FruitQuery _fruits;
|
||||
|
||||
@override
|
||||
get casts {
|
||||
return {};
|
||||
}
|
||||
|
||||
@override
|
||||
get tableName {
|
||||
return 'trees';
|
||||
}
|
||||
|
||||
@override
|
||||
get fields {
|
||||
return const ['id', 'created_at', 'updated_at', 'rings'];
|
||||
}
|
||||
|
||||
@override
|
||||
TreeQueryWhere get where {
|
||||
return _where;
|
||||
}
|
||||
|
||||
@override
|
||||
TreeQueryWhere newWhereClause() {
|
||||
return TreeQueryWhere(this);
|
||||
}
|
||||
|
||||
static Tree parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
var model = Tree(
|
||||
id: row[0].toString(),
|
||||
createdAt: (row[1] as DateTime),
|
||||
updatedAt: (row[2] as DateTime),
|
||||
rings: (row[3] as int));
|
||||
if (row.length > 4) {
|
||||
model = model.copyWith(
|
||||
fruits: [FruitQuery.parseRow(row.skip(4).take(5).toList())]
|
||||
.where((x) => x != null)
|
||||
.toList());
|
||||
}
|
||||
return model;
|
||||
}
|
||||
|
||||
@override
|
||||
deserialize(List row) {
|
||||
return parseRow(row);
|
||||
}
|
||||
|
||||
FruitQuery get fruits {
|
||||
return _fruits;
|
||||
}
|
||||
|
||||
@override
|
||||
get(QueryExecutor executor) {
|
||||
return super.get(executor).then((result) {
|
||||
return result.fold<List<Tree>>([], (out, model) {
|
||||
var idx = out.indexWhere((m) => m.id == model.id);
|
||||
|
||||
if (idx == -1) {
|
||||
return out..add(model);
|
||||
} else {
|
||||
var l = out[idx];
|
||||
return out
|
||||
..[idx] = l.copyWith(
|
||||
fruits: List<_Fruit>.from(l.fruits ?? [])
|
||||
..addAll(model.fruits ?? []));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
update(QueryExecutor executor) {
|
||||
return super.update(executor).then((result) {
|
||||
return result.fold<List<Tree>>([], (out, model) {
|
||||
var idx = out.indexWhere((m) => m.id == model.id);
|
||||
|
||||
if (idx == -1) {
|
||||
return out..add(model);
|
||||
} else {
|
||||
var l = out[idx];
|
||||
return out
|
||||
..[idx] = l.copyWith(
|
||||
fruits: List<_Fruit>.from(l.fruits ?? [])
|
||||
..addAll(model.fruits ?? []));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
delete(QueryExecutor executor) {
|
||||
return super.delete(executor).then((result) {
|
||||
return result.fold<List<Tree>>([], (out, model) {
|
||||
var idx = out.indexWhere((m) => m.id == model.id);
|
||||
|
||||
if (idx == -1) {
|
||||
return out..add(model);
|
||||
} else {
|
||||
var l = out[idx];
|
||||
return out
|
||||
..[idx] = l.copyWith(
|
||||
fruits: List<_Fruit>.from(l.fruits ?? [])
|
||||
..addAll(model.fruits ?? []));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class TreeQueryWhere extends QueryWhere {
|
||||
TreeQueryWhere(TreeQuery query)
|
||||
: id = NumericSqlExpressionBuilder<int>(query, 'id'),
|
||||
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
|
||||
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'),
|
||||
rings = NumericSqlExpressionBuilder<int>(query, 'rings');
|
||||
|
||||
final NumericSqlExpressionBuilder<int> id;
|
||||
|
||||
final DateTimeSqlExpressionBuilder createdAt;
|
||||
|
||||
final DateTimeSqlExpressionBuilder updatedAt;
|
||||
|
||||
final NumericSqlExpressionBuilder<int> rings;
|
||||
|
||||
@override
|
||||
get expressionBuilders {
|
||||
return [id, createdAt, updatedAt, rings];
|
||||
}
|
||||
}
|
||||
|
||||
class TreeQueryValues extends MapQueryValues {
|
||||
@override
|
||||
get casts {
|
||||
return {};
|
||||
}
|
||||
|
||||
String get id {
|
||||
return (values['id'] as String);
|
||||
}
|
||||
|
||||
set id(String value) => values['id'] = value;
|
||||
DateTime get createdAt {
|
||||
return (values['created_at'] as DateTime);
|
||||
}
|
||||
|
||||
set createdAt(DateTime value) => values['created_at'] = value;
|
||||
DateTime get updatedAt {
|
||||
return (values['updated_at'] as DateTime);
|
||||
}
|
||||
|
||||
set updatedAt(DateTime value) => values['updated_at'] = value;
|
||||
int get rings {
|
||||
return (values['rings'] as int);
|
||||
}
|
||||
|
||||
set rings(int value) => values['rings'] = value;
|
||||
void copyFrom(Tree model) {
|
||||
createdAt = model.createdAt;
|
||||
updatedAt = model.updatedAt;
|
||||
rings = model.rings;
|
||||
}
|
||||
}
|
||||
|
||||
class FruitQuery extends Query<Fruit, FruitQueryWhere> {
|
||||
FruitQuery({Query parent, Set<String> trampoline}) : super(parent: parent) {
|
||||
trampoline ??= Set();
|
||||
trampoline.add(tableName);
|
||||
_where = FruitQueryWhere(this);
|
||||
}
|
||||
|
||||
@override
|
||||
final FruitQueryValues values = FruitQueryValues();
|
||||
|
||||
FruitQueryWhere _where;
|
||||
|
||||
@override
|
||||
get casts {
|
||||
return {};
|
||||
}
|
||||
|
||||
@override
|
||||
get tableName {
|
||||
return 'fruits';
|
||||
}
|
||||
|
||||
@override
|
||||
get fields {
|
||||
return const ['id', 'created_at', 'updated_at', 'tree_id', 'common_name'];
|
||||
}
|
||||
|
||||
@override
|
||||
FruitQueryWhere get where {
|
||||
return _where;
|
||||
}
|
||||
|
||||
@override
|
||||
FruitQueryWhere newWhereClause() {
|
||||
return FruitQueryWhere(this);
|
||||
}
|
||||
|
||||
static Fruit parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
var model = Fruit(
|
||||
id: row[0].toString(),
|
||||
createdAt: (row[1] as DateTime),
|
||||
updatedAt: (row[2] as DateTime),
|
||||
treeId: (row[3] as int),
|
||||
commonName: (row[4] as String));
|
||||
return model;
|
||||
}
|
||||
|
||||
@override
|
||||
deserialize(List row) {
|
||||
return parseRow(row);
|
||||
}
|
||||
}
|
||||
|
||||
class FruitQueryWhere extends QueryWhere {
|
||||
FruitQueryWhere(FruitQuery query)
|
||||
: id = NumericSqlExpressionBuilder<int>(query, 'id'),
|
||||
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
|
||||
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'),
|
||||
treeId = NumericSqlExpressionBuilder<int>(query, 'tree_id'),
|
||||
commonName = StringSqlExpressionBuilder(query, 'common_name');
|
||||
|
||||
final NumericSqlExpressionBuilder<int> id;
|
||||
|
||||
final DateTimeSqlExpressionBuilder createdAt;
|
||||
|
||||
final DateTimeSqlExpressionBuilder updatedAt;
|
||||
|
||||
final NumericSqlExpressionBuilder<int> treeId;
|
||||
|
||||
final StringSqlExpressionBuilder commonName;
|
||||
|
||||
@override
|
||||
get expressionBuilders {
|
||||
return [id, createdAt, updatedAt, treeId, commonName];
|
||||
}
|
||||
}
|
||||
|
||||
class FruitQueryValues extends MapQueryValues {
|
||||
@override
|
||||
get casts {
|
||||
return {};
|
||||
}
|
||||
|
||||
String get id {
|
||||
return (values['id'] as String);
|
||||
}
|
||||
|
||||
set id(String value) => values['id'] = value;
|
||||
DateTime get createdAt {
|
||||
return (values['created_at'] as DateTime);
|
||||
}
|
||||
|
||||
set createdAt(DateTime value) => values['created_at'] = value;
|
||||
DateTime get updatedAt {
|
||||
return (values['updated_at'] as DateTime);
|
||||
}
|
||||
|
||||
set updatedAt(DateTime value) => values['updated_at'] = value;
|
||||
int get treeId {
|
||||
return (values['tree_id'] as int);
|
||||
}
|
||||
|
||||
set treeId(int value) => values['tree_id'] = value;
|
||||
String get commonName {
|
||||
return (values['common_name'] as String);
|
||||
}
|
||||
|
||||
set commonName(String value) => values['common_name'] = value;
|
||||
void copyFrom(Fruit model) {
|
||||
createdAt = model.createdAt;
|
||||
updatedAt = model.updatedAt;
|
||||
treeId = model.treeId;
|
||||
commonName = model.commonName;
|
||||
}
|
||||
}
|
||||
|
||||
// **************************************************************************
|
||||
// JsonModelGenerator
|
||||
// **************************************************************************
|
||||
|
||||
@generatedSerializable
|
||||
class Tree extends _Tree {
|
||||
Tree(
|
||||
{this.id,
|
||||
this.createdAt,
|
||||
this.updatedAt,
|
||||
this.rings,
|
||||
List<_Fruit> fruits})
|
||||
: this.fruits = List.unmodifiable(fruits ?? []);
|
||||
|
||||
/// A unique identifier corresponding to this item.
|
||||
@override
|
||||
String id;
|
||||
|
||||
/// The time at which this item was created.
|
||||
@override
|
||||
DateTime createdAt;
|
||||
|
||||
/// The last time at which this item was updated.
|
||||
@override
|
||||
DateTime updatedAt;
|
||||
|
||||
@override
|
||||
int rings;
|
||||
|
||||
@override
|
||||
List<_Fruit> fruits;
|
||||
|
||||
Tree copyWith(
|
||||
{String id,
|
||||
DateTime createdAt,
|
||||
DateTime updatedAt,
|
||||
int rings,
|
||||
List<_Fruit> fruits}) {
|
||||
return Tree(
|
||||
id: id ?? this.id,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
updatedAt: updatedAt ?? this.updatedAt,
|
||||
rings: rings ?? this.rings,
|
||||
fruits: fruits ?? this.fruits);
|
||||
}
|
||||
|
||||
bool operator ==(other) {
|
||||
return other is _Tree &&
|
||||
other.id == id &&
|
||||
other.createdAt == createdAt &&
|
||||
other.updatedAt == updatedAt &&
|
||||
other.rings == rings &&
|
||||
ListEquality<_Fruit>(DefaultEquality<_Fruit>())
|
||||
.equals(other.fruits, fruits);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return hashObjects([id, createdAt, updatedAt, rings, fruits]);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return "Tree(id=$id, createdAt=$createdAt, updatedAt=$updatedAt, rings=$rings, fruits=$fruits)";
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return TreeSerializer.toMap(this);
|
||||
}
|
||||
}
|
||||
|
||||
@generatedSerializable
|
||||
class Fruit extends _Fruit {
|
||||
Fruit(
|
||||
{this.id, this.createdAt, this.updatedAt, this.treeId, this.commonName});
|
||||
|
||||
/// A unique identifier corresponding to this item.
|
||||
@override
|
||||
String id;
|
||||
|
||||
/// The time at which this item was created.
|
||||
@override
|
||||
DateTime createdAt;
|
||||
|
||||
/// The last time at which this item was updated.
|
||||
@override
|
||||
DateTime updatedAt;
|
||||
|
||||
@override
|
||||
int treeId;
|
||||
|
||||
@override
|
||||
String commonName;
|
||||
|
||||
Fruit copyWith(
|
||||
{String id,
|
||||
DateTime createdAt,
|
||||
DateTime updatedAt,
|
||||
int treeId,
|
||||
String commonName}) {
|
||||
return Fruit(
|
||||
id: id ?? this.id,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
updatedAt: updatedAt ?? this.updatedAt,
|
||||
treeId: treeId ?? this.treeId,
|
||||
commonName: commonName ?? this.commonName);
|
||||
}
|
||||
|
||||
bool operator ==(other) {
|
||||
return other is _Fruit &&
|
||||
other.id == id &&
|
||||
other.createdAt == createdAt &&
|
||||
other.updatedAt == updatedAt &&
|
||||
other.treeId == treeId &&
|
||||
other.commonName == commonName;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return hashObjects([id, createdAt, updatedAt, treeId, commonName]);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return "Fruit(id=$id, createdAt=$createdAt, updatedAt=$updatedAt, treeId=$treeId, commonName=$commonName)";
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return FruitSerializer.toMap(this);
|
||||
}
|
||||
}
|
||||
|
||||
// **************************************************************************
|
||||
// SerializerGenerator
|
||||
// **************************************************************************
|
||||
|
||||
const TreeSerializer treeSerializer = TreeSerializer();
|
||||
|
||||
class TreeEncoder extends Converter<Tree, Map> {
|
||||
const TreeEncoder();
|
||||
|
||||
@override
|
||||
Map convert(Tree model) => TreeSerializer.toMap(model);
|
||||
}
|
||||
|
||||
class TreeDecoder extends Converter<Map, Tree> {
|
||||
const TreeDecoder();
|
||||
|
||||
@override
|
||||
Tree convert(Map map) => TreeSerializer.fromMap(map);
|
||||
}
|
||||
|
||||
class TreeSerializer extends Codec<Tree, Map> {
|
||||
const TreeSerializer();
|
||||
|
||||
@override
|
||||
get encoder => const TreeEncoder();
|
||||
@override
|
||||
get decoder => const TreeDecoder();
|
||||
static Tree fromMap(Map map) {
|
||||
return Tree(
|
||||
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,
|
||||
rings: map['rings'] as int,
|
||||
fruits: map['fruits'] is Iterable
|
||||
? List.unmodifiable(((map['fruits'] as Iterable).whereType<Map>())
|
||||
.map(FruitSerializer.fromMap))
|
||||
: null);
|
||||
}
|
||||
|
||||
static Map<String, dynamic> toMap(_Tree model) {
|
||||
if (model == null) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
'id': model.id,
|
||||
'created_at': model.createdAt?.toIso8601String(),
|
||||
'updated_at': model.updatedAt?.toIso8601String(),
|
||||
'rings': model.rings,
|
||||
'fruits': model.fruits?.map((m) => FruitSerializer.toMap(m))?.toList()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
abstract class TreeFields {
|
||||
static const List<String> allFields = <String>[
|
||||
id,
|
||||
createdAt,
|
||||
updatedAt,
|
||||
rings,
|
||||
fruits
|
||||
];
|
||||
|
||||
static const String id = 'id';
|
||||
|
||||
static const String createdAt = 'created_at';
|
||||
|
||||
static const String updatedAt = 'updated_at';
|
||||
|
||||
static const String rings = 'rings';
|
||||
|
||||
static const String fruits = 'fruits';
|
||||
}
|
||||
|
||||
const FruitSerializer fruitSerializer = FruitSerializer();
|
||||
|
||||
class FruitEncoder extends Converter<Fruit, Map> {
|
||||
const FruitEncoder();
|
||||
|
||||
@override
|
||||
Map convert(Fruit model) => FruitSerializer.toMap(model);
|
||||
}
|
||||
|
||||
class FruitDecoder extends Converter<Map, Fruit> {
|
||||
const FruitDecoder();
|
||||
|
||||
@override
|
||||
Fruit convert(Map map) => FruitSerializer.fromMap(map);
|
||||
}
|
||||
|
||||
class FruitSerializer extends Codec<Fruit, Map> {
|
||||
const FruitSerializer();
|
||||
|
||||
@override
|
||||
get encoder => const FruitEncoder();
|
||||
@override
|
||||
get decoder => const FruitDecoder();
|
||||
static Fruit fromMap(Map map) {
|
||||
return Fruit(
|
||||
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,
|
||||
treeId: map['tree_id'] as int,
|
||||
commonName: map['common_name'] as String);
|
||||
}
|
||||
|
||||
static Map<String, dynamic> toMap(_Fruit model) {
|
||||
if (model == null) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
'id': model.id,
|
||||
'created_at': model.createdAt?.toIso8601String(),
|
||||
'updated_at': model.updatedAt?.toIso8601String(),
|
||||
'tree_id': model.treeId,
|
||||
'common_name': model.commonName
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
abstract class FruitFields {
|
||||
static const List<String> allFields = <String>[
|
||||
id,
|
||||
createdAt,
|
||||
updatedAt,
|
||||
treeId,
|
||||
commonName
|
||||
];
|
||||
|
||||
static const String id = 'id';
|
||||
|
||||
static const String createdAt = 'created_at';
|
||||
|
||||
static const String updatedAt = 'updated_at';
|
||||
|
||||
static const String treeId = 'tree_id';
|
||||
|
||||
static const String commonName = 'common_name';
|
||||
}
|
1481
angel_orm_test/lib/src/models/unorthodox.g.dart
Normal file
1481
angel_orm_test/lib/src/models/unorthodox.g.dart
Normal file
File diff suppressed because it is too large
Load diff
995
angel_orm_test/lib/src/models/user.g.dart
Normal file
995
angel_orm_test/lib/src/models/user.g.dart
Normal file
|
@ -0,0 +1,995 @@
|
|||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of angel_orm_generator.test.models.user;
|
||||
|
||||
// **************************************************************************
|
||||
// MigrationGenerator
|
||||
// **************************************************************************
|
||||
|
||||
class UserMigration extends Migration {
|
||||
@override
|
||||
up(Schema schema) {
|
||||
schema.create('users', (table) {
|
||||
table.serial('id')..primaryKey();
|
||||
table.timeStamp('created_at');
|
||||
table.timeStamp('updated_at');
|
||||
table.varChar('username');
|
||||
table.varChar('password');
|
||||
table.varChar('email');
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
down(Schema schema) {
|
||||
schema.drop('users', cascade: true);
|
||||
}
|
||||
}
|
||||
|
||||
class RoleUserMigration extends Migration {
|
||||
@override
|
||||
up(Schema schema) {
|
||||
schema.create('role_users', (table) {
|
||||
table.declare('role_id', ColumnType('serial')).references('roles', 'id');
|
||||
table.declare('user_id', ColumnType('serial')).references('users', 'id');
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
down(Schema schema) {
|
||||
schema.drop('role_users');
|
||||
}
|
||||
}
|
||||
|
||||
class RoleMigration extends Migration {
|
||||
@override
|
||||
up(Schema schema) {
|
||||
schema.create('roles', (table) {
|
||||
table.serial('id')..primaryKey();
|
||||
table.timeStamp('created_at');
|
||||
table.timeStamp('updated_at');
|
||||
table.varChar('name');
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
down(Schema schema) {
|
||||
schema.drop('roles', cascade: true);
|
||||
}
|
||||
}
|
||||
|
||||
// **************************************************************************
|
||||
// OrmGenerator
|
||||
// **************************************************************************
|
||||
|
||||
class UserQuery extends Query<User, UserQueryWhere> {
|
||||
UserQuery({Query parent, Set<String> trampoline}) : super(parent: parent) {
|
||||
trampoline ??= Set();
|
||||
trampoline.add(tableName);
|
||||
_where = UserQueryWhere(this);
|
||||
leftJoin(_roles = RoleUserQuery(trampoline: trampoline, parent: this), 'id',
|
||||
'user_id',
|
||||
additionalFields: const ['id', 'created_at', 'updated_at', 'name'],
|
||||
trampoline: trampoline);
|
||||
}
|
||||
|
||||
@override
|
||||
final UserQueryValues values = UserQueryValues();
|
||||
|
||||
UserQueryWhere _where;
|
||||
|
||||
RoleUserQuery _roles;
|
||||
|
||||
@override
|
||||
get casts {
|
||||
return {};
|
||||
}
|
||||
|
||||
@override
|
||||
get tableName {
|
||||
return 'users';
|
||||
}
|
||||
|
||||
@override
|
||||
get fields {
|
||||
return const [
|
||||
'id',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'username',
|
||||
'password',
|
||||
'email'
|
||||
];
|
||||
}
|
||||
|
||||
@override
|
||||
UserQueryWhere get where {
|
||||
return _where;
|
||||
}
|
||||
|
||||
@override
|
||||
UserQueryWhere newWhereClause() {
|
||||
return UserQueryWhere(this);
|
||||
}
|
||||
|
||||
static User parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
var model = User(
|
||||
id: row[0].toString(),
|
||||
createdAt: (row[1] as DateTime),
|
||||
updatedAt: (row[2] as DateTime),
|
||||
username: (row[3] as String),
|
||||
password: (row[4] as String),
|
||||
email: (row[5] as String));
|
||||
if (row.length > 6) {
|
||||
model = model.copyWith(
|
||||
roles: [RoleQuery.parseRow(row.skip(6).take(4).toList())]
|
||||
.where((x) => x != null)
|
||||
.toList());
|
||||
}
|
||||
return model;
|
||||
}
|
||||
|
||||
@override
|
||||
deserialize(List row) {
|
||||
return parseRow(row);
|
||||
}
|
||||
|
||||
RoleUserQuery get roles {
|
||||
return _roles;
|
||||
}
|
||||
|
||||
@override
|
||||
bool canCompile(trampoline) {
|
||||
return (!(trampoline.contains('users') &&
|
||||
trampoline.contains('role_users')));
|
||||
}
|
||||
|
||||
@override
|
||||
get(QueryExecutor executor) {
|
||||
return super.get(executor).then((result) {
|
||||
return result.fold<List<User>>([], (out, model) {
|
||||
var idx = out.indexWhere((m) => m.id == model.id);
|
||||
|
||||
if (idx == -1) {
|
||||
return out..add(model);
|
||||
} else {
|
||||
var l = out[idx];
|
||||
return out
|
||||
..[idx] = l.copyWith(
|
||||
roles: List<_Role>.from(l.roles ?? [])
|
||||
..addAll(model.roles ?? []));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
update(QueryExecutor executor) {
|
||||
return super.update(executor).then((result) {
|
||||
return result.fold<List<User>>([], (out, model) {
|
||||
var idx = out.indexWhere((m) => m.id == model.id);
|
||||
|
||||
if (idx == -1) {
|
||||
return out..add(model);
|
||||
} else {
|
||||
var l = out[idx];
|
||||
return out
|
||||
..[idx] = l.copyWith(
|
||||
roles: List<_Role>.from(l.roles ?? [])
|
||||
..addAll(model.roles ?? []));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
delete(QueryExecutor executor) {
|
||||
return super.delete(executor).then((result) {
|
||||
return result.fold<List<User>>([], (out, model) {
|
||||
var idx = out.indexWhere((m) => m.id == model.id);
|
||||
|
||||
if (idx == -1) {
|
||||
return out..add(model);
|
||||
} else {
|
||||
var l = out[idx];
|
||||
return out
|
||||
..[idx] = l.copyWith(
|
||||
roles: List<_Role>.from(l.roles ?? [])
|
||||
..addAll(model.roles ?? []));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class UserQueryWhere extends QueryWhere {
|
||||
UserQueryWhere(UserQuery query)
|
||||
: id = NumericSqlExpressionBuilder<int>(query, 'id'),
|
||||
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
|
||||
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'),
|
||||
username = StringSqlExpressionBuilder(query, 'username'),
|
||||
password = StringSqlExpressionBuilder(query, 'password'),
|
||||
email = StringSqlExpressionBuilder(query, 'email');
|
||||
|
||||
final NumericSqlExpressionBuilder<int> id;
|
||||
|
||||
final DateTimeSqlExpressionBuilder createdAt;
|
||||
|
||||
final DateTimeSqlExpressionBuilder updatedAt;
|
||||
|
||||
final StringSqlExpressionBuilder username;
|
||||
|
||||
final StringSqlExpressionBuilder password;
|
||||
|
||||
final StringSqlExpressionBuilder email;
|
||||
|
||||
@override
|
||||
get expressionBuilders {
|
||||
return [id, createdAt, updatedAt, username, password, email];
|
||||
}
|
||||
}
|
||||
|
||||
class UserQueryValues extends MapQueryValues {
|
||||
@override
|
||||
get casts {
|
||||
return {};
|
||||
}
|
||||
|
||||
String get id {
|
||||
return (values['id'] as String);
|
||||
}
|
||||
|
||||
set id(String value) => values['id'] = value;
|
||||
DateTime get createdAt {
|
||||
return (values['created_at'] as DateTime);
|
||||
}
|
||||
|
||||
set createdAt(DateTime value) => values['created_at'] = value;
|
||||
DateTime get updatedAt {
|
||||
return (values['updated_at'] as DateTime);
|
||||
}
|
||||
|
||||
set updatedAt(DateTime value) => values['updated_at'] = value;
|
||||
String get username {
|
||||
return (values['username'] as String);
|
||||
}
|
||||
|
||||
set username(String value) => values['username'] = value;
|
||||
String get password {
|
||||
return (values['password'] as String);
|
||||
}
|
||||
|
||||
set password(String value) => values['password'] = value;
|
||||
String get email {
|
||||
return (values['email'] as String);
|
||||
}
|
||||
|
||||
set email(String value) => values['email'] = value;
|
||||
void copyFrom(User model) {
|
||||
createdAt = model.createdAt;
|
||||
updatedAt = model.updatedAt;
|
||||
username = model.username;
|
||||
password = model.password;
|
||||
email = model.email;
|
||||
}
|
||||
}
|
||||
|
||||
class RoleUserQuery extends Query<RoleUser, RoleUserQueryWhere> {
|
||||
RoleUserQuery({Query parent, Set<String> trampoline})
|
||||
: super(parent: parent) {
|
||||
trampoline ??= Set();
|
||||
trampoline.add(tableName);
|
||||
_where = RoleUserQueryWhere(this);
|
||||
leftJoin(_role = RoleQuery(trampoline: trampoline, parent: this), 'role_id',
|
||||
'id',
|
||||
additionalFields: const ['id', 'created_at', 'updated_at', 'name'],
|
||||
trampoline: trampoline);
|
||||
leftJoin(_user = UserQuery(trampoline: trampoline, parent: this), 'user_id',
|
||||
'id',
|
||||
additionalFields: const [
|
||||
'id',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'username',
|
||||
'password',
|
||||
'email'
|
||||
],
|
||||
trampoline: trampoline);
|
||||
}
|
||||
|
||||
@override
|
||||
final RoleUserQueryValues values = RoleUserQueryValues();
|
||||
|
||||
RoleUserQueryWhere _where;
|
||||
|
||||
RoleQuery _role;
|
||||
|
||||
UserQuery _user;
|
||||
|
||||
@override
|
||||
get casts {
|
||||
return {};
|
||||
}
|
||||
|
||||
@override
|
||||
get tableName {
|
||||
return 'role_users';
|
||||
}
|
||||
|
||||
@override
|
||||
get fields {
|
||||
return const ['role_id', 'user_id'];
|
||||
}
|
||||
|
||||
@override
|
||||
RoleUserQueryWhere get where {
|
||||
return _where;
|
||||
}
|
||||
|
||||
@override
|
||||
RoleUserQueryWhere newWhereClause() {
|
||||
return RoleUserQueryWhere(this);
|
||||
}
|
||||
|
||||
static RoleUser parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
var model = RoleUser();
|
||||
if (row.length > 2) {
|
||||
model = model.copyWith(
|
||||
role: RoleQuery.parseRow(row.skip(2).take(4).toList()));
|
||||
}
|
||||
if (row.length > 6) {
|
||||
model = model.copyWith(
|
||||
user: UserQuery.parseRow(row.skip(6).take(6).toList()));
|
||||
}
|
||||
return model;
|
||||
}
|
||||
|
||||
@override
|
||||
deserialize(List row) {
|
||||
return parseRow(row);
|
||||
}
|
||||
|
||||
RoleQuery get role {
|
||||
return _role;
|
||||
}
|
||||
|
||||
UserQuery get user {
|
||||
return _user;
|
||||
}
|
||||
}
|
||||
|
||||
class RoleUserQueryWhere extends QueryWhere {
|
||||
RoleUserQueryWhere(RoleUserQuery query)
|
||||
: roleId = NumericSqlExpressionBuilder<int>(query, 'role_id'),
|
||||
userId = NumericSqlExpressionBuilder<int>(query, 'user_id');
|
||||
|
||||
final NumericSqlExpressionBuilder<int> roleId;
|
||||
|
||||
final NumericSqlExpressionBuilder<int> userId;
|
||||
|
||||
@override
|
||||
get expressionBuilders {
|
||||
return [roleId, userId];
|
||||
}
|
||||
}
|
||||
|
||||
class RoleUserQueryValues extends MapQueryValues {
|
||||
@override
|
||||
get casts {
|
||||
return {};
|
||||
}
|
||||
|
||||
int get roleId {
|
||||
return (values['role_id'] as int);
|
||||
}
|
||||
|
||||
set roleId(int value) => values['role_id'] = value;
|
||||
int get userId {
|
||||
return (values['user_id'] as int);
|
||||
}
|
||||
|
||||
set userId(int value) => values['user_id'] = value;
|
||||
void copyFrom(RoleUser model) {
|
||||
if (model.role != null) {
|
||||
values['role_id'] = model.role.id;
|
||||
}
|
||||
if (model.user != null) {
|
||||
values['user_id'] = model.user.id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class RoleQuery extends Query<Role, RoleQueryWhere> {
|
||||
RoleQuery({Query parent, Set<String> trampoline}) : super(parent: parent) {
|
||||
trampoline ??= Set();
|
||||
trampoline.add(tableName);
|
||||
_where = RoleQueryWhere(this);
|
||||
leftJoin(_users = RoleUserQuery(trampoline: trampoline, parent: this), 'id',
|
||||
'role_id',
|
||||
additionalFields: const [
|
||||
'id',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'username',
|
||||
'password',
|
||||
'email'
|
||||
],
|
||||
trampoline: trampoline);
|
||||
}
|
||||
|
||||
@override
|
||||
final RoleQueryValues values = RoleQueryValues();
|
||||
|
||||
RoleQueryWhere _where;
|
||||
|
||||
RoleUserQuery _users;
|
||||
|
||||
@override
|
||||
get casts {
|
||||
return {};
|
||||
}
|
||||
|
||||
@override
|
||||
get tableName {
|
||||
return 'roles';
|
||||
}
|
||||
|
||||
@override
|
||||
get fields {
|
||||
return const ['id', 'created_at', 'updated_at', 'name'];
|
||||
}
|
||||
|
||||
@override
|
||||
RoleQueryWhere get where {
|
||||
return _where;
|
||||
}
|
||||
|
||||
@override
|
||||
RoleQueryWhere newWhereClause() {
|
||||
return RoleQueryWhere(this);
|
||||
}
|
||||
|
||||
static Role parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
var model = Role(
|
||||
id: row[0].toString(),
|
||||
createdAt: (row[1] as DateTime),
|
||||
updatedAt: (row[2] as DateTime),
|
||||
name: (row[3] as String));
|
||||
if (row.length > 4) {
|
||||
model = model.copyWith(
|
||||
users: [UserQuery.parseRow(row.skip(4).take(6).toList())]
|
||||
.where((x) => x != null)
|
||||
.toList());
|
||||
}
|
||||
return model;
|
||||
}
|
||||
|
||||
@override
|
||||
deserialize(List row) {
|
||||
return parseRow(row);
|
||||
}
|
||||
|
||||
RoleUserQuery get users {
|
||||
return _users;
|
||||
}
|
||||
|
||||
@override
|
||||
bool canCompile(trampoline) {
|
||||
return (!(trampoline.contains('roles') &&
|
||||
trampoline.contains('role_users')));
|
||||
}
|
||||
|
||||
@override
|
||||
get(QueryExecutor executor) {
|
||||
return super.get(executor).then((result) {
|
||||
return result.fold<List<Role>>([], (out, model) {
|
||||
var idx = out.indexWhere((m) => m.id == model.id);
|
||||
|
||||
if (idx == -1) {
|
||||
return out..add(model);
|
||||
} else {
|
||||
var l = out[idx];
|
||||
return out
|
||||
..[idx] = l.copyWith(
|
||||
users: List<_User>.from(l.users ?? [])
|
||||
..addAll(model.users ?? []));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
update(QueryExecutor executor) {
|
||||
return super.update(executor).then((result) {
|
||||
return result.fold<List<Role>>([], (out, model) {
|
||||
var idx = out.indexWhere((m) => m.id == model.id);
|
||||
|
||||
if (idx == -1) {
|
||||
return out..add(model);
|
||||
} else {
|
||||
var l = out[idx];
|
||||
return out
|
||||
..[idx] = l.copyWith(
|
||||
users: List<_User>.from(l.users ?? [])
|
||||
..addAll(model.users ?? []));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
delete(QueryExecutor executor) {
|
||||
return super.delete(executor).then((result) {
|
||||
return result.fold<List<Role>>([], (out, model) {
|
||||
var idx = out.indexWhere((m) => m.id == model.id);
|
||||
|
||||
if (idx == -1) {
|
||||
return out..add(model);
|
||||
} else {
|
||||
var l = out[idx];
|
||||
return out
|
||||
..[idx] = l.copyWith(
|
||||
users: List<_User>.from(l.users ?? [])
|
||||
..addAll(model.users ?? []));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class RoleQueryWhere extends QueryWhere {
|
||||
RoleQueryWhere(RoleQuery query)
|
||||
: id = NumericSqlExpressionBuilder<int>(query, 'id'),
|
||||
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
|
||||
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'),
|
||||
name = StringSqlExpressionBuilder(query, 'name');
|
||||
|
||||
final NumericSqlExpressionBuilder<int> id;
|
||||
|
||||
final DateTimeSqlExpressionBuilder createdAt;
|
||||
|
||||
final DateTimeSqlExpressionBuilder updatedAt;
|
||||
|
||||
final StringSqlExpressionBuilder name;
|
||||
|
||||
@override
|
||||
get expressionBuilders {
|
||||
return [id, createdAt, updatedAt, name];
|
||||
}
|
||||
}
|
||||
|
||||
class RoleQueryValues extends MapQueryValues {
|
||||
@override
|
||||
get casts {
|
||||
return {};
|
||||
}
|
||||
|
||||
String get id {
|
||||
return (values['id'] as String);
|
||||
}
|
||||
|
||||
set id(String value) => values['id'] = value;
|
||||
DateTime get createdAt {
|
||||
return (values['created_at'] as DateTime);
|
||||
}
|
||||
|
||||
set createdAt(DateTime value) => values['created_at'] = value;
|
||||
DateTime get updatedAt {
|
||||
return (values['updated_at'] as DateTime);
|
||||
}
|
||||
|
||||
set updatedAt(DateTime value) => values['updated_at'] = value;
|
||||
String get name {
|
||||
return (values['name'] as String);
|
||||
}
|
||||
|
||||
set name(String value) => values['name'] = value;
|
||||
void copyFrom(Role model) {
|
||||
createdAt = model.createdAt;
|
||||
updatedAt = model.updatedAt;
|
||||
name = model.name;
|
||||
}
|
||||
}
|
||||
|
||||
// **************************************************************************
|
||||
// JsonModelGenerator
|
||||
// **************************************************************************
|
||||
|
||||
@generatedSerializable
|
||||
class User extends _User {
|
||||
User(
|
||||
{this.id,
|
||||
this.createdAt,
|
||||
this.updatedAt,
|
||||
this.username,
|
||||
this.password,
|
||||
this.email,
|
||||
List<_Role> roles})
|
||||
: this.roles = List.unmodifiable(roles ?? []);
|
||||
|
||||
/// A unique identifier corresponding to this item.
|
||||
@override
|
||||
String id;
|
||||
|
||||
/// The time at which this item was created.
|
||||
@override
|
||||
DateTime createdAt;
|
||||
|
||||
/// The last time at which this item was updated.
|
||||
@override
|
||||
DateTime updatedAt;
|
||||
|
||||
@override
|
||||
final String username;
|
||||
|
||||
@override
|
||||
final String password;
|
||||
|
||||
@override
|
||||
final String email;
|
||||
|
||||
@override
|
||||
final List<_Role> roles;
|
||||
|
||||
User copyWith(
|
||||
{String id,
|
||||
DateTime createdAt,
|
||||
DateTime updatedAt,
|
||||
String username,
|
||||
String password,
|
||||
String email,
|
||||
List<_Role> roles}) {
|
||||
return User(
|
||||
id: id ?? this.id,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
updatedAt: updatedAt ?? this.updatedAt,
|
||||
username: username ?? this.username,
|
||||
password: password ?? this.password,
|
||||
email: email ?? this.email,
|
||||
roles: roles ?? this.roles);
|
||||
}
|
||||
|
||||
bool operator ==(other) {
|
||||
return other is _User &&
|
||||
other.id == id &&
|
||||
other.createdAt == createdAt &&
|
||||
other.updatedAt == updatedAt &&
|
||||
other.username == username &&
|
||||
other.password == password &&
|
||||
other.email == email &&
|
||||
ListEquality<_Role>(DefaultEquality<_Role>())
|
||||
.equals(other.roles, roles);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return hashObjects(
|
||||
[id, createdAt, updatedAt, username, password, email, roles]);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return "User(id=$id, createdAt=$createdAt, updatedAt=$updatedAt, username=$username, password=$password, email=$email, roles=$roles)";
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return UserSerializer.toMap(this);
|
||||
}
|
||||
}
|
||||
|
||||
@generatedSerializable
|
||||
class RoleUser implements _RoleUser {
|
||||
const RoleUser({this.role, this.user});
|
||||
|
||||
@override
|
||||
final _Role role;
|
||||
|
||||
@override
|
||||
final _User user;
|
||||
|
||||
RoleUser copyWith({_Role role, _User user}) {
|
||||
return RoleUser(role: role ?? this.role, user: user ?? this.user);
|
||||
}
|
||||
|
||||
bool operator ==(other) {
|
||||
return other is _RoleUser && other.role == role && other.user == user;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return hashObjects([role, user]);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return "RoleUser(role=$role, user=$user)";
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return RoleUserSerializer.toMap(this);
|
||||
}
|
||||
}
|
||||
|
||||
@generatedSerializable
|
||||
class Role extends _Role {
|
||||
Role({this.id, this.createdAt, this.updatedAt, this.name, List<_User> users})
|
||||
: this.users = List.unmodifiable(users ?? []);
|
||||
|
||||
/// A unique identifier corresponding to this item.
|
||||
@override
|
||||
String id;
|
||||
|
||||
/// The time at which this item was created.
|
||||
@override
|
||||
DateTime createdAt;
|
||||
|
||||
/// The last time at which this item was updated.
|
||||
@override
|
||||
DateTime updatedAt;
|
||||
|
||||
@override
|
||||
String name;
|
||||
|
||||
@override
|
||||
final List<_User> users;
|
||||
|
||||
Role copyWith(
|
||||
{String id,
|
||||
DateTime createdAt,
|
||||
DateTime updatedAt,
|
||||
String name,
|
||||
List<_User> users}) {
|
||||
return Role(
|
||||
id: id ?? this.id,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
updatedAt: updatedAt ?? this.updatedAt,
|
||||
name: name ?? this.name,
|
||||
users: users ?? this.users);
|
||||
}
|
||||
|
||||
bool operator ==(other) {
|
||||
return other is _Role &&
|
||||
other.id == id &&
|
||||
other.createdAt == createdAt &&
|
||||
other.updatedAt == updatedAt &&
|
||||
other.name == name &&
|
||||
ListEquality<_User>(DefaultEquality<_User>())
|
||||
.equals(other.users, users);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return hashObjects([id, createdAt, updatedAt, name, users]);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return "Role(id=$id, createdAt=$createdAt, updatedAt=$updatedAt, name=$name, users=$users)";
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return RoleSerializer.toMap(this);
|
||||
}
|
||||
}
|
||||
|
||||
// **************************************************************************
|
||||
// SerializerGenerator
|
||||
// **************************************************************************
|
||||
|
||||
const UserSerializer userSerializer = UserSerializer();
|
||||
|
||||
class UserEncoder extends Converter<User, Map> {
|
||||
const UserEncoder();
|
||||
|
||||
@override
|
||||
Map convert(User model) => UserSerializer.toMap(model);
|
||||
}
|
||||
|
||||
class UserDecoder extends Converter<Map, User> {
|
||||
const UserDecoder();
|
||||
|
||||
@override
|
||||
User convert(Map map) => UserSerializer.fromMap(map);
|
||||
}
|
||||
|
||||
class UserSerializer extends Codec<User, Map> {
|
||||
const UserSerializer();
|
||||
|
||||
@override
|
||||
get encoder => const UserEncoder();
|
||||
@override
|
||||
get decoder => const UserDecoder();
|
||||
static User fromMap(Map map) {
|
||||
return User(
|
||||
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,
|
||||
username: map['username'] as String,
|
||||
password: map['password'] as String,
|
||||
email: map['email'] as String,
|
||||
roles: map['roles'] is Iterable
|
||||
? List.unmodifiable(((map['roles'] as Iterable).whereType<Map>())
|
||||
.map(RoleSerializer.fromMap))
|
||||
: null);
|
||||
}
|
||||
|
||||
static Map<String, dynamic> toMap(_User model) {
|
||||
if (model == null) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
'id': model.id,
|
||||
'created_at': model.createdAt?.toIso8601String(),
|
||||
'updated_at': model.updatedAt?.toIso8601String(),
|
||||
'username': model.username,
|
||||
'password': model.password,
|
||||
'email': model.email,
|
||||
'roles': model.roles?.map((m) => RoleSerializer.toMap(m))?.toList()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
abstract class UserFields {
|
||||
static const List<String> allFields = <String>[
|
||||
id,
|
||||
createdAt,
|
||||
updatedAt,
|
||||
username,
|
||||
password,
|
||||
email,
|
||||
roles
|
||||
];
|
||||
|
||||
static const String id = 'id';
|
||||
|
||||
static const String createdAt = 'created_at';
|
||||
|
||||
static const String updatedAt = 'updated_at';
|
||||
|
||||
static const String username = 'username';
|
||||
|
||||
static const String password = 'password';
|
||||
|
||||
static const String email = 'email';
|
||||
|
||||
static const String roles = 'roles';
|
||||
}
|
||||
|
||||
const RoleUserSerializer roleUserSerializer = RoleUserSerializer();
|
||||
|
||||
class RoleUserEncoder extends Converter<RoleUser, Map> {
|
||||
const RoleUserEncoder();
|
||||
|
||||
@override
|
||||
Map convert(RoleUser model) => RoleUserSerializer.toMap(model);
|
||||
}
|
||||
|
||||
class RoleUserDecoder extends Converter<Map, RoleUser> {
|
||||
const RoleUserDecoder();
|
||||
|
||||
@override
|
||||
RoleUser convert(Map map) => RoleUserSerializer.fromMap(map);
|
||||
}
|
||||
|
||||
class RoleUserSerializer extends Codec<RoleUser, Map> {
|
||||
const RoleUserSerializer();
|
||||
|
||||
@override
|
||||
get encoder => const RoleUserEncoder();
|
||||
@override
|
||||
get decoder => const RoleUserDecoder();
|
||||
static RoleUser fromMap(Map map) {
|
||||
return RoleUser(
|
||||
role: map['role'] != null
|
||||
? RoleSerializer.fromMap(map['role'] as Map)
|
||||
: null,
|
||||
user: map['user'] != null
|
||||
? UserSerializer.fromMap(map['user'] as Map)
|
||||
: null);
|
||||
}
|
||||
|
||||
static Map<String, dynamic> toMap(_RoleUser model) {
|
||||
if (model == null) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
'role': RoleSerializer.toMap(model.role),
|
||||
'user': UserSerializer.toMap(model.user)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
abstract class RoleUserFields {
|
||||
static const List<String> allFields = <String>[role, user];
|
||||
|
||||
static const String role = 'role';
|
||||
|
||||
static const String user = 'user';
|
||||
}
|
||||
|
||||
const RoleSerializer roleSerializer = RoleSerializer();
|
||||
|
||||
class RoleEncoder extends Converter<Role, Map> {
|
||||
const RoleEncoder();
|
||||
|
||||
@override
|
||||
Map convert(Role model) => RoleSerializer.toMap(model);
|
||||
}
|
||||
|
||||
class RoleDecoder extends Converter<Map, Role> {
|
||||
const RoleDecoder();
|
||||
|
||||
@override
|
||||
Role convert(Map map) => RoleSerializer.fromMap(map);
|
||||
}
|
||||
|
||||
class RoleSerializer extends Codec<Role, Map> {
|
||||
const RoleSerializer();
|
||||
|
||||
@override
|
||||
get encoder => const RoleEncoder();
|
||||
@override
|
||||
get decoder => const RoleDecoder();
|
||||
static Role fromMap(Map map) {
|
||||
return Role(
|
||||
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,
|
||||
name: map['name'] as String,
|
||||
users: map['users'] is Iterable
|
||||
? List.unmodifiable(((map['users'] as Iterable).whereType<Map>())
|
||||
.map(UserSerializer.fromMap))
|
||||
: null);
|
||||
}
|
||||
|
||||
static Map<String, dynamic> toMap(_Role model) {
|
||||
if (model == null) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
'id': model.id,
|
||||
'created_at': model.createdAt?.toIso8601String(),
|
||||
'updated_at': model.updatedAt?.toIso8601String(),
|
||||
'name': model.name,
|
||||
'users': model.users?.map((m) => UserSerializer.toMap(m))?.toList()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
abstract class RoleFields {
|
||||
static const List<String> allFields = <String>[
|
||||
id,
|
||||
createdAt,
|
||||
updatedAt,
|
||||
name,
|
||||
users
|
||||
];
|
||||
|
||||
static const String id = 'id';
|
||||
|
||||
static const String createdAt = 'created_at';
|
||||
|
||||
static const String updatedAt = 'updated_at';
|
||||
|
||||
static const String name = 'name';
|
||||
|
||||
static const String users = 'users';
|
||||
}
|
Loading…
Reference in a new issue