ORM deps broken
This commit is contained in:
parent
8dfcdc1f5f
commit
e87c92a48b
18 changed files with 201 additions and 576 deletions
|
@ -280,9 +280,10 @@ abstract class Query<T, Where extends QueryWhere> extends QueryBase<T> {
|
|||
return ss;
|
||||
}));
|
||||
_joins.forEach((j) {
|
||||
f
|
||||
..add(j.fieldName)
|
||||
..addAll(j.additionalFields.map((s) => j.nameFor(s)));
|
||||
var additional = j.additionalFields.map((s) => j.nameFor(s)).toList();
|
||||
// if (!additional.contains(j.fieldName))
|
||||
// additional.insert(0, j.fieldName);
|
||||
f.addAll(additional);
|
||||
});
|
||||
}
|
||||
if (withFields) b.write(f.join(', '));
|
||||
|
|
|
@ -30,7 +30,7 @@ targets:
|
|||
- test/models/role.dart
|
||||
$default:
|
||||
dependencies:
|
||||
- :_standalone
|
||||
- angel_orm:_standalone
|
||||
sources:
|
||||
- test/models/book.dart
|
||||
- test/models/has_car.dart
|
||||
|
|
|
@ -177,13 +177,14 @@ Future<OrmBuildContext> buildOrmContext(
|
|||
ctx.buildContext.aliases[name] = relation.localKey;
|
||||
|
||||
if (!ctx.effectiveFields.any((f) => f.name == field.name)) {
|
||||
if (field.name != 'id' ||
|
||||
!const TypeChecker.fromRuntime(Model)
|
||||
.isAssignableFromType(ctx.buildContext.clazz.type)) {
|
||||
// TODO: Consequences of allowing ID to be a relation? (should be none)
|
||||
// if (field.name != 'id' ||
|
||||
// !const TypeChecker.fromRuntime(Model)
|
||||
// .isAssignableFromType(ctx.buildContext.clazz.type)) {
|
||||
var rf = new RelationFieldImpl(name,
|
||||
field.type.element.context.typeProvider.intType, field.name);
|
||||
ctx.effectiveFields.add(rf);
|
||||
}
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -281,7 +281,7 @@ class OrmGenerator extends GeneratorForAnnotation<Orm> {
|
|||
relation.type == RelationshipType.hasMany) {
|
||||
var foreign = ctx.relationTypes[relation];
|
||||
var additionalFields = foreign.effectiveFields
|
||||
.where((f) => f.name != 'id' || !isSpecialId(ctx, f))
|
||||
// .where((f) => f.name != 'id' || !isSpecialId(ctx, f))
|
||||
.map((f) => literalString(
|
||||
foreign.buildContext.resolveFieldName(f.name)));
|
||||
var joinArgs = [relation.localKey, relation.foreignKey]
|
||||
|
|
|
@ -34,6 +34,6 @@ dev_dependencies:
|
|||
collection: ^1.0.0
|
||||
postgres: ^1.0.0
|
||||
test: ^1.0.0
|
||||
# dependency_overrides:
|
||||
# angel_orm:
|
||||
# path: ../angel_orm
|
||||
dependency_overrides:
|
||||
angel_orm:
|
||||
path: ../angel_orm
|
||||
|
|
|
@ -17,6 +17,7 @@ main() {
|
|||
});
|
||||
|
||||
test('sets to null if no child', () async {
|
||||
print(LegQuery().compile(Set()));
|
||||
var query = new LegQuery()..where.id.equals(int.parse(originalLeg.id));
|
||||
var leg = await query.getOne(executor);
|
||||
print(leg.toJson());
|
||||
|
|
|
@ -31,11 +31,11 @@ class AuthorQuery extends Query<Author, AuthorQueryWhere> {
|
|||
AuthorQuery({Set<String> trampoline}) {
|
||||
trampoline ??= Set();
|
||||
trampoline.add(tableName);
|
||||
_where = new AuthorQueryWhere(this);
|
||||
_where = AuthorQueryWhere(this);
|
||||
}
|
||||
|
||||
@override
|
||||
final AuthorQueryValues values = new AuthorQueryValues();
|
||||
final AuthorQueryValues values = AuthorQueryValues();
|
||||
|
||||
AuthorQueryWhere _where;
|
||||
|
||||
|
@ -61,12 +61,12 @@ class AuthorQuery extends Query<Author, AuthorQueryWhere> {
|
|||
|
||||
@override
|
||||
AuthorQueryWhere newWhereClause() {
|
||||
return new AuthorQueryWhere(this);
|
||||
return AuthorQueryWhere(this);
|
||||
}
|
||||
|
||||
static Author parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
var model = new Author(
|
||||
var model = Author(
|
||||
id: row[0].toString(),
|
||||
name: (row[1] as String),
|
||||
createdAt: (row[2] as DateTime),
|
||||
|
@ -82,10 +82,10 @@ class AuthorQuery extends Query<Author, AuthorQueryWhere> {
|
|||
|
||||
class AuthorQueryWhere extends QueryWhere {
|
||||
AuthorQueryWhere(AuthorQuery query)
|
||||
: id = new NumericSqlExpressionBuilder<int>(query, 'id'),
|
||||
name = new StringSqlExpressionBuilder(query, 'name'),
|
||||
createdAt = new DateTimeSqlExpressionBuilder(query, 'created_at'),
|
||||
updatedAt = new DateTimeSqlExpressionBuilder(query, 'updated_at');
|
||||
: id = NumericSqlExpressionBuilder<int>(query, 'id'),
|
||||
name = StringSqlExpressionBuilder(query, 'name'),
|
||||
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
|
||||
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at');
|
||||
|
||||
final NumericSqlExpressionBuilder<int> id;
|
||||
|
||||
|
@ -140,7 +140,11 @@ class AuthorQueryValues extends MapQueryValues {
|
|||
|
||||
@generatedSerializable
|
||||
class Author extends _Author {
|
||||
Author({this.id, this.name: 'Tobe Osakwe', this.createdAt, this.updatedAt});
|
||||
Author(
|
||||
{this.id,
|
||||
@required this.name = 'Tobe Osakwe',
|
||||
this.createdAt,
|
||||
this.updatedAt});
|
||||
|
||||
@override
|
||||
final String id;
|
||||
|
@ -187,6 +191,10 @@ class Author extends _Author {
|
|||
|
||||
abstract class AuthorSerializer {
|
||||
static Author fromMap(Map map) {
|
||||
if (map['name'] == null) {
|
||||
throw new FormatException("Missing required field 'name' on Author.");
|
||||
}
|
||||
|
||||
return new Author(
|
||||
id: map['id'] as String,
|
||||
name: map['name'] as String ?? 'Tobe Osakwe',
|
||||
|
@ -206,6 +214,10 @@ abstract class AuthorSerializer {
|
|||
if (model == null) {
|
||||
return null;
|
||||
}
|
||||
if (model.name == null) {
|
||||
throw new FormatException("Missing required field 'name' on Author.");
|
||||
}
|
||||
|
||||
return {
|
||||
'id': model.id,
|
||||
'name': model.name,
|
||||
|
@ -216,7 +228,7 @@ abstract class AuthorSerializer {
|
|||
}
|
||||
|
||||
abstract class AuthorFields {
|
||||
static const List<String> allFields = const <String>[
|
||||
static const List<String> allFields = <String>[
|
||||
id,
|
||||
name,
|
||||
createdAt,
|
||||
|
|
|
@ -2,29 +2,6 @@
|
|||
|
||||
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.varChar('name');
|
||||
table.timeStamp('created_at');
|
||||
table.timeStamp('updated_at');
|
||||
table.integer('author_id').references('authors', 'id');
|
||||
table.integer('partner_author_id').references('authors', 'id');
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
down(Schema schema) {
|
||||
schema.drop('books');
|
||||
}
|
||||
}
|
||||
|
||||
// **************************************************************************
|
||||
// OrmGenerator
|
||||
// **************************************************************************
|
||||
|
@ -33,15 +10,11 @@ class BookQuery extends Query<Book, BookQueryWhere> {
|
|||
BookQuery({Set<String> trampoline}) {
|
||||
trampoline ??= Set();
|
||||
trampoline.add(tableName);
|
||||
_where = new BookQueryWhere(this);
|
||||
leftJoin('authors', 'author_id', 'id',
|
||||
additionalFields: const ['name', 'created_at', 'updated_at']);
|
||||
leftJoin('authors', 'partner_author_id', 'id',
|
||||
additionalFields: const ['name', 'created_at', 'updated_at']);
|
||||
_where = BookQueryWhere(this);
|
||||
}
|
||||
|
||||
@override
|
||||
final BookQueryValues values = new BookQueryValues();
|
||||
final BookQueryValues values = BookQueryValues();
|
||||
|
||||
BookQueryWhere _where;
|
||||
|
||||
|
@ -57,14 +30,7 @@ class BookQuery extends Query<Book, BookQueryWhere> {
|
|||
|
||||
@override
|
||||
get fields {
|
||||
return const [
|
||||
'id',
|
||||
'author_id',
|
||||
'partner_author_id',
|
||||
'name',
|
||||
'created_at',
|
||||
'updated_at'
|
||||
];
|
||||
return const ['id'];
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -74,24 +40,12 @@ class BookQuery extends Query<Book, BookQueryWhere> {
|
|||
|
||||
@override
|
||||
BookQueryWhere newWhereClause() {
|
||||
return new BookQueryWhere(this);
|
||||
return BookQueryWhere(this);
|
||||
}
|
||||
|
||||
static Book parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
var model = new Book(
|
||||
id: row[0].toString(),
|
||||
name: (row[3] as String),
|
||||
createdAt: (row[4] as DateTime),
|
||||
updatedAt: (row[5] as DateTime));
|
||||
if (row.length > 6) {
|
||||
model =
|
||||
model.copyWith(author: AuthorQuery.parseRow(row.skip(6).toList()));
|
||||
}
|
||||
if (row.length > 10) {
|
||||
model = model.copyWith(
|
||||
partnerAuthor: AuthorQuery.parseRow(row.skip(10).toList()));
|
||||
}
|
||||
var model = Book(id: row[0].toString());
|
||||
return model;
|
||||
}
|
||||
|
||||
|
@ -103,29 +57,13 @@ class BookQuery extends Query<Book, BookQueryWhere> {
|
|||
|
||||
class BookQueryWhere extends QueryWhere {
|
||||
BookQueryWhere(BookQuery query)
|
||||
: id = new NumericSqlExpressionBuilder<int>(query, 'id'),
|
||||
authorId = new NumericSqlExpressionBuilder<int>(query, 'author_id'),
|
||||
partnerAuthorId =
|
||||
new NumericSqlExpressionBuilder<int>(query, 'partner_author_id'),
|
||||
name = new StringSqlExpressionBuilder(query, 'name'),
|
||||
createdAt = new DateTimeSqlExpressionBuilder(query, 'created_at'),
|
||||
updatedAt = new DateTimeSqlExpressionBuilder(query, 'updated_at');
|
||||
: id = NumericSqlExpressionBuilder<int>(query, 'id');
|
||||
|
||||
final NumericSqlExpressionBuilder<int> id;
|
||||
|
||||
final NumericSqlExpressionBuilder<int> authorId;
|
||||
|
||||
final NumericSqlExpressionBuilder<int> partnerAuthorId;
|
||||
|
||||
final StringSqlExpressionBuilder name;
|
||||
|
||||
final DateTimeSqlExpressionBuilder createdAt;
|
||||
|
||||
final DateTimeSqlExpressionBuilder updatedAt;
|
||||
|
||||
@override
|
||||
get expressionBuilders {
|
||||
return [id, authorId, partnerAuthorId, name, createdAt, updatedAt];
|
||||
return [id];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -140,42 +78,7 @@ class BookQueryValues extends MapQueryValues {
|
|||
}
|
||||
|
||||
set id(int value) => values['id'] = 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;
|
||||
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(Book model) {
|
||||
name = model.name;
|
||||
createdAt = model.createdAt;
|
||||
updatedAt = model.updatedAt;
|
||||
if (model.author != null) {
|
||||
values['author_id'] = int.parse(model.author.id);
|
||||
}
|
||||
if (model.partnerAuthor != null) {
|
||||
values['partner_author_id'] = int.parse(model.partnerAuthor.id);
|
||||
}
|
||||
}
|
||||
void copyFrom(Book model) {}
|
||||
}
|
||||
|
||||
// **************************************************************************
|
||||
|
@ -196,10 +99,10 @@ class Book extends _Book {
|
|||
final String id;
|
||||
|
||||
@override
|
||||
final Author author;
|
||||
final dynamic author;
|
||||
|
||||
@override
|
||||
final Author partnerAuthor;
|
||||
final dynamic partnerAuthor;
|
||||
|
||||
@override
|
||||
final String name;
|
||||
|
@ -212,8 +115,8 @@ class Book extends _Book {
|
|||
|
||||
Book copyWith(
|
||||
{String id,
|
||||
Author author,
|
||||
Author partnerAuthor,
|
||||
dynamic author,
|
||||
dynamic partnerAuthor,
|
||||
String name,
|
||||
DateTime createdAt,
|
||||
DateTime updatedAt}) {
|
||||
|
@ -254,12 +157,8 @@ abstract class BookSerializer {
|
|||
static Book fromMap(Map map) {
|
||||
return new Book(
|
||||
id: map['id'] as String,
|
||||
author: map['author'] != null
|
||||
? AuthorSerializer.fromMap(map['author'] as Map)
|
||||
: null,
|
||||
partnerAuthor: map['partner_author'] != null
|
||||
? AuthorSerializer.fromMap(map['partner_author'] as Map)
|
||||
: null,
|
||||
author: map['author'] as dynamic,
|
||||
partnerAuthor: map['partner_author'] as dynamic,
|
||||
name: map['name'] as String,
|
||||
createdAt: map['created_at'] != null
|
||||
? (map['created_at'] is DateTime
|
||||
|
@ -279,8 +178,8 @@ abstract class BookSerializer {
|
|||
}
|
||||
return {
|
||||
'id': model.id,
|
||||
'author': AuthorSerializer.toMap(model.author),
|
||||
'partner_author': AuthorSerializer.toMap(model.partnerAuthor),
|
||||
'author': model.author,
|
||||
'partner_author': model.partnerAuthor,
|
||||
'name': model.name,
|
||||
'created_at': model.createdAt?.toIso8601String(),
|
||||
'updated_at': model.updatedAt?.toIso8601String()
|
||||
|
@ -289,7 +188,7 @@ abstract class BookSerializer {
|
|||
}
|
||||
|
||||
abstract class BookFields {
|
||||
static const List<String> allFields = const <String>[
|
||||
static const List<String> allFields = <String>[
|
||||
id,
|
||||
author,
|
||||
partnerAuthor,
|
||||
|
|
|
@ -34,11 +34,11 @@ class CarQuery extends Query<Car, CarQueryWhere> {
|
|||
CarQuery({Set<String> trampoline}) {
|
||||
trampoline ??= Set();
|
||||
trampoline.add(tableName);
|
||||
_where = new CarQueryWhere(this);
|
||||
_where = CarQueryWhere(this);
|
||||
}
|
||||
|
||||
@override
|
||||
final CarQueryValues values = new CarQueryValues();
|
||||
final CarQueryValues values = CarQueryValues();
|
||||
|
||||
CarQueryWhere _where;
|
||||
|
||||
|
@ -72,12 +72,12 @@ class CarQuery extends Query<Car, CarQueryWhere> {
|
|||
|
||||
@override
|
||||
CarQueryWhere newWhereClause() {
|
||||
return new CarQueryWhere(this);
|
||||
return CarQueryWhere(this);
|
||||
}
|
||||
|
||||
static Car parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
var model = new Car(
|
||||
var model = Car(
|
||||
id: row[0].toString(),
|
||||
make: (row[1] as String),
|
||||
description: (row[2] as String),
|
||||
|
@ -96,14 +96,13 @@ class CarQuery extends Query<Car, CarQueryWhere> {
|
|||
|
||||
class CarQueryWhere extends QueryWhere {
|
||||
CarQueryWhere(CarQuery query)
|
||||
: id = new NumericSqlExpressionBuilder<int>(query, 'id'),
|
||||
make = new StringSqlExpressionBuilder(query, 'make'),
|
||||
description = new StringSqlExpressionBuilder(query, 'description'),
|
||||
familyFriendly =
|
||||
new BooleanSqlExpressionBuilder(query, 'family_friendly'),
|
||||
recalledAt = new DateTimeSqlExpressionBuilder(query, 'recalled_at'),
|
||||
createdAt = new DateTimeSqlExpressionBuilder(query, 'created_at'),
|
||||
updatedAt = new DateTimeSqlExpressionBuilder(query, 'updated_at');
|
||||
: id = NumericSqlExpressionBuilder<int>(query, 'id'),
|
||||
make = StringSqlExpressionBuilder(query, 'make'),
|
||||
description = StringSqlExpressionBuilder(query, 'description'),
|
||||
familyFriendly = BooleanSqlExpressionBuilder(query, 'family_friendly'),
|
||||
recalledAt = DateTimeSqlExpressionBuilder(query, 'recalled_at'),
|
||||
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
|
||||
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at');
|
||||
|
||||
final NumericSqlExpressionBuilder<int> id;
|
||||
|
||||
|
@ -312,7 +311,7 @@ abstract class CarSerializer {
|
|||
}
|
||||
|
||||
abstract class CarFields {
|
||||
static const List<String> allFields = const <String>[
|
||||
static const List<String> allFields = <String>[
|
||||
id,
|
||||
make,
|
||||
description,
|
||||
|
|
|
@ -30,11 +30,11 @@ class CustomerQuery extends Query<Customer, CustomerQueryWhere> {
|
|||
CustomerQuery({Set<String> trampoline}) {
|
||||
trampoline ??= Set();
|
||||
trampoline.add(tableName);
|
||||
_where = new CustomerQueryWhere(this);
|
||||
_where = CustomerQueryWhere(this);
|
||||
}
|
||||
|
||||
@override
|
||||
final CustomerQueryValues values = new CustomerQueryValues();
|
||||
final CustomerQueryValues values = CustomerQueryValues();
|
||||
|
||||
CustomerQueryWhere _where;
|
||||
|
||||
|
@ -60,12 +60,12 @@ class CustomerQuery extends Query<Customer, CustomerQueryWhere> {
|
|||
|
||||
@override
|
||||
CustomerQueryWhere newWhereClause() {
|
||||
return new CustomerQueryWhere(this);
|
||||
return CustomerQueryWhere(this);
|
||||
}
|
||||
|
||||
static Customer parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
var model = new Customer(
|
||||
var model = Customer(
|
||||
id: row[0].toString(),
|
||||
createdAt: (row[1] as DateTime),
|
||||
updatedAt: (row[2] as DateTime));
|
||||
|
@ -80,9 +80,9 @@ class CustomerQuery extends Query<Customer, CustomerQueryWhere> {
|
|||
|
||||
class CustomerQueryWhere extends QueryWhere {
|
||||
CustomerQueryWhere(CustomerQuery query)
|
||||
: id = new NumericSqlExpressionBuilder<int>(query, 'id'),
|
||||
createdAt = new DateTimeSqlExpressionBuilder(query, 'created_at'),
|
||||
updatedAt = new DateTimeSqlExpressionBuilder(query, 'updated_at');
|
||||
: id = NumericSqlExpressionBuilder<int>(query, 'id'),
|
||||
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
|
||||
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at');
|
||||
|
||||
final NumericSqlExpressionBuilder<int> id;
|
||||
|
||||
|
@ -197,11 +197,7 @@ abstract class CustomerSerializer {
|
|||
}
|
||||
|
||||
abstract class CustomerFields {
|
||||
static const List<String> allFields = const <String>[
|
||||
id,
|
||||
createdAt,
|
||||
updatedAt
|
||||
];
|
||||
static const List<String> allFields = <String>[id, createdAt, updatedAt];
|
||||
|
||||
static const String id = 'id';
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ class FootMigration extends Migration {
|
|||
schema.create('feet', (table) {
|
||||
table.serial('id')..primaryKey();
|
||||
table.integer('leg_id');
|
||||
table.declare('n_toes', new ColumnType('decimal'));
|
||||
table.declare('n_toes', ColumnType('decimal'));
|
||||
table.timeStamp('created_at');
|
||||
table.timeStamp('updated_at');
|
||||
});
|
||||
|
@ -32,11 +32,11 @@ class FootQuery extends Query<Foot, FootQueryWhere> {
|
|||
FootQuery({Set<String> trampoline}) {
|
||||
trampoline ??= Set();
|
||||
trampoline.add(tableName);
|
||||
_where = new FootQueryWhere(this);
|
||||
_where = FootQueryWhere(this);
|
||||
}
|
||||
|
||||
@override
|
||||
final FootQueryValues values = new FootQueryValues();
|
||||
final FootQueryValues values = FootQueryValues();
|
||||
|
||||
FootQueryWhere _where;
|
||||
|
||||
|
@ -62,12 +62,12 @@ class FootQuery extends Query<Foot, FootQueryWhere> {
|
|||
|
||||
@override
|
||||
FootQueryWhere newWhereClause() {
|
||||
return new FootQueryWhere(this);
|
||||
return FootQueryWhere(this);
|
||||
}
|
||||
|
||||
static Foot parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
var model = new Foot(
|
||||
var model = Foot(
|
||||
id: row[0].toString(),
|
||||
legId: (row[1] as int),
|
||||
nToes: double.parse(row[2].toString()),
|
||||
|
@ -84,11 +84,11 @@ class FootQuery extends Query<Foot, FootQueryWhere> {
|
|||
|
||||
class FootQueryWhere extends QueryWhere {
|
||||
FootQueryWhere(FootQuery query)
|
||||
: id = new NumericSqlExpressionBuilder<int>(query, 'id'),
|
||||
legId = new NumericSqlExpressionBuilder<int>(query, 'leg_id'),
|
||||
nToes = new NumericSqlExpressionBuilder<double>(query, 'n_toes'),
|
||||
createdAt = new DateTimeSqlExpressionBuilder(query, 'created_at'),
|
||||
updatedAt = new DateTimeSqlExpressionBuilder(query, 'updated_at');
|
||||
: id = NumericSqlExpressionBuilder<int>(query, 'id'),
|
||||
legId = NumericSqlExpressionBuilder<int>(query, 'leg_id'),
|
||||
nToes = NumericSqlExpressionBuilder<double>(query, 'n_toes'),
|
||||
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
|
||||
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at');
|
||||
|
||||
final NumericSqlExpressionBuilder<int> id;
|
||||
|
||||
|
@ -238,7 +238,7 @@ abstract class FootSerializer {
|
|||
}
|
||||
|
||||
abstract class FootFields {
|
||||
static const List<String> allFields = const <String>[
|
||||
static const List<String> allFields = <String>[
|
||||
id,
|
||||
legId,
|
||||
nToes,
|
||||
|
|
|
@ -32,11 +32,11 @@ class FruitQuery extends Query<Fruit, FruitQueryWhere> {
|
|||
FruitQuery({Set<String> trampoline}) {
|
||||
trampoline ??= Set();
|
||||
trampoline.add(tableName);
|
||||
_where = new FruitQueryWhere(this);
|
||||
_where = FruitQueryWhere(this);
|
||||
}
|
||||
|
||||
@override
|
||||
final FruitQueryValues values = new FruitQueryValues();
|
||||
final FruitQueryValues values = FruitQueryValues();
|
||||
|
||||
FruitQueryWhere _where;
|
||||
|
||||
|
@ -62,12 +62,12 @@ class FruitQuery extends Query<Fruit, FruitQueryWhere> {
|
|||
|
||||
@override
|
||||
FruitQueryWhere newWhereClause() {
|
||||
return new FruitQueryWhere(this);
|
||||
return FruitQueryWhere(this);
|
||||
}
|
||||
|
||||
static Fruit parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
var model = new Fruit(
|
||||
var model = Fruit(
|
||||
id: row[0].toString(),
|
||||
treeId: (row[1] as int),
|
||||
commonName: (row[2] as String),
|
||||
|
@ -84,11 +84,11 @@ class FruitQuery extends Query<Fruit, FruitQueryWhere> {
|
|||
|
||||
class FruitQueryWhere extends QueryWhere {
|
||||
FruitQueryWhere(FruitQuery query)
|
||||
: id = new NumericSqlExpressionBuilder<int>(query, 'id'),
|
||||
treeId = new NumericSqlExpressionBuilder<int>(query, 'tree_id'),
|
||||
commonName = new StringSqlExpressionBuilder(query, 'common_name'),
|
||||
createdAt = new DateTimeSqlExpressionBuilder(query, 'created_at'),
|
||||
updatedAt = new DateTimeSqlExpressionBuilder(query, 'updated_at');
|
||||
: id = NumericSqlExpressionBuilder<int>(query, 'id'),
|
||||
treeId = NumericSqlExpressionBuilder<int>(query, 'tree_id'),
|
||||
commonName = StringSqlExpressionBuilder(query, 'common_name'),
|
||||
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
|
||||
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at');
|
||||
|
||||
final NumericSqlExpressionBuilder<int> id;
|
||||
|
||||
|
@ -239,7 +239,7 @@ abstract class FruitSerializer {
|
|||
}
|
||||
|
||||
abstract class FruitFields {
|
||||
static const List<String> allFields = const <String>[
|
||||
static const List<String> allFields = <String>[
|
||||
id,
|
||||
treeId,
|
||||
commonName,
|
||||
|
|
|
@ -31,11 +31,11 @@ class HasCarQuery extends Query<HasCar, HasCarQueryWhere> {
|
|||
HasCarQuery({Set<String> trampoline}) {
|
||||
trampoline ??= Set();
|
||||
trampoline.add(tableName);
|
||||
_where = new HasCarQueryWhere(this);
|
||||
_where = HasCarQueryWhere(this);
|
||||
}
|
||||
|
||||
@override
|
||||
final HasCarQueryValues values = new HasCarQueryValues();
|
||||
final HasCarQueryValues values = HasCarQueryValues();
|
||||
|
||||
HasCarQueryWhere _where;
|
||||
|
||||
|
@ -61,12 +61,12 @@ class HasCarQuery extends Query<HasCar, HasCarQueryWhere> {
|
|||
|
||||
@override
|
||||
HasCarQueryWhere newWhereClause() {
|
||||
return new HasCarQueryWhere(this);
|
||||
return HasCarQueryWhere(this);
|
||||
}
|
||||
|
||||
static HasCar parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
var model = new HasCar(
|
||||
var model = HasCar(
|
||||
id: row[0].toString(),
|
||||
type: CarType.values[(row[1] as int)],
|
||||
createdAt: (row[2] as DateTime),
|
||||
|
@ -82,11 +82,10 @@ class HasCarQuery extends Query<HasCar, HasCarQueryWhere> {
|
|||
|
||||
class HasCarQueryWhere extends QueryWhere {
|
||||
HasCarQueryWhere(HasCarQuery query)
|
||||
: id = new NumericSqlExpressionBuilder<int>(query, 'id'),
|
||||
type = new EnumSqlExpressionBuilder<CarType>(
|
||||
query, 'type', (v) => v.index),
|
||||
createdAt = new DateTimeSqlExpressionBuilder(query, 'created_at'),
|
||||
updatedAt = new DateTimeSqlExpressionBuilder(query, 'updated_at');
|
||||
: id = NumericSqlExpressionBuilder<int>(query, 'id'),
|
||||
type = EnumSqlExpressionBuilder<CarType>(query, 'type', (v) => v.index),
|
||||
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
|
||||
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at');
|
||||
|
||||
final NumericSqlExpressionBuilder<int> id;
|
||||
|
||||
|
@ -227,7 +226,7 @@ abstract class HasCarSerializer {
|
|||
}
|
||||
|
||||
abstract class HasCarFields {
|
||||
static const List<String> allFields = const <String>[
|
||||
static const List<String> allFields = <String>[
|
||||
id,
|
||||
type,
|
||||
createdAt,
|
||||
|
|
|
@ -10,8 +10,8 @@ class HasMapMigration extends Migration {
|
|||
@override
|
||||
up(Schema schema) {
|
||||
schema.create('has_maps', (table) {
|
||||
table.declare('value', new ColumnType('jsonb'));
|
||||
table.declare('list', new ColumnType('jsonb'));
|
||||
table.declare('value', ColumnType('jsonb'));
|
||||
table.declare('list', ColumnType('jsonb'));
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -29,11 +29,11 @@ class HasMapQuery extends Query<HasMap, HasMapQueryWhere> {
|
|||
HasMapQuery({Set<String> trampoline}) {
|
||||
trampoline ??= Set();
|
||||
trampoline.add(tableName);
|
||||
_where = new HasMapQueryWhere(this);
|
||||
_where = HasMapQueryWhere(this);
|
||||
}
|
||||
|
||||
@override
|
||||
final HasMapQueryValues values = new HasMapQueryValues();
|
||||
final HasMapQueryValues values = HasMapQueryValues();
|
||||
|
||||
HasMapQueryWhere _where;
|
||||
|
||||
|
@ -59,12 +59,12 @@ class HasMapQuery extends Query<HasMap, HasMapQueryWhere> {
|
|||
|
||||
@override
|
||||
HasMapQueryWhere newWhereClause() {
|
||||
return new HasMapQueryWhere(this);
|
||||
return HasMapQueryWhere(this);
|
||||
}
|
||||
|
||||
static HasMap parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
var model = new HasMap(
|
||||
var model = HasMap(
|
||||
value: (row[0] as Map<dynamic, dynamic>),
|
||||
list: (row[1] as List<dynamic>));
|
||||
return model;
|
||||
|
@ -78,8 +78,8 @@ class HasMapQuery extends Query<HasMap, HasMapQueryWhere> {
|
|||
|
||||
class HasMapQueryWhere extends QueryWhere {
|
||||
HasMapQueryWhere(HasMapQuery query)
|
||||
: value = new MapSqlExpressionBuilder(query, 'value'),
|
||||
list = new ListSqlExpressionBuilder(query, 'list');
|
||||
: value = MapSqlExpressionBuilder(query, 'value'),
|
||||
list = ListSqlExpressionBuilder(query, 'list');
|
||||
|
||||
final MapSqlExpressionBuilder value;
|
||||
|
||||
|
@ -174,7 +174,7 @@ abstract class HasMapSerializer {
|
|||
}
|
||||
|
||||
abstract class HasMapFields {
|
||||
static const List<String> allFields = const <String>[value, list];
|
||||
static const List<String> allFields = <String>[value, list];
|
||||
|
||||
static const String value = 'value';
|
||||
|
||||
|
|
|
@ -2,27 +2,6 @@
|
|||
|
||||
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.varChar('name');
|
||||
table.timeStamp('created_at');
|
||||
table.timeStamp('updated_at');
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
down(Schema schema) {
|
||||
schema.drop('legs');
|
||||
}
|
||||
}
|
||||
|
||||
// **************************************************************************
|
||||
// OrmGenerator
|
||||
// **************************************************************************
|
||||
|
@ -31,17 +10,11 @@ class LegQuery extends Query<Leg, LegQueryWhere> {
|
|||
LegQuery({Set<String> trampoline}) {
|
||||
trampoline ??= Set();
|
||||
trampoline.add(tableName);
|
||||
_where = new LegQueryWhere(this);
|
||||
leftJoin('feet', 'id', 'leg_id', additionalFields: const [
|
||||
'leg_id',
|
||||
'n_toes',
|
||||
'created_at',
|
||||
'updated_at'
|
||||
]);
|
||||
_where = LegQueryWhere(this);
|
||||
}
|
||||
|
||||
@override
|
||||
final LegQueryValues values = new LegQueryValues();
|
||||
final LegQueryValues values = LegQueryValues();
|
||||
|
||||
LegQueryWhere _where;
|
||||
|
||||
|
@ -57,7 +30,7 @@ class LegQuery extends Query<Leg, LegQueryWhere> {
|
|||
|
||||
@override
|
||||
get fields {
|
||||
return const ['id', 'name', 'created_at', 'updated_at'];
|
||||
return const ['id'];
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -67,19 +40,12 @@ class LegQuery extends Query<Leg, LegQueryWhere> {
|
|||
|
||||
@override
|
||||
LegQueryWhere newWhereClause() {
|
||||
return new LegQueryWhere(this);
|
||||
return LegQueryWhere(this);
|
||||
}
|
||||
|
||||
static Leg parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
var model = new Leg(
|
||||
id: row[0].toString(),
|
||||
name: (row[1] as String),
|
||||
createdAt: (row[2] as DateTime),
|
||||
updatedAt: (row[3] as DateTime));
|
||||
if (row.length > 4) {
|
||||
model = model.copyWith(foot: FootQuery.parseRow(row.skip(4).toList()));
|
||||
}
|
||||
var model = Leg(id: row[0].toString());
|
||||
return model;
|
||||
}
|
||||
|
||||
|
@ -91,22 +57,13 @@ class LegQuery extends Query<Leg, LegQueryWhere> {
|
|||
|
||||
class LegQueryWhere extends QueryWhere {
|
||||
LegQueryWhere(LegQuery query)
|
||||
: id = new NumericSqlExpressionBuilder<int>(query, 'id'),
|
||||
name = new StringSqlExpressionBuilder(query, 'name'),
|
||||
createdAt = new DateTimeSqlExpressionBuilder(query, 'created_at'),
|
||||
updatedAt = new DateTimeSqlExpressionBuilder(query, 'updated_at');
|
||||
: id = NumericSqlExpressionBuilder<int>(query, 'id');
|
||||
|
||||
final NumericSqlExpressionBuilder<int> id;
|
||||
|
||||
final StringSqlExpressionBuilder name;
|
||||
|
||||
final DateTimeSqlExpressionBuilder createdAt;
|
||||
|
||||
final DateTimeSqlExpressionBuilder updatedAt;
|
||||
|
||||
@override
|
||||
get expressionBuilders {
|
||||
return [id, name, createdAt, updatedAt];
|
||||
return [id];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -121,26 +78,7 @@ class LegQueryValues extends MapQueryValues {
|
|||
}
|
||||
|
||||
set id(int value) => values['id'] = value;
|
||||
String get name {
|
||||
return (values['name'] as String);
|
||||
}
|
||||
|
||||
set name(String value) => values['name'] = 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(Leg model) {
|
||||
name = model.name;
|
||||
createdAt = model.createdAt;
|
||||
updatedAt = model.updatedAt;
|
||||
}
|
||||
void copyFrom(Leg model) {}
|
||||
}
|
||||
|
||||
// **************************************************************************
|
||||
|
@ -155,7 +93,7 @@ class Leg extends _Leg {
|
|||
final String id;
|
||||
|
||||
@override
|
||||
final Foot foot;
|
||||
final dynamic foot;
|
||||
|
||||
@override
|
||||
final String name;
|
||||
|
@ -168,7 +106,7 @@ class Leg extends _Leg {
|
|||
|
||||
Leg copyWith(
|
||||
{String id,
|
||||
Foot foot,
|
||||
dynamic foot,
|
||||
String name,
|
||||
DateTime createdAt,
|
||||
DateTime updatedAt}) {
|
||||
|
@ -207,9 +145,7 @@ abstract class LegSerializer {
|
|||
static Leg fromMap(Map map) {
|
||||
return new Leg(
|
||||
id: map['id'] as String,
|
||||
foot: map['foot'] != null
|
||||
? FootSerializer.fromMap(map['foot'] as Map)
|
||||
: null,
|
||||
foot: map['foot'] as dynamic,
|
||||
name: map['name'] as String,
|
||||
createdAt: map['created_at'] != null
|
||||
? (map['created_at'] is DateTime
|
||||
|
@ -229,7 +165,7 @@ abstract class LegSerializer {
|
|||
}
|
||||
return {
|
||||
'id': model.id,
|
||||
'foot': FootSerializer.toMap(model.foot),
|
||||
'foot': model.foot,
|
||||
'name': model.name,
|
||||
'created_at': model.createdAt?.toIso8601String(),
|
||||
'updated_at': model.updatedAt?.toIso8601String()
|
||||
|
@ -238,7 +174,7 @@ abstract class LegSerializer {
|
|||
}
|
||||
|
||||
abstract class LegFields {
|
||||
static const List<String> allFields = const <String>[
|
||||
static const List<String> allFields = <String>[
|
||||
id,
|
||||
foot,
|
||||
name,
|
||||
|
|
|
@ -2,30 +2,6 @@
|
|||
|
||||
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.integer('employee_id');
|
||||
table.timeStamp('order_date');
|
||||
table.integer('shipper_id');
|
||||
table.timeStamp('created_at');
|
||||
table.timeStamp('updated_at');
|
||||
table.integer('customer_id').references('customers', 'id');
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
down(Schema schema) {
|
||||
schema.drop('orders');
|
||||
}
|
||||
}
|
||||
|
||||
// **************************************************************************
|
||||
// OrmGenerator
|
||||
// **************************************************************************
|
||||
|
@ -34,13 +10,11 @@ class OrderQuery extends Query<Order, OrderQueryWhere> {
|
|||
OrderQuery({Set<String> trampoline}) {
|
||||
trampoline ??= Set();
|
||||
trampoline.add(tableName);
|
||||
_where = new OrderQueryWhere(this);
|
||||
leftJoin('customers', 'customer_id', 'id',
|
||||
additionalFields: const ['created_at', 'updated_at']);
|
||||
_where = OrderQueryWhere(this);
|
||||
}
|
||||
|
||||
@override
|
||||
final OrderQueryValues values = new OrderQueryValues();
|
||||
final OrderQueryValues values = OrderQueryValues();
|
||||
|
||||
OrderQueryWhere _where;
|
||||
|
||||
|
@ -56,15 +30,7 @@ class OrderQuery extends Query<Order, OrderQueryWhere> {
|
|||
|
||||
@override
|
||||
get fields {
|
||||
return const [
|
||||
'id',
|
||||
'customer_id',
|
||||
'employee_id',
|
||||
'order_date',
|
||||
'shipper_id',
|
||||
'created_at',
|
||||
'updated_at'
|
||||
];
|
||||
return const ['id'];
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -74,22 +40,12 @@ class OrderQuery extends Query<Order, OrderQueryWhere> {
|
|||
|
||||
@override
|
||||
OrderQueryWhere newWhereClause() {
|
||||
return new OrderQueryWhere(this);
|
||||
return OrderQueryWhere(this);
|
||||
}
|
||||
|
||||
static Order parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
var model = new Order(
|
||||
id: row[0].toString(),
|
||||
employeeId: (row[2] as int),
|
||||
orderDate: (row[3] as DateTime),
|
||||
shipperId: (row[4] as int),
|
||||
createdAt: (row[5] as DateTime),
|
||||
updatedAt: (row[6] as DateTime));
|
||||
if (row.length > 7) {
|
||||
model = model.copyWith(
|
||||
customer: CustomerQuery.parseRow(row.skip(7).toList()));
|
||||
}
|
||||
var model = Order(id: row[0].toString());
|
||||
return model;
|
||||
}
|
||||
|
||||
|
@ -101,39 +57,13 @@ class OrderQuery extends Query<Order, OrderQueryWhere> {
|
|||
|
||||
class OrderQueryWhere extends QueryWhere {
|
||||
OrderQueryWhere(OrderQuery query)
|
||||
: id = new NumericSqlExpressionBuilder<int>(query, 'id'),
|
||||
customerId = new NumericSqlExpressionBuilder<int>(query, 'customer_id'),
|
||||
employeeId = new NumericSqlExpressionBuilder<int>(query, 'employee_id'),
|
||||
orderDate = new DateTimeSqlExpressionBuilder(query, 'order_date'),
|
||||
shipperId = new NumericSqlExpressionBuilder<int>(query, 'shipper_id'),
|
||||
createdAt = new DateTimeSqlExpressionBuilder(query, 'created_at'),
|
||||
updatedAt = new DateTimeSqlExpressionBuilder(query, 'updated_at');
|
||||
: id = NumericSqlExpressionBuilder<int>(query, 'id');
|
||||
|
||||
final NumericSqlExpressionBuilder<int> id;
|
||||
|
||||
final NumericSqlExpressionBuilder<int> customerId;
|
||||
|
||||
final NumericSqlExpressionBuilder<int> employeeId;
|
||||
|
||||
final DateTimeSqlExpressionBuilder orderDate;
|
||||
|
||||
final NumericSqlExpressionBuilder<int> shipperId;
|
||||
|
||||
final DateTimeSqlExpressionBuilder createdAt;
|
||||
|
||||
final DateTimeSqlExpressionBuilder updatedAt;
|
||||
|
||||
@override
|
||||
get expressionBuilders {
|
||||
return [
|
||||
id,
|
||||
customerId,
|
||||
employeeId,
|
||||
orderDate,
|
||||
shipperId,
|
||||
createdAt,
|
||||
updatedAt
|
||||
];
|
||||
return [id];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -148,46 +78,7 @@ class OrderQueryValues extends MapQueryValues {
|
|||
}
|
||||
|
||||
set id(int value) => values['id'] = 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;
|
||||
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(Order model) {
|
||||
employeeId = model.employeeId;
|
||||
orderDate = model.orderDate;
|
||||
shipperId = model.shipperId;
|
||||
createdAt = model.createdAt;
|
||||
updatedAt = model.updatedAt;
|
||||
if (model.customer != null) {
|
||||
values['customer_id'] = int.parse(model.customer.id);
|
||||
}
|
||||
}
|
||||
void copyFrom(Order model) {}
|
||||
}
|
||||
|
||||
// **************************************************************************
|
||||
|
@ -209,7 +100,7 @@ class Order extends _Order {
|
|||
final String id;
|
||||
|
||||
@override
|
||||
final Customer customer;
|
||||
final dynamic customer;
|
||||
|
||||
@override
|
||||
final int employeeId;
|
||||
|
@ -228,7 +119,7 @@ class Order extends _Order {
|
|||
|
||||
Order copyWith(
|
||||
{String id,
|
||||
Customer customer,
|
||||
dynamic customer,
|
||||
int employeeId,
|
||||
DateTime orderDate,
|
||||
int shipperId,
|
||||
|
@ -274,9 +165,7 @@ abstract class OrderSerializer {
|
|||
static Order fromMap(Map map) {
|
||||
return new Order(
|
||||
id: map['id'] as String,
|
||||
customer: map['customer'] != null
|
||||
? CustomerSerializer.fromMap(map['customer'] as Map)
|
||||
: null,
|
||||
customer: map['customer'] as dynamic,
|
||||
employeeId: map['employee_id'] as int,
|
||||
orderDate: map['order_date'] != null
|
||||
? (map['order_date'] is DateTime
|
||||
|
@ -302,7 +191,7 @@ abstract class OrderSerializer {
|
|||
}
|
||||
return {
|
||||
'id': model.id,
|
||||
'customer': CustomerSerializer.toMap(model.customer),
|
||||
'customer': model.customer,
|
||||
'employee_id': model.employeeId,
|
||||
'order_date': model.orderDate?.toIso8601String(),
|
||||
'shipper_id': model.shipperId,
|
||||
|
@ -313,7 +202,7 @@ abstract class OrderSerializer {
|
|||
}
|
||||
|
||||
abstract class OrderFields {
|
||||
static const List<String> allFields = const <String>[
|
||||
static const List<String> allFields = <String>[
|
||||
id,
|
||||
customer,
|
||||
employeeId,
|
||||
|
|
|
@ -2,27 +2,6 @@
|
|||
|
||||
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.declare('rings', new ColumnType('smallint'));
|
||||
table.timeStamp('created_at');
|
||||
table.timeStamp('updated_at');
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
down(Schema schema) {
|
||||
schema.drop('trees');
|
||||
}
|
||||
}
|
||||
|
||||
// **************************************************************************
|
||||
// OrmGenerator
|
||||
// **************************************************************************
|
||||
|
@ -31,18 +10,11 @@ class TreeQuery extends Query<Tree, TreeQueryWhere> {
|
|||
TreeQuery({Set<String> trampoline}) {
|
||||
trampoline ??= Set();
|
||||
trampoline.add(tableName);
|
||||
_where = new TreeQueryWhere(this);
|
||||
leftJoin(new FruitQuery(trampoline: trampoline), 'id', 'tree_id',
|
||||
additionalFields: const [
|
||||
'tree_id',
|
||||
'common_name',
|
||||
'created_at',
|
||||
'updated_at'
|
||||
]);
|
||||
_where = TreeQueryWhere(this);
|
||||
}
|
||||
|
||||
@override
|
||||
final TreeQueryValues values = new TreeQueryValues();
|
||||
final TreeQueryValues values = TreeQueryValues();
|
||||
|
||||
TreeQueryWhere _where;
|
||||
|
||||
|
@ -58,7 +30,7 @@ class TreeQuery extends Query<Tree, TreeQueryWhere> {
|
|||
|
||||
@override
|
||||
get fields {
|
||||
return const ['id', 'rings', 'created_at', 'updated_at'];
|
||||
return const ['id', 'rings'];
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -68,22 +40,12 @@ class TreeQuery extends Query<Tree, TreeQueryWhere> {
|
|||
|
||||
@override
|
||||
TreeQueryWhere newWhereClause() {
|
||||
return new TreeQueryWhere(this);
|
||||
return TreeQueryWhere(this);
|
||||
}
|
||||
|
||||
static Tree parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
var model = new Tree(
|
||||
id: row[0].toString(),
|
||||
rings: (row[1] as int),
|
||||
createdAt: (row[2] as DateTime),
|
||||
updatedAt: (row[3] as DateTime));
|
||||
if (row.length > 4) {
|
||||
model = model.copyWith(
|
||||
fruits: [FruitQuery.parseRow(row.skip(4).toList())]
|
||||
.where((x) => x != null)
|
||||
.toList());
|
||||
}
|
||||
var model = Tree(id: row[0].toString(), rings: (row[1] as int));
|
||||
return model;
|
||||
}
|
||||
|
||||
|
@ -91,83 +53,20 @@ class TreeQuery extends Query<Tree, TreeQueryWhere> {
|
|||
deserialize(List row) {
|
||||
return parseRow(row);
|
||||
}
|
||||
|
||||
@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 = new NumericSqlExpressionBuilder<int>(query, 'id'),
|
||||
rings = new NumericSqlExpressionBuilder<int>(query, 'rings'),
|
||||
createdAt = new DateTimeSqlExpressionBuilder(query, 'created_at'),
|
||||
updatedAt = new DateTimeSqlExpressionBuilder(query, 'updated_at');
|
||||
: id = NumericSqlExpressionBuilder<int>(query, 'id'),
|
||||
rings = NumericSqlExpressionBuilder<int>(query, 'rings');
|
||||
|
||||
final NumericSqlExpressionBuilder<int> id;
|
||||
|
||||
final NumericSqlExpressionBuilder<int> rings;
|
||||
|
||||
final DateTimeSqlExpressionBuilder createdAt;
|
||||
|
||||
final DateTimeSqlExpressionBuilder updatedAt;
|
||||
|
||||
@override
|
||||
get expressionBuilders {
|
||||
return [id, rings, createdAt, updatedAt];
|
||||
return [id, rings];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -187,20 +86,8 @@ class TreeQueryValues extends MapQueryValues {
|
|||
}
|
||||
|
||||
set rings(int value) => values['rings'] = 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(Tree model) {
|
||||
rings = model.rings;
|
||||
createdAt = model.createdAt;
|
||||
updatedAt = model.updatedAt;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -211,7 +98,11 @@ class TreeQueryValues extends MapQueryValues {
|
|||
@generatedSerializable
|
||||
class Tree extends _Tree {
|
||||
Tree(
|
||||
{this.id, this.rings, List<Fruit> fruits, this.createdAt, this.updatedAt})
|
||||
{this.id,
|
||||
this.rings,
|
||||
List<dynamic> fruits,
|
||||
this.createdAt,
|
||||
this.updatedAt})
|
||||
: this.fruits = new List.unmodifiable(fruits ?? []);
|
||||
|
||||
@override
|
||||
|
@ -221,7 +112,7 @@ class Tree extends _Tree {
|
|||
final int rings;
|
||||
|
||||
@override
|
||||
final List<Fruit> fruits;
|
||||
final List<dynamic> fruits;
|
||||
|
||||
@override
|
||||
final DateTime createdAt;
|
||||
|
@ -232,7 +123,7 @@ class Tree extends _Tree {
|
|||
Tree copyWith(
|
||||
{String id,
|
||||
int rings,
|
||||
List<Fruit> fruits,
|
||||
List<dynamic> fruits,
|
||||
DateTime createdAt,
|
||||
DateTime updatedAt}) {
|
||||
return new Tree(
|
||||
|
@ -247,7 +138,7 @@ class Tree extends _Tree {
|
|||
return other is _Tree &&
|
||||
other.id == id &&
|
||||
other.rings == rings &&
|
||||
const ListEquality<Fruit>(const DefaultEquality<Fruit>())
|
||||
const ListEquality<dynamic>(const DefaultEquality())
|
||||
.equals(other.fruits, fruits) &&
|
||||
other.createdAt == createdAt &&
|
||||
other.updatedAt == updatedAt;
|
||||
|
@ -273,9 +164,7 @@ abstract class TreeSerializer {
|
|||
id: map['id'] as String,
|
||||
rings: map['rings'] as int,
|
||||
fruits: map['fruits'] is Iterable
|
||||
? new List.unmodifiable(((map['fruits'] as Iterable)
|
||||
.where((x) => x is Map) as Iterable<Map>)
|
||||
.map(FruitSerializer.fromMap))
|
||||
? (map['fruits'] as Iterable).cast<dynamic>().toList()
|
||||
: null,
|
||||
createdAt: map['created_at'] != null
|
||||
? (map['created_at'] is DateTime
|
||||
|
@ -296,7 +185,7 @@ abstract class TreeSerializer {
|
|||
return {
|
||||
'id': model.id,
|
||||
'rings': model.rings,
|
||||
'fruits': model.fruits?.map((m) => FruitSerializer.toMap(m))?.toList(),
|
||||
'fruits': model.fruits,
|
||||
'created_at': model.createdAt?.toIso8601String(),
|
||||
'updated_at': model.updatedAt?.toIso8601String()
|
||||
};
|
||||
|
@ -304,7 +193,7 @@ abstract class TreeSerializer {
|
|||
}
|
||||
|
||||
abstract class TreeFields {
|
||||
static const List<String> allFields = const <String>[
|
||||
static const List<String> allFields = <String>[
|
||||
id,
|
||||
rings,
|
||||
fruits,
|
||||
|
|
|
@ -68,11 +68,11 @@ class UserQuery extends Query<User, UserQueryWhere> {
|
|||
UserQuery({Set<String> trampoline}) {
|
||||
trampoline ??= Set();
|
||||
trampoline.add(tableName);
|
||||
_where = new UserQueryWhere(this);
|
||||
_where = UserQueryWhere(this);
|
||||
}
|
||||
|
||||
@override
|
||||
final UserQueryValues values = new UserQueryValues();
|
||||
final UserQueryValues values = UserQueryValues();
|
||||
|
||||
UserQueryWhere _where;
|
||||
|
||||
|
@ -105,12 +105,12 @@ class UserQuery extends Query<User, UserQueryWhere> {
|
|||
|
||||
@override
|
||||
UserQueryWhere newWhereClause() {
|
||||
return new UserQueryWhere(this);
|
||||
return UserQueryWhere(this);
|
||||
}
|
||||
|
||||
static User parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
var model = new User(
|
||||
var model = User(
|
||||
id: row[0].toString(),
|
||||
username: (row[1] as String),
|
||||
password: (row[2] as String),
|
||||
|
@ -128,12 +128,12 @@ class UserQuery extends Query<User, UserQueryWhere> {
|
|||
|
||||
class UserQueryWhere extends QueryWhere {
|
||||
UserQueryWhere(UserQuery query)
|
||||
: id = new NumericSqlExpressionBuilder<int>(query, 'id'),
|
||||
username = new StringSqlExpressionBuilder(query, 'username'),
|
||||
password = new StringSqlExpressionBuilder(query, 'password'),
|
||||
email = new StringSqlExpressionBuilder(query, 'email'),
|
||||
createdAt = new DateTimeSqlExpressionBuilder(query, 'created_at'),
|
||||
updatedAt = new DateTimeSqlExpressionBuilder(query, 'updated_at');
|
||||
: id = NumericSqlExpressionBuilder<int>(query, 'id'),
|
||||
username = StringSqlExpressionBuilder(query, 'username'),
|
||||
password = StringSqlExpressionBuilder(query, 'password'),
|
||||
email = StringSqlExpressionBuilder(query, 'email'),
|
||||
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
|
||||
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at');
|
||||
|
||||
final NumericSqlExpressionBuilder<int> id;
|
||||
|
||||
|
@ -202,10 +202,11 @@ class RoleUserQuery extends Query<RoleUser, RoleUserQueryWhere> {
|
|||
RoleUserQuery({Set<String> trampoline}) {
|
||||
trampoline ??= Set();
|
||||
trampoline.add(tableName);
|
||||
_where = new RoleUserQueryWhere(this);
|
||||
_where = RoleUserQueryWhere(this);
|
||||
leftJoin('roles', 'role_id', 'id',
|
||||
additionalFields: const ['name', 'created_at', 'updated_at']);
|
||||
additionalFields: const ['id', 'name', 'created_at', 'updated_at']);
|
||||
leftJoin('users', 'user_id', 'id', additionalFields: const [
|
||||
'id',
|
||||
'username',
|
||||
'password',
|
||||
'email',
|
||||
|
@ -215,7 +216,7 @@ class RoleUserQuery extends Query<RoleUser, RoleUserQueryWhere> {
|
|||
}
|
||||
|
||||
@override
|
||||
final RoleUserQueryValues values = new RoleUserQueryValues();
|
||||
final RoleUserQueryValues values = RoleUserQueryValues();
|
||||
|
||||
RoleUserQueryWhere _where;
|
||||
|
||||
|
@ -241,12 +242,12 @@ class RoleUserQuery extends Query<RoleUser, RoleUserQueryWhere> {
|
|||
|
||||
@override
|
||||
RoleUserQueryWhere newWhereClause() {
|
||||
return new RoleUserQueryWhere(this);
|
||||
return RoleUserQueryWhere(this);
|
||||
}
|
||||
|
||||
static RoleUser parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
var model = new RoleUser(
|
||||
var model = RoleUser(
|
||||
id: row[0].toString(),
|
||||
createdAt: (row[3] as DateTime),
|
||||
updatedAt: (row[4] as DateTime));
|
||||
|
@ -267,11 +268,11 @@ class RoleUserQuery extends Query<RoleUser, RoleUserQueryWhere> {
|
|||
|
||||
class RoleUserQueryWhere extends QueryWhere {
|
||||
RoleUserQueryWhere(RoleUserQuery query)
|
||||
: id = new NumericSqlExpressionBuilder<int>(query, 'id'),
|
||||
roleId = new NumericSqlExpressionBuilder<int>(query, 'role_id'),
|
||||
userId = new NumericSqlExpressionBuilder<int>(query, 'user_id'),
|
||||
createdAt = new DateTimeSqlExpressionBuilder(query, 'created_at'),
|
||||
updatedAt = new DateTimeSqlExpressionBuilder(query, 'updated_at');
|
||||
: id = NumericSqlExpressionBuilder<int>(query, 'id'),
|
||||
roleId = NumericSqlExpressionBuilder<int>(query, 'role_id'),
|
||||
userId = NumericSqlExpressionBuilder<int>(query, 'user_id'),
|
||||
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
|
||||
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at');
|
||||
|
||||
final NumericSqlExpressionBuilder<int> id;
|
||||
|
||||
|
@ -336,11 +337,11 @@ class RoleQuery extends Query<Role, RoleQueryWhere> {
|
|||
RoleQuery({Set<String> trampoline}) {
|
||||
trampoline ??= Set();
|
||||
trampoline.add(tableName);
|
||||
_where = new RoleQueryWhere(this);
|
||||
_where = RoleQueryWhere(this);
|
||||
}
|
||||
|
||||
@override
|
||||
final RoleQueryValues values = new RoleQueryValues();
|
||||
final RoleQueryValues values = RoleQueryValues();
|
||||
|
||||
RoleQueryWhere _where;
|
||||
|
||||
|
@ -366,12 +367,12 @@ class RoleQuery extends Query<Role, RoleQueryWhere> {
|
|||
|
||||
@override
|
||||
RoleQueryWhere newWhereClause() {
|
||||
return new RoleQueryWhere(this);
|
||||
return RoleQueryWhere(this);
|
||||
}
|
||||
|
||||
static Role parseRow(List row) {
|
||||
if (row.every((x) => x == null)) return null;
|
||||
var model = new Role(
|
||||
var model = Role(
|
||||
id: row[0].toString(),
|
||||
name: (row[1] as String),
|
||||
createdAt: (row[2] as DateTime),
|
||||
|
@ -387,10 +388,10 @@ class RoleQuery extends Query<Role, RoleQueryWhere> {
|
|||
|
||||
class RoleQueryWhere extends QueryWhere {
|
||||
RoleQueryWhere(RoleQuery query)
|
||||
: id = new NumericSqlExpressionBuilder<int>(query, 'id'),
|
||||
name = new StringSqlExpressionBuilder(query, 'name'),
|
||||
createdAt = new DateTimeSqlExpressionBuilder(query, 'created_at'),
|
||||
updatedAt = new DateTimeSqlExpressionBuilder(query, 'updated_at');
|
||||
: id = NumericSqlExpressionBuilder<int>(query, 'id'),
|
||||
name = StringSqlExpressionBuilder(query, 'name'),
|
||||
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
|
||||
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at');
|
||||
|
||||
final NumericSqlExpressionBuilder<int> id;
|
||||
|
||||
|
@ -635,8 +636,9 @@ abstract class UserSerializer {
|
|||
password: map['password'] as String,
|
||||
email: map['email'] as String,
|
||||
roles: map['roles'] is Iterable
|
||||
? new List.unmodifiable(((map['roles'] as Iterable)
|
||||
.where((x) => x is Map) as Iterable<Map>)
|
||||
? new List.unmodifiable(
|
||||
((map['roles'] as Iterable).where((x) => x is Map))
|
||||
.cast<Map>()
|
||||
.map(RoleSerializer.fromMap))
|
||||
: null,
|
||||
createdAt: map['created_at'] != null
|
||||
|
@ -668,7 +670,7 @@ abstract class UserSerializer {
|
|||
}
|
||||
|
||||
abstract class UserFields {
|
||||
static const List<String> allFields = const <String>[
|
||||
static const List<String> allFields = <String>[
|
||||
id,
|
||||
username,
|
||||
password,
|
||||
|
@ -730,7 +732,7 @@ abstract class RoleUserSerializer {
|
|||
}
|
||||
|
||||
abstract class RoleUserFields {
|
||||
static const List<String> allFields = const <String>[
|
||||
static const List<String> allFields = <String>[
|
||||
id,
|
||||
role,
|
||||
user,
|
||||
|
@ -755,8 +757,9 @@ abstract class RoleSerializer {
|
|||
id: map['id'] as String,
|
||||
name: map['name'] as String,
|
||||
users: map['users'] is Iterable
|
||||
? new List.unmodifiable(((map['users'] as Iterable)
|
||||
.where((x) => x is Map) as Iterable<Map>)
|
||||
? new List.unmodifiable(
|
||||
((map['users'] as Iterable).where((x) => x is Map))
|
||||
.cast<Map>()
|
||||
.map(UserSerializer.fromMap))
|
||||
: null,
|
||||
createdAt: map['created_at'] != null
|
||||
|
@ -786,7 +789,7 @@ abstract class RoleSerializer {
|
|||
}
|
||||
|
||||
abstract class RoleFields {
|
||||
static const List<String> allFields = const <String>[
|
||||
static const List<String> allFields = <String>[
|
||||
id,
|
||||
name,
|
||||
users,
|
||||
|
|
Loading…
Reference in a new issue