diff --git a/angel_orm/lib/src/query.dart b/angel_orm/lib/src/query.dart index 97749160..aced78f3 100644 --- a/angel_orm/lib/src/query.dart +++ b/angel_orm/lib/src/query.dart @@ -451,7 +451,11 @@ class Union extends QueryBase { final QueryBase left, right; final bool all; - Union(this.left, this.right, {this.all: false}); + Union(this.left, this.right, {this.all: false}) { + substitutionValues + ..addAll(left.substitutionValues) + ..addAll(right.substitutionValues); + } @override List get fields => left.fields; diff --git a/angel_orm_generator/CHANGELOG.md b/angel_orm_generator/CHANGELOG.md index 7141514b..374dd012 100644 --- a/angel_orm_generator/CHANGELOG.md +++ b/angel_orm_generator/CHANGELOG.md @@ -1,3 +1,6 @@ +# 2.0.0-dev.2 +* Changes to work with `package:angel_orm@2.0.0-dev.15`. + # 2.0.0-dev.1 * Generate migration files. diff --git a/angel_orm_generator/lib/src/migration_generator.dart b/angel_orm_generator/lib/src/migration_generator.dart index 7ef38d44..28911ac4 100644 --- a/angel_orm_generator/lib/src/migration_generator.dart +++ b/angel_orm_generator/lib/src/migration_generator.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'package:analyzer/dart/element/element.dart'; import 'package:angel_orm/angel_orm.dart'; +import 'package:angel_serialize_generator/angel_serialize_generator.dart'; import 'package:build/build.dart'; import 'package:code_builder/code_builder.dart'; import 'package:dart_style/dart_style.dart'; @@ -168,9 +169,14 @@ class MigrationGenerator extends GeneratorForAnnotation { var field = table.property(methodName).call(positional, named); var cascade = []; - if (col.defaultValue != null) { - cascade - .add(refer('defaultsTo').call([literal(col.defaultValue)])); + var defaultValue = ctx.buildContext.defaults[name]; + + if (defaultValue != null) { + cascade.add(refer('defaultsTo').call([ + new CodeExpression( + new Code(dartObjectToString(defaultValue)), + ), + ])); } if (col.indexType == IndexType.primaryKey || diff --git a/angel_orm_generator/lib/src/orm_build_context.dart b/angel_orm_generator/lib/src/orm_build_context.dart index 46808d78..4d9d0ea2 100644 --- a/angel_orm_generator/lib/src/orm_build_context.dart +++ b/angel_orm_generator/lib/src/orm_build_context.dart @@ -86,7 +86,6 @@ Future buildOrmContext( isNullable: column.isNullable, length: column.length, indexType: column.indexType, - defaultValue: column.defaultValue, type: inferColumnType(field.type), ); } @@ -233,7 +232,6 @@ Column reviveColumn(ConstantReader cr) { return new Column( isNullable: cr.peek('isNullable')?.boolValue, length: cr.peek('length')?.intValue, - defaultValue: cr.peek('defaultValue')?.literalValue, type: columnType, indexType: indexType, ); diff --git a/angel_orm_generator/lib/src/orm_generator.dart b/angel_orm_generator/lib/src/orm_generator.dart index 84d48cba..52d6eadd 100644 --- a/angel_orm_generator/lib/src/orm_generator.dart +++ b/angel_orm_generator/lib/src/orm_generator.dart @@ -105,23 +105,30 @@ class OrmGenerator extends GeneratorForAnnotation { }); })); - // Add where member + // Add _where member clazz.fields.add(new Field((b) { b - ..annotations.add(refer('override')) - ..name = 'where' - ..modifier = FieldModifier.final$ - ..type = queryWhereType - ..assignment = queryWhereType.newInstance([]).code; + ..name = '_where' + ..type = queryWhereType; })); + // Add where getter + clazz.methods.add(new Method((b) { + b + ..name = 'where' + ..type = MethodType.getter + ..returns = queryWhereType + ..annotations.add(refer('override')) + ..body = new Block((b) => b.addExpression(refer('_where').returned)); + })); + // newWhereClause() clazz.methods.add(new Method((b) { b ..name = 'newWhereClause' ..annotations.add(refer('override')) ..returns = queryWhereType - ..body = new Block( - (b) => b.addExpression(queryWhereType.newInstance([]).returned)); + ..body = new Block((b) => b.addExpression( + queryWhereType.newInstance([refer('this')]).returned)); })); // Add deserialize() @@ -197,88 +204,91 @@ class OrmGenerator extends GeneratorForAnnotation { })); // If there are any relations, we need some overrides. + clazz.constructors.add(new Constructor((b) { + b + ..body = new Block((b) { + // Add a constructor that initializes _where + b.addExpression( + refer('_where') + .assign(queryWhereType.newInstance([refer('this')])), + ); + + ctx.relations.forEach((fieldName, relation) { + //var name = ctx.buildContext.resolveFieldName(fieldName); + if (relation.type == RelationshipType.belongsTo || + relation.type == RelationshipType.hasOne) { + var foreign = ctx.relationTypes[relation]; + var additionalFields = foreign.effectiveFields + .where((f) => f.name != 'id' || !isSpecialId(f)) + .map((f) => literalString( + foreign.buildContext.resolveFieldName(f.name))); + var joinArgs = [ + relation.foreignTable, + relation.localKey, + relation.foreignKey + ].map(literalString); + b.addExpression(refer('leftJoin').call(joinArgs, { + 'additionalFields': + literalConstList(additionalFields.toList()) + })); + } + }); + }); + })); if (ctx.relations.isNotEmpty) { - clazz.constructors.add(new Constructor((b) { + clazz.methods.add(new Method((b) { b + ..name = 'insert' + ..annotations.add(refer('override')) + ..requiredParameters.add(new Parameter((b) => b..name = 'executor')) ..body = new Block((b) { - ctx.relations.forEach((fieldName, relation) { - //var name = ctx.buildContext.resolveFieldName(fieldName); - if (relation.type == RelationshipType.belongsTo || - relation.type == RelationshipType.hasOne) { - var foreign = ctx.relationTypes[relation]; - var additionalFields = foreign.effectiveFields - .where((f) => f.name != 'id' || !isSpecialId(f)) - .map((f) => literalString( - foreign.buildContext.resolveFieldName(f.name))); - var joinArgs = [ - relation.foreignTable, - relation.localKey, - relation.foreignKey - ].map(literalString); - b.addExpression(refer('leftJoin').call(joinArgs, { - 'additionalFields': - literalConstList(additionalFields.toList()) - })); - } + var inTransaction = new Method((b) { + b + ..modifier = MethodModifier.async + ..body = new Block((b) { + b.addExpression(refer('super') + .property('insert') + .call([refer('executor')]) + .awaited + .assignVar('result')); + + // Just call getOne() again + if (ctx.effectiveFields.any((f) => + isSpecialId(f) || + (ctx.columns[f.name]?.indexType == + IndexType.primaryKey))) { + b.addExpression(refer('where') + .property('id') + .property('equals') + .call([ + (refer('int') + .property('parse') + .call([refer('result').property('id')])) + ])); + + b.addExpression(refer('result').assign( + refer('getOne').call([refer('executor')]).awaited)); + } + + // Fetch the results of @hasMany + ctx.relations.forEach((name, relation) { + if (relation.type == RelationshipType.hasMany) { + // Call fetchLinked(); + var fetchLinked = refer('fetchLinked') + .call([refer('result'), refer('executor')]).awaited; + b.addExpression(refer('result').assign(fetchLinked)); + } + }); + + b.addExpression(refer('result').returned); + }); }); + + b.addExpression(refer('executor') + .property('transaction') + .call([inTransaction.closure]).returned); }); })); - if (ctx.relations.isNotEmpty) { - clazz.methods.add(new Method((b) { - b - ..name = 'insert' - ..annotations.add(refer('override')) - ..requiredParameters - .add(new Parameter((b) => b..name = 'executor')) - ..body = new Block((b) { - var inTransaction = new Method((b) { - b - ..modifier = MethodModifier.async - ..body = new Block((b) { - b.addExpression(refer('super') - .property('insert') - .call([refer('executor')]) - .awaited - .assignVar('result')); - - // Just call getOne() again - if (ctx.effectiveFields.any((f) => - isSpecialId(f) || - (ctx.columns[f.name]?.indexType == - IndexType.primaryKey))) { - b.addExpression(refer('where') - .property('id') - .property('equals') - .call([ - (refer('int') - .property('parse') - .call([refer('result').property('id')])) - ])); - - b.addExpression(refer('result').assign( - refer('getOne').call([refer('executor')]).awaited)); - } - - // Fetch the results of @hasMany - ctx.relations.forEach((name, relation) { - if (relation.type == RelationshipType.hasMany) { - // Call fetchLinked(); - var fetchLinked = refer('fetchLinked').call( - [refer('result'), refer('executor')]).awaited; - b.addExpression(refer('result').assign(fetchLinked)); - } - }); - - b.addExpression(refer('result').returned); - }); - }); - - b.addExpression(refer('executor') - .property('transaction') - .call([inTransaction.closure]).returned); - }); - })); - } } // Create a Future fetchLinked(T model, QueryExecutor), if necessary. @@ -412,6 +422,8 @@ class OrmGenerator extends GeneratorForAnnotation { }); })); + var initializers = []; + // Add builders for each field for (var field in ctx.effectiveFields) { var name = field.name; @@ -451,12 +463,27 @@ class OrmGenerator extends GeneratorForAnnotation { b ..name = name ..modifier = FieldModifier.final$ - ..type = builderType - ..assignment = builderType.newInstance([ - literalString(ctx.buildContext.resolveFieldName(field.name)) - ]).code; + ..type = builderType; + + initializers.add( + refer(field.name) + .assign(builderType.newInstance([ + refer('query'), + literalString(ctx.buildContext.resolveFieldName(field.name)) + ])) + .code, + ); })); } + + // Now, just add a constructor that initializes each builder. + clazz.constructors.add(new Constructor((b) { + b + ..requiredParameters.add(new Parameter((b) => b + ..name = 'query' + ..type = refer('${rc.pascalCase}Query'))) + ..initializers.addAll(initializers); + })); }); } @@ -487,7 +514,6 @@ class OrmGenerator extends GeneratorForAnnotation { b ..name = field.name ..type = MethodType.setter - ..returns = refer('void') ..requiredParameters.add(new Parameter((b) => b ..name = 'value' ..type = type)) diff --git a/angel_orm_generator/pubspec.yaml b/angel_orm_generator/pubspec.yaml index f65afc1f..13b90539 100644 --- a/angel_orm_generator/pubspec.yaml +++ b/angel_orm_generator/pubspec.yaml @@ -1,5 +1,5 @@ name: angel_orm_generator -version: 2.0.0-dev.1 +version: 2.0.0-dev.2 description: Code generators for Angel's ORM. Generates query builder classes. author: Tobe O homepage: https://github.com/angel-dart/orm @@ -34,3 +34,6 @@ dev_dependencies: collection: ^1.0.0 postgres: ^1.0.0 test: ^1.0.0 +# dependency_overrides: +# angel_orm: +# path: ../angel_orm diff --git a/angel_orm_generator/test/belongs_to_test.dart b/angel_orm_generator/test/belongs_to_test.dart index 0a0890bd..1eccea04 100644 --- a/angel_orm_generator/test/belongs_to_test.dart +++ b/angel_orm_generator/test/belongs_to_test.dart @@ -88,7 +88,7 @@ main() { }); test('union', () async { - var query1 = new BookQuery()..where.name.like('Deathly%'); + var query1 = new BookQuery()..where.name.like((_) => 'Deathly%'); var query2 = new BookQuery()..where.authorId.equals(-1); var query3 = new BookQuery() ..where.name.isIn(['Goblet of Fire', 'Order of the Phoenix']); diff --git a/angel_orm_generator/test/common.dart b/angel_orm_generator/test/common.dart index a0f69196..af9010e2 100644 --- a/angel_orm_generator/test/common.dart +++ b/angel_orm_generator/test/common.dart @@ -23,15 +23,20 @@ class PostgresExecutor extends QueryExecutor { Future close() => (connection as PostgreSQLConnection).close(); @override - Future> query(String query, [List returningFields]) { + Future> query( + String query, Map substitutionValues, + [List returningFields]) { if (returningFields != null) { var fields = returningFields.join(', '); var returning = 'RETURNING $fields'; query = '$query $returning'; } - if (!Platform.environment.containsKey('STFU')) print('Running: $query'); - return connection.query(query); + if (!Platform.environment.containsKey('STFU')) { + print('Running: $query'); + if (substitutionValues.isNotEmpty) print('Values: $substitutionValues'); + } + return connection.query(query, substitutionValues: substitutionValues); } @override diff --git a/angel_orm_generator/test/models/author.dart b/angel_orm_generator/test/models/author.dart index f0b070a5..58042ec0 100644 --- a/angel_orm_generator/test/models/author.dart +++ b/angel_orm_generator/test/models/author.dart @@ -9,6 +9,7 @@ part 'author.g.dart'; @serializable @orm abstract class _Author extends Model { - @Column(length: 255, indexType: IndexType.unique, defaultValue: 'Tobe Osakwe') + @Column(length: 255, indexType: IndexType.unique) + @DefaultValue('Tobe Osakwe') String get name; } diff --git a/angel_orm_generator/test/models/author.g.dart b/angel_orm_generator/test/models/author.g.dart index 3d345415..fd441d86 100644 --- a/angel_orm_generator/test/models/author.g.dart +++ b/angel_orm_generator/test/models/author.g.dart @@ -11,7 +11,7 @@ class AuthorMigration extends Migration { up(Schema schema) { schema.create('authors', (table) { table.serial('id')..primaryKey(); - table.varChar('name'); + table.varChar('name')..defaultsTo('Tobe Osakwe'); table.timeStamp('created_at'); table.timeStamp('updated_at'); }); @@ -28,11 +28,14 @@ class AuthorMigration extends Migration { // ************************************************************************** class AuthorQuery extends Query { + AuthorQuery() { + _where = new AuthorQueryWhere(this); + } + @override final AuthorQueryValues values = new AuthorQueryValues(); - @override - final AuthorQueryWhere where = new AuthorQueryWhere(); + AuthorQueryWhere _where; @override get tableName { @@ -44,9 +47,14 @@ class AuthorQuery extends Query { return const ['id', 'name', 'created_at', 'updated_at']; } + @override + AuthorQueryWhere get where { + return _where; + } + @override AuthorQueryWhere newWhereClause() { - return new AuthorQueryWhere(); + return new AuthorQueryWhere(this); } static Author parseRow(List row) { @@ -66,17 +74,19 @@ class AuthorQuery extends Query { } class AuthorQueryWhere extends QueryWhere { - final NumericSqlExpressionBuilder id = - new NumericSqlExpressionBuilder('id'); + AuthorQueryWhere(AuthorQuery query) + : id = new NumericSqlExpressionBuilder(query, 'id'), + name = new StringSqlExpressionBuilder(query, 'name'), + createdAt = new DateTimeSqlExpressionBuilder(query, 'created_at'), + updatedAt = new DateTimeSqlExpressionBuilder(query, 'updated_at'); - final StringSqlExpressionBuilder name = - new StringSqlExpressionBuilder('name'); + final NumericSqlExpressionBuilder id; - final DateTimeSqlExpressionBuilder createdAt = - new DateTimeSqlExpressionBuilder('created_at'); + final StringSqlExpressionBuilder name; - final DateTimeSqlExpressionBuilder updatedAt = - new DateTimeSqlExpressionBuilder('updated_at'); + final DateTimeSqlExpressionBuilder createdAt; + + final DateTimeSqlExpressionBuilder updatedAt; @override get expressionBuilders { @@ -89,22 +99,22 @@ class AuthorQueryValues extends MapQueryValues { return (values['id'] as int); } - void set id(int value) => values['id'] = value; + set id(int value) => values['id'] = value; String get name { return (values['name'] as String); } - void set name(String value) => values['name'] = value; + set name(String value) => values['name'] = value; DateTime get createdAt { return (values['created_at'] as DateTime); } - void set createdAt(DateTime value) => values['created_at'] = value; + set createdAt(DateTime value) => values['created_at'] = value; DateTime get updatedAt { return (values['updated_at'] as DateTime); } - void set updatedAt(DateTime value) => values['updated_at'] = value; + set updatedAt(DateTime value) => values['updated_at'] = value; void copyFrom(Author model) { values.addAll({ 'name': model.name, @@ -120,7 +130,7 @@ class AuthorQueryValues extends MapQueryValues { @generatedSerializable class Author extends _Author { - Author({this.id, this.name, this.createdAt, this.updatedAt}); + Author({this.id, this.name: 'Tobe Osakwe', this.createdAt, this.updatedAt}); @override final String id; @@ -169,7 +179,7 @@ abstract class AuthorSerializer { static Author fromMap(Map map) { return new Author( id: map['id'] as String, - name: map['name'] as String, + name: map['name'] as String ?? 'Tobe Osakwe', createdAt: map['created_at'] != null ? (map['created_at'] is DateTime ? (map['created_at'] as DateTime) diff --git a/angel_orm_generator/test/models/book.g.dart b/angel_orm_generator/test/models/book.g.dart index be61700e..3805842b 100644 --- a/angel_orm_generator/test/models/book.g.dart +++ b/angel_orm_generator/test/models/book.g.dart @@ -31,6 +31,7 @@ class BookMigration extends Migration { class BookQuery extends Query { BookQuery() { + _where = new BookQueryWhere(this); leftJoin('authors', 'author_id', 'id', additionalFields: const ['name', 'created_at', 'updated_at']); leftJoin('authors', 'partner_author_id', 'id', @@ -40,8 +41,7 @@ class BookQuery extends Query { @override final BookQueryValues values = new BookQueryValues(); - @override - final BookQueryWhere where = new BookQueryWhere(); + BookQueryWhere _where; @override get tableName { @@ -60,9 +60,14 @@ class BookQuery extends Query { ]; } + @override + BookQueryWhere get where { + return _where; + } + @override BookQueryWhere newWhereClause() { - return new BookQueryWhere(); + return new BookQueryWhere(this); } static Book parseRow(List row) { @@ -100,23 +105,26 @@ class BookQuery extends Query { } class BookQueryWhere extends QueryWhere { - final NumericSqlExpressionBuilder id = - new NumericSqlExpressionBuilder('id'); + BookQueryWhere(BookQuery query) + : id = new NumericSqlExpressionBuilder(query, 'id'), + authorId = new NumericSqlExpressionBuilder(query, 'author_id'), + partnerAuthorId = + new NumericSqlExpressionBuilder(query, 'partner_author_id'), + name = new StringSqlExpressionBuilder(query, 'name'), + createdAt = new DateTimeSqlExpressionBuilder(query, 'created_at'), + updatedAt = new DateTimeSqlExpressionBuilder(query, 'updated_at'); - final NumericSqlExpressionBuilder authorId = - new NumericSqlExpressionBuilder('author_id'); + final NumericSqlExpressionBuilder id; - final NumericSqlExpressionBuilder partnerAuthorId = - new NumericSqlExpressionBuilder('partner_author_id'); + final NumericSqlExpressionBuilder authorId; - final StringSqlExpressionBuilder name = - new StringSqlExpressionBuilder('name'); + final NumericSqlExpressionBuilder partnerAuthorId; - final DateTimeSqlExpressionBuilder createdAt = - new DateTimeSqlExpressionBuilder('created_at'); + final StringSqlExpressionBuilder name; - final DateTimeSqlExpressionBuilder updatedAt = - new DateTimeSqlExpressionBuilder('updated_at'); + final DateTimeSqlExpressionBuilder createdAt; + + final DateTimeSqlExpressionBuilder updatedAt; @override get expressionBuilders { @@ -129,32 +137,32 @@ class BookQueryValues extends MapQueryValues { return (values['id'] as int); } - void set id(int value) => values['id'] = value; + set id(int value) => values['id'] = value; int get authorId { return (values['author_id'] as int); } - void set authorId(int value) => values['author_id'] = value; + set authorId(int value) => values['author_id'] = value; int get partnerAuthorId { return (values['partner_author_id'] as int); } - void set partnerAuthorId(int value) => values['partner_author_id'] = value; + set partnerAuthorId(int value) => values['partner_author_id'] = value; String get name { return (values['name'] as String); } - void set name(String value) => values['name'] = value; + set name(String value) => values['name'] = value; DateTime get createdAt { return (values['created_at'] as DateTime); } - void set createdAt(DateTime value) => values['created_at'] = value; + set createdAt(DateTime value) => values['created_at'] = value; DateTime get updatedAt { return (values['updated_at'] as DateTime); } - void set updatedAt(DateTime value) => values['updated_at'] = value; + set updatedAt(DateTime value) => values['updated_at'] = value; void copyFrom(Book model) { values.addAll({ 'name': model.name, diff --git a/angel_orm_generator/test/models/car.g.dart b/angel_orm_generator/test/models/car.g.dart index 431ab9bd..a1452e6f 100644 --- a/angel_orm_generator/test/models/car.g.dart +++ b/angel_orm_generator/test/models/car.g.dart @@ -31,11 +31,14 @@ class CarMigration extends Migration { // ************************************************************************** class CarQuery extends Query { + CarQuery() { + _where = new CarQueryWhere(this); + } + @override final CarQueryValues values = new CarQueryValues(); - @override - final CarQueryWhere where = new CarQueryWhere(); + CarQueryWhere _where; @override get tableName { @@ -55,9 +58,14 @@ class CarQuery extends Query { ]; } + @override + CarQueryWhere get where { + return _where; + } + @override CarQueryWhere newWhereClause() { - return new CarQueryWhere(); + return new CarQueryWhere(this); } static Car parseRow(List row) { @@ -80,26 +88,29 @@ class CarQuery extends Query { } class CarQueryWhere extends QueryWhere { - final NumericSqlExpressionBuilder id = - new NumericSqlExpressionBuilder('id'); + CarQueryWhere(CarQuery query) + : id = new NumericSqlExpressionBuilder(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'); - final StringSqlExpressionBuilder make = - new StringSqlExpressionBuilder('make'); + final NumericSqlExpressionBuilder id; - final StringSqlExpressionBuilder description = - new StringSqlExpressionBuilder('description'); + final StringSqlExpressionBuilder make; - final BooleanSqlExpressionBuilder familyFriendly = - new BooleanSqlExpressionBuilder('family_friendly'); + final StringSqlExpressionBuilder description; - final DateTimeSqlExpressionBuilder recalledAt = - new DateTimeSqlExpressionBuilder('recalled_at'); + final BooleanSqlExpressionBuilder familyFriendly; - final DateTimeSqlExpressionBuilder createdAt = - new DateTimeSqlExpressionBuilder('created_at'); + final DateTimeSqlExpressionBuilder recalledAt; - final DateTimeSqlExpressionBuilder updatedAt = - new DateTimeSqlExpressionBuilder('updated_at'); + final DateTimeSqlExpressionBuilder createdAt; + + final DateTimeSqlExpressionBuilder updatedAt; @override get expressionBuilders { @@ -120,37 +131,37 @@ class CarQueryValues extends MapQueryValues { return (values['id'] as int); } - void set id(int value) => values['id'] = value; + set id(int value) => values['id'] = value; String get make { return (values['make'] as String); } - void set make(String value) => values['make'] = value; + set make(String value) => values['make'] = value; String get description { return (values['description'] as String); } - void set description(String value) => values['description'] = value; + set description(String value) => values['description'] = value; bool get familyFriendly { return (values['family_friendly'] as bool); } - void set familyFriendly(bool value) => values['family_friendly'] = value; + set familyFriendly(bool value) => values['family_friendly'] = value; DateTime get recalledAt { return (values['recalled_at'] as DateTime); } - void set recalledAt(DateTime value) => values['recalled_at'] = value; + set recalledAt(DateTime value) => values['recalled_at'] = value; DateTime get createdAt { return (values['created_at'] as DateTime); } - void set createdAt(DateTime value) => values['created_at'] = value; + set createdAt(DateTime value) => values['created_at'] = value; DateTime get updatedAt { return (values['updated_at'] as DateTime); } - void set updatedAt(DateTime value) => values['updated_at'] = value; + set updatedAt(DateTime value) => values['updated_at'] = value; void copyFrom(Car model) { values.addAll({ 'make': model.make, diff --git a/angel_orm_generator/test/models/customer.g.dart b/angel_orm_generator/test/models/customer.g.dart index 819b5ab9..cf567546 100644 --- a/angel_orm_generator/test/models/customer.g.dart +++ b/angel_orm_generator/test/models/customer.g.dart @@ -27,11 +27,14 @@ class CustomerMigration extends Migration { // ************************************************************************** class CustomerQuery extends Query { + CustomerQuery() { + _where = new CustomerQueryWhere(this); + } + @override final CustomerQueryValues values = new CustomerQueryValues(); - @override - final CustomerQueryWhere where = new CustomerQueryWhere(); + CustomerQueryWhere _where; @override get tableName { @@ -43,9 +46,14 @@ class CustomerQuery extends Query { return const ['id', 'created_at', 'updated_at']; } + @override + CustomerQueryWhere get where { + return _where; + } + @override CustomerQueryWhere newWhereClause() { - return new CustomerQueryWhere(); + return new CustomerQueryWhere(this); } static Customer parseRow(List row) { @@ -64,14 +72,16 @@ class CustomerQuery extends Query { } class CustomerQueryWhere extends QueryWhere { - final NumericSqlExpressionBuilder id = - new NumericSqlExpressionBuilder('id'); + CustomerQueryWhere(CustomerQuery query) + : id = new NumericSqlExpressionBuilder(query, 'id'), + createdAt = new DateTimeSqlExpressionBuilder(query, 'created_at'), + updatedAt = new DateTimeSqlExpressionBuilder(query, 'updated_at'); - final DateTimeSqlExpressionBuilder createdAt = - new DateTimeSqlExpressionBuilder('created_at'); + final NumericSqlExpressionBuilder id; - final DateTimeSqlExpressionBuilder updatedAt = - new DateTimeSqlExpressionBuilder('updated_at'); + final DateTimeSqlExpressionBuilder createdAt; + + final DateTimeSqlExpressionBuilder updatedAt; @override get expressionBuilders { @@ -84,17 +94,17 @@ class CustomerQueryValues extends MapQueryValues { return (values['id'] as int); } - void set id(int value) => values['id'] = value; + set id(int value) => values['id'] = value; DateTime get createdAt { return (values['created_at'] as DateTime); } - void set createdAt(DateTime value) => values['created_at'] = value; + set createdAt(DateTime value) => values['created_at'] = value; DateTime get updatedAt { return (values['updated_at'] as DateTime); } - void set updatedAt(DateTime value) => values['updated_at'] = value; + set updatedAt(DateTime value) => values['updated_at'] = value; void copyFrom(Customer model) { values .addAll({'created_at': model.createdAt, 'updated_at': model.updatedAt}); diff --git a/angel_orm_generator/test/models/foot.g.dart b/angel_orm_generator/test/models/foot.g.dart index feeaf456..4f06d59e 100644 --- a/angel_orm_generator/test/models/foot.g.dart +++ b/angel_orm_generator/test/models/foot.g.dart @@ -29,11 +29,14 @@ class FootMigration extends Migration { // ************************************************************************** class FootQuery extends Query { + FootQuery() { + _where = new FootQueryWhere(this); + } + @override final FootQueryValues values = new FootQueryValues(); - @override - final FootQueryWhere where = new FootQueryWhere(); + FootQueryWhere _where; @override get tableName { @@ -45,9 +48,14 @@ class FootQuery extends Query { return const ['id', 'leg_id', 'n_toes', 'created_at', 'updated_at']; } + @override + FootQueryWhere get where { + return _where; + } + @override FootQueryWhere newWhereClause() { - return new FootQueryWhere(); + return new FootQueryWhere(this); } static Foot parseRow(List row) { @@ -68,20 +76,22 @@ class FootQuery extends Query { } class FootQueryWhere extends QueryWhere { - final NumericSqlExpressionBuilder id = - new NumericSqlExpressionBuilder('id'); + FootQueryWhere(FootQuery query) + : id = new NumericSqlExpressionBuilder(query, 'id'), + legId = new NumericSqlExpressionBuilder(query, 'leg_id'), + nToes = new NumericSqlExpressionBuilder(query, 'n_toes'), + createdAt = new DateTimeSqlExpressionBuilder(query, 'created_at'), + updatedAt = new DateTimeSqlExpressionBuilder(query, 'updated_at'); - final NumericSqlExpressionBuilder legId = - new NumericSqlExpressionBuilder('leg_id'); + final NumericSqlExpressionBuilder id; - final NumericSqlExpressionBuilder nToes = - new NumericSqlExpressionBuilder('n_toes'); + final NumericSqlExpressionBuilder legId; - final DateTimeSqlExpressionBuilder createdAt = - new DateTimeSqlExpressionBuilder('created_at'); + final NumericSqlExpressionBuilder nToes; - final DateTimeSqlExpressionBuilder updatedAt = - new DateTimeSqlExpressionBuilder('updated_at'); + final DateTimeSqlExpressionBuilder createdAt; + + final DateTimeSqlExpressionBuilder updatedAt; @override get expressionBuilders { @@ -94,27 +104,27 @@ class FootQueryValues extends MapQueryValues { return (values['id'] as int); } - void set id(int value) => values['id'] = value; + set id(int value) => values['id'] = value; int get legId { return (values['leg_id'] as int); } - void set legId(int value) => values['leg_id'] = value; + set legId(int value) => values['leg_id'] = value; int get nToes { return (values['n_toes'] as int); } - void set nToes(int value) => values['n_toes'] = value; + set nToes(int value) => values['n_toes'] = value; DateTime get createdAt { return (values['created_at'] as DateTime); } - void set createdAt(DateTime value) => values['created_at'] = value; + set createdAt(DateTime value) => values['created_at'] = value; DateTime get updatedAt { return (values['updated_at'] as DateTime); } - void set updatedAt(DateTime value) => values['updated_at'] = value; + set updatedAt(DateTime value) => values['updated_at'] = value; void copyFrom(Foot model) { values.addAll({ 'leg_id': model.legId, diff --git a/angel_orm_generator/test/models/fruit.g.dart b/angel_orm_generator/test/models/fruit.g.dart index 5b6fd7e1..3ae8c2bf 100644 --- a/angel_orm_generator/test/models/fruit.g.dart +++ b/angel_orm_generator/test/models/fruit.g.dart @@ -29,11 +29,14 @@ class FruitMigration extends Migration { // ************************************************************************** class FruitQuery extends Query { + FruitQuery() { + _where = new FruitQueryWhere(this); + } + @override final FruitQueryValues values = new FruitQueryValues(); - @override - final FruitQueryWhere where = new FruitQueryWhere(); + FruitQueryWhere _where; @override get tableName { @@ -45,9 +48,14 @@ class FruitQuery extends Query { return const ['id', 'tree_id', 'common_name', 'created_at', 'updated_at']; } + @override + FruitQueryWhere get where { + return _where; + } + @override FruitQueryWhere newWhereClause() { - return new FruitQueryWhere(); + return new FruitQueryWhere(this); } static Fruit parseRow(List row) { @@ -68,20 +76,22 @@ class FruitQuery extends Query { } class FruitQueryWhere extends QueryWhere { - final NumericSqlExpressionBuilder id = - new NumericSqlExpressionBuilder('id'); + FruitQueryWhere(FruitQuery query) + : id = new NumericSqlExpressionBuilder(query, 'id'), + treeId = new NumericSqlExpressionBuilder(query, 'tree_id'), + commonName = new StringSqlExpressionBuilder(query, 'common_name'), + createdAt = new DateTimeSqlExpressionBuilder(query, 'created_at'), + updatedAt = new DateTimeSqlExpressionBuilder(query, 'updated_at'); - final NumericSqlExpressionBuilder treeId = - new NumericSqlExpressionBuilder('tree_id'); + final NumericSqlExpressionBuilder id; - final StringSqlExpressionBuilder commonName = - new StringSqlExpressionBuilder('common_name'); + final NumericSqlExpressionBuilder treeId; - final DateTimeSqlExpressionBuilder createdAt = - new DateTimeSqlExpressionBuilder('created_at'); + final StringSqlExpressionBuilder commonName; - final DateTimeSqlExpressionBuilder updatedAt = - new DateTimeSqlExpressionBuilder('updated_at'); + final DateTimeSqlExpressionBuilder createdAt; + + final DateTimeSqlExpressionBuilder updatedAt; @override get expressionBuilders { @@ -94,27 +104,27 @@ class FruitQueryValues extends MapQueryValues { return (values['id'] as int); } - void set id(int value) => values['id'] = value; + set id(int value) => values['id'] = value; int get treeId { return (values['tree_id'] as int); } - void set treeId(int value) => values['tree_id'] = value; + set treeId(int value) => values['tree_id'] = value; String get commonName { return (values['common_name'] as String); } - void set commonName(String value) => values['common_name'] = value; + set commonName(String value) => values['common_name'] = value; DateTime get createdAt { return (values['created_at'] as DateTime); } - void set createdAt(DateTime value) => values['created_at'] = value; + set createdAt(DateTime value) => values['created_at'] = value; DateTime get updatedAt { return (values['updated_at'] as DateTime); } - void set updatedAt(DateTime value) => values['updated_at'] = value; + set updatedAt(DateTime value) => values['updated_at'] = value; void copyFrom(Fruit model) { values.addAll({ 'tree_id': model.treeId, diff --git a/angel_orm_generator/test/models/leg.g.dart b/angel_orm_generator/test/models/leg.g.dart index 0d4283cd..c8e67054 100644 --- a/angel_orm_generator/test/models/leg.g.dart +++ b/angel_orm_generator/test/models/leg.g.dart @@ -29,6 +29,7 @@ class LegMigration extends Migration { class LegQuery extends Query { LegQuery() { + _where = new LegQueryWhere(this); leftJoin('feet', 'id', 'leg_id', additionalFields: const [ 'leg_id', 'n_toes', @@ -40,8 +41,7 @@ class LegQuery extends Query { @override final LegQueryValues values = new LegQueryValues(); - @override - final LegQueryWhere where = new LegQueryWhere(); + LegQueryWhere _where; @override get tableName { @@ -53,9 +53,14 @@ class LegQuery extends Query { return const ['id', 'name', 'created_at', 'updated_at']; } + @override + LegQueryWhere get where { + return _where; + } + @override LegQueryWhere newWhereClause() { - return new LegQueryWhere(); + return new LegQueryWhere(this); } static Leg parseRow(List row) { @@ -88,17 +93,19 @@ class LegQuery extends Query { } class LegQueryWhere extends QueryWhere { - final NumericSqlExpressionBuilder id = - new NumericSqlExpressionBuilder('id'); + LegQueryWhere(LegQuery query) + : id = new NumericSqlExpressionBuilder(query, 'id'), + name = new StringSqlExpressionBuilder(query, 'name'), + createdAt = new DateTimeSqlExpressionBuilder(query, 'created_at'), + updatedAt = new DateTimeSqlExpressionBuilder(query, 'updated_at'); - final StringSqlExpressionBuilder name = - new StringSqlExpressionBuilder('name'); + final NumericSqlExpressionBuilder id; - final DateTimeSqlExpressionBuilder createdAt = - new DateTimeSqlExpressionBuilder('created_at'); + final StringSqlExpressionBuilder name; - final DateTimeSqlExpressionBuilder updatedAt = - new DateTimeSqlExpressionBuilder('updated_at'); + final DateTimeSqlExpressionBuilder createdAt; + + final DateTimeSqlExpressionBuilder updatedAt; @override get expressionBuilders { @@ -111,22 +118,22 @@ class LegQueryValues extends MapQueryValues { return (values['id'] as int); } - void set id(int value) => values['id'] = value; + set id(int value) => values['id'] = value; String get name { return (values['name'] as String); } - void set name(String value) => values['name'] = value; + set name(String value) => values['name'] = value; DateTime get createdAt { return (values['created_at'] as DateTime); } - void set createdAt(DateTime value) => values['created_at'] = value; + set createdAt(DateTime value) => values['created_at'] = value; DateTime get updatedAt { return (values['updated_at'] as DateTime); } - void set updatedAt(DateTime value) => values['updated_at'] = value; + set updatedAt(DateTime value) => values['updated_at'] = value; void copyFrom(Leg model) { values.addAll({ 'name': model.name, diff --git a/angel_orm_generator/test/models/order.g.dart b/angel_orm_generator/test/models/order.g.dart index 8751bb8e..ba0ad236 100644 --- a/angel_orm_generator/test/models/order.g.dart +++ b/angel_orm_generator/test/models/order.g.dart @@ -31,11 +31,14 @@ class OrderMigration extends Migration { // ************************************************************************** class OrderQuery extends Query { + OrderQuery() { + _where = new OrderQueryWhere(this); + } + @override final OrderQueryValues values = new OrderQueryValues(); - @override - final OrderQueryWhere where = new OrderQueryWhere(); + OrderQueryWhere _where; @override get tableName { @@ -55,9 +58,14 @@ class OrderQuery extends Query { ]; } + @override + OrderQueryWhere get where { + return _where; + } + @override OrderQueryWhere newWhereClause() { - return new OrderQueryWhere(); + return new OrderQueryWhere(this); } static Order parseRow(List row) { @@ -80,26 +88,28 @@ class OrderQuery extends Query { } class OrderQueryWhere extends QueryWhere { - final NumericSqlExpressionBuilder id = - new NumericSqlExpressionBuilder('id'); + OrderQueryWhere(OrderQuery query) + : id = new NumericSqlExpressionBuilder(query, 'id'), + customerId = new NumericSqlExpressionBuilder(query, 'customer_id'), + employeeId = new NumericSqlExpressionBuilder(query, 'employee_id'), + orderDate = new DateTimeSqlExpressionBuilder(query, 'order_date'), + shipperId = new NumericSqlExpressionBuilder(query, 'shipper_id'), + createdAt = new DateTimeSqlExpressionBuilder(query, 'created_at'), + updatedAt = new DateTimeSqlExpressionBuilder(query, 'updated_at'); - final NumericSqlExpressionBuilder customerId = - new NumericSqlExpressionBuilder('customer_id'); + final NumericSqlExpressionBuilder id; - final NumericSqlExpressionBuilder employeeId = - new NumericSqlExpressionBuilder('employee_id'); + final NumericSqlExpressionBuilder customerId; - final DateTimeSqlExpressionBuilder orderDate = - new DateTimeSqlExpressionBuilder('order_date'); + final NumericSqlExpressionBuilder employeeId; - final NumericSqlExpressionBuilder shipperId = - new NumericSqlExpressionBuilder('shipper_id'); + final DateTimeSqlExpressionBuilder orderDate; - final DateTimeSqlExpressionBuilder createdAt = - new DateTimeSqlExpressionBuilder('created_at'); + final NumericSqlExpressionBuilder shipperId; - final DateTimeSqlExpressionBuilder updatedAt = - new DateTimeSqlExpressionBuilder('updated_at'); + final DateTimeSqlExpressionBuilder createdAt; + + final DateTimeSqlExpressionBuilder updatedAt; @override get expressionBuilders { @@ -120,37 +130,37 @@ class OrderQueryValues extends MapQueryValues { return (values['id'] as int); } - void set id(int value) => values['id'] = value; + set id(int value) => values['id'] = value; int get customerId { return (values['customer_id'] as int); } - void set customerId(int value) => values['customer_id'] = value; + set customerId(int value) => values['customer_id'] = value; int get employeeId { return (values['employee_id'] as int); } - void set employeeId(int value) => values['employee_id'] = value; + set employeeId(int value) => values['employee_id'] = value; DateTime get orderDate { return (values['order_date'] as DateTime); } - void set orderDate(DateTime value) => values['order_date'] = value; + set orderDate(DateTime value) => values['order_date'] = value; int get shipperId { return (values['shipper_id'] as int); } - void set shipperId(int value) => values['shipper_id'] = value; + set shipperId(int value) => values['shipper_id'] = value; DateTime get createdAt { return (values['created_at'] as DateTime); } - void set createdAt(DateTime value) => values['created_at'] = value; + set createdAt(DateTime value) => values['created_at'] = value; DateTime get updatedAt { return (values['updated_at'] as DateTime); } - void set updatedAt(DateTime value) => values['updated_at'] = value; + set updatedAt(DateTime value) => values['updated_at'] = value; void copyFrom(Order model) { values.addAll({ 'customer_id': model.customerId, diff --git a/angel_orm_generator/test/models/tree.g.dart b/angel_orm_generator/test/models/tree.g.dart index 46233e31..78390ccd 100644 --- a/angel_orm_generator/test/models/tree.g.dart +++ b/angel_orm_generator/test/models/tree.g.dart @@ -28,13 +28,14 @@ class TreeMigration extends Migration { // ************************************************************************** class TreeQuery extends Query { - TreeQuery() {} + TreeQuery() { + _where = new TreeQueryWhere(this); + } @override final TreeQueryValues values = new TreeQueryValues(); - @override - final TreeQueryWhere where = new TreeQueryWhere(); + TreeQueryWhere _where; @override get tableName { @@ -46,9 +47,14 @@ class TreeQuery extends Query { return const ['id', 'rings', 'created_at', 'updated_at']; } + @override + TreeQueryWhere get where { + return _where; + } + @override TreeQueryWhere newWhereClause() { - return new TreeQueryWhere(); + return new TreeQueryWhere(this); } static Tree parseRow(List row) { @@ -110,17 +116,19 @@ class TreeQuery extends Query { } class TreeQueryWhere extends QueryWhere { - final NumericSqlExpressionBuilder id = - new NumericSqlExpressionBuilder('id'); + TreeQueryWhere(TreeQuery query) + : id = new NumericSqlExpressionBuilder(query, 'id'), + rings = new NumericSqlExpressionBuilder(query, 'rings'), + createdAt = new DateTimeSqlExpressionBuilder(query, 'created_at'), + updatedAt = new DateTimeSqlExpressionBuilder(query, 'updated_at'); - final NumericSqlExpressionBuilder rings = - new NumericSqlExpressionBuilder('rings'); + final NumericSqlExpressionBuilder id; - final DateTimeSqlExpressionBuilder createdAt = - new DateTimeSqlExpressionBuilder('created_at'); + final NumericSqlExpressionBuilder rings; - final DateTimeSqlExpressionBuilder updatedAt = - new DateTimeSqlExpressionBuilder('updated_at'); + final DateTimeSqlExpressionBuilder createdAt; + + final DateTimeSqlExpressionBuilder updatedAt; @override get expressionBuilders { @@ -133,22 +141,22 @@ class TreeQueryValues extends MapQueryValues { return (values['id'] as int); } - void set id(int value) => values['id'] = value; + set id(int value) => values['id'] = value; int get rings { return (values['rings'] as int); } - void set rings(int value) => values['rings'] = value; + set rings(int value) => values['rings'] = value; DateTime get createdAt { return (values['created_at'] as DateTime); } - void set createdAt(DateTime value) => values['created_at'] = value; + set createdAt(DateTime value) => values['created_at'] = value; DateTime get updatedAt { return (values['updated_at'] as DateTime); } - void set updatedAt(DateTime value) => values['updated_at'] = value; + set updatedAt(DateTime value) => values['updated_at'] = value; void copyFrom(Tree model) { values.addAll({ 'rings': model.rings, diff --git a/angel_orm_generator/test/models/user.g.dart b/angel_orm_generator/test/models/user.g.dart index 18425a27..35e5052e 100644 --- a/angel_orm_generator/test/models/user.g.dart +++ b/angel_orm_generator/test/models/user.g.dart @@ -63,13 +63,14 @@ class UserRoleMigration extends Migration { // ************************************************************************** class UserQuery extends Query { - UserQuery() {} + UserQuery() { + _where = new UserQueryWhere(this); + } @override final UserQueryValues values = new UserQueryValues(); - @override - final UserQueryWhere where = new UserQueryWhere(); + UserQueryWhere _where; @override get tableName { @@ -88,9 +89,14 @@ class UserQuery extends Query { ]; } + @override + UserQueryWhere get where { + return _where; + } + @override UserQueryWhere newWhereClause() { - return new UserQueryWhere(); + return new UserQueryWhere(this); } static User parseRow(List row) { @@ -154,23 +160,25 @@ class UserQuery extends Query { } class UserQueryWhere extends QueryWhere { - final NumericSqlExpressionBuilder id = - new NumericSqlExpressionBuilder('id'); + UserQueryWhere(UserQuery query) + : id = new NumericSqlExpressionBuilder(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'); - final StringSqlExpressionBuilder username = - new StringSqlExpressionBuilder('username'); + final NumericSqlExpressionBuilder id; - final StringSqlExpressionBuilder password = - new StringSqlExpressionBuilder('password'); + final StringSqlExpressionBuilder username; - final StringSqlExpressionBuilder email = - new StringSqlExpressionBuilder('email'); + final StringSqlExpressionBuilder password; - final DateTimeSqlExpressionBuilder createdAt = - new DateTimeSqlExpressionBuilder('created_at'); + final StringSqlExpressionBuilder email; - final DateTimeSqlExpressionBuilder updatedAt = - new DateTimeSqlExpressionBuilder('updated_at'); + final DateTimeSqlExpressionBuilder createdAt; + + final DateTimeSqlExpressionBuilder updatedAt; @override get expressionBuilders { @@ -183,32 +191,32 @@ class UserQueryValues extends MapQueryValues { return (values['id'] as int); } - void set id(int value) => values['id'] = value; + set id(int value) => values['id'] = value; String get username { return (values['username'] as String); } - void set username(String value) => values['username'] = value; + set username(String value) => values['username'] = value; String get password { return (values['password'] as String); } - void set password(String value) => values['password'] = value; + set password(String value) => values['password'] = value; String get email { return (values['email'] as String); } - void set email(String value) => values['email'] = value; + set email(String value) => values['email'] = value; DateTime get createdAt { return (values['created_at'] as DateTime); } - void set createdAt(DateTime value) => values['created_at'] = value; + set createdAt(DateTime value) => values['created_at'] = value; DateTime get updatedAt { return (values['updated_at'] as DateTime); } - void set updatedAt(DateTime value) => values['updated_at'] = value; + set updatedAt(DateTime value) => values['updated_at'] = value; void copyFrom(User model) { values.addAll({ 'username': model.username, @@ -221,13 +229,14 @@ class UserQueryValues extends MapQueryValues { } class RoleQuery extends Query { - RoleQuery() {} + RoleQuery() { + _where = new RoleQueryWhere(this); + } @override final RoleQueryValues values = new RoleQueryValues(); - @override - final RoleQueryWhere where = new RoleQueryWhere(); + RoleQueryWhere _where; @override get tableName { @@ -239,9 +248,14 @@ class RoleQuery extends Query { return const ['id', 'name', 'created_at', 'updated_at']; } + @override + RoleQueryWhere get where { + return _where; + } + @override RoleQueryWhere newWhereClause() { - return new RoleQueryWhere(); + return new RoleQueryWhere(this); } static Role parseRow(List row) { @@ -303,17 +317,19 @@ class RoleQuery extends Query { } class RoleQueryWhere extends QueryWhere { - final NumericSqlExpressionBuilder id = - new NumericSqlExpressionBuilder('id'); + RoleQueryWhere(RoleQuery query) + : id = new NumericSqlExpressionBuilder(query, 'id'), + name = new StringSqlExpressionBuilder(query, 'name'), + createdAt = new DateTimeSqlExpressionBuilder(query, 'created_at'), + updatedAt = new DateTimeSqlExpressionBuilder(query, 'updated_at'); - final StringSqlExpressionBuilder name = - new StringSqlExpressionBuilder('name'); + final NumericSqlExpressionBuilder id; - final DateTimeSqlExpressionBuilder createdAt = - new DateTimeSqlExpressionBuilder('created_at'); + final StringSqlExpressionBuilder name; - final DateTimeSqlExpressionBuilder updatedAt = - new DateTimeSqlExpressionBuilder('updated_at'); + final DateTimeSqlExpressionBuilder createdAt; + + final DateTimeSqlExpressionBuilder updatedAt; @override get expressionBuilders { @@ -326,22 +342,22 @@ class RoleQueryValues extends MapQueryValues { return (values['id'] as int); } - void set id(int value) => values['id'] = value; + set id(int value) => values['id'] = value; String get name { return (values['name'] as String); } - void set name(String value) => values['name'] = value; + set name(String value) => values['name'] = value; DateTime get createdAt { return (values['created_at'] as DateTime); } - void set createdAt(DateTime value) => values['created_at'] = value; + set createdAt(DateTime value) => values['created_at'] = value; DateTime get updatedAt { return (values['updated_at'] as DateTime); } - void set updatedAt(DateTime value) => values['updated_at'] = value; + set updatedAt(DateTime value) => values['updated_at'] = value; void copyFrom(Role model) { values.addAll({ 'name': model.name, @@ -353,6 +369,7 @@ class RoleQueryValues extends MapQueryValues { class UserRoleQuery extends Query { UserRoleQuery() { + _where = new UserRoleQueryWhere(this); leftJoin('users', 'user_id', 'id', additionalFields: const [ 'username', 'password', @@ -367,8 +384,7 @@ class UserRoleQuery extends Query { @override final UserRoleQueryValues values = new UserRoleQueryValues(); - @override - final UserRoleQueryWhere where = new UserRoleQueryWhere(); + UserRoleQueryWhere _where; @override get tableName { @@ -380,9 +396,14 @@ class UserRoleQuery extends Query { return const ['id', 'user_id', 'role_id']; } + @override + UserRoleQueryWhere get where { + return _where; + } + @override UserRoleQueryWhere newWhereClause() { - return new UserRoleQueryWhere(); + return new UserRoleQueryWhere(this); } static UserRole parseRow(List row) { @@ -412,14 +433,16 @@ class UserRoleQuery extends Query { } class UserRoleQueryWhere extends QueryWhere { - final NumericSqlExpressionBuilder id = - new NumericSqlExpressionBuilder('id'); + UserRoleQueryWhere(UserRoleQuery query) + : id = new NumericSqlExpressionBuilder(query, 'id'), + userId = new NumericSqlExpressionBuilder(query, 'user_id'), + roleId = new NumericSqlExpressionBuilder(query, 'role_id'); - final NumericSqlExpressionBuilder userId = - new NumericSqlExpressionBuilder('user_id'); + final NumericSqlExpressionBuilder id; - final NumericSqlExpressionBuilder roleId = - new NumericSqlExpressionBuilder('role_id'); + final NumericSqlExpressionBuilder userId; + + final NumericSqlExpressionBuilder roleId; @override get expressionBuilders { @@ -432,17 +455,17 @@ class UserRoleQueryValues extends MapQueryValues { return (values['id'] as int); } - void set id(int value) => values['id'] = value; + set id(int value) => values['id'] = value; int get userId { return (values['user_id'] as int); } - void set userId(int value) => values['user_id'] = value; + set userId(int value) => values['user_id'] = value; int get roleId { return (values['role_id'] as int); } - void set roleId(int value) => values['role_id'] = value; + set roleId(int value) => values['role_id'] = value; void copyFrom(UserRole model) { values.addAll({'id': model.id}); if (model.user != null) { diff --git a/angel_orm_generator/test/standalone_test.dart b/angel_orm_generator/test/standalone_test.dart index 23017331..ad3b44d1 100644 --- a/angel_orm_generator/test/standalone_test.dart +++ b/angel_orm_generator/test/standalone_test.dart @@ -78,7 +78,7 @@ main() { }); test('union', () async { - var query1 = new CarQuery()..where.make.like('%Fer%'); + var query1 = new CarQuery()..where.make.like((_) => '%Fer%'); var query2 = new CarQuery()..where.familyFriendly.isTrue; var query3 = new CarQuery()..where.description.equals('Submarine'); var union = query1.union(query2).unionAll(query3); @@ -89,7 +89,7 @@ main() { test('or clause', () async { var query = new CarQuery() - ..where.make.like('Fer%') + ..where.make.like((_) => 'Fer%') ..orWhere((where) => where ..familyFriendly.isTrue ..make.equals('Honda'));