diff --git a/packages/orm/angel_orm/example/main.dart b/packages/orm/angel_orm/example/main.dart index fd394f68..cb996f56 100644 --- a/packages/orm/angel_orm/example/main.dart +++ b/packages/orm/angel_orm/example/main.dart @@ -11,7 +11,7 @@ void main() async { var query = EmployeeQuery() ..where?.firstName.equals('Rich') ..where?.lastName.equals('Person') - ..orWhere((w) => w?.salary.greaterThanOrEqualTo(75000)) + ..orWhere((w) => w.salary.greaterThanOrEqualTo(75000)) ..join('companies', 'company_id', 'id'); var richPerson = await query.getOne(_FakeExecutor()); @@ -51,7 +51,7 @@ abstract class _Employee extends Model { double? get salary; } -class EmployeeQuery extends Query { +class EmployeeQuery extends Query { @override final QueryValues values = MapQueryValues(); diff --git a/packages/orm/angel_orm/lib/src/query.dart b/packages/orm/angel_orm/lib/src/query.dart index f00c026a..10f55327 100644 --- a/packages/orm/angel_orm/lib/src/query.dart +++ b/packages/orm/angel_orm/lib/src/query.dart @@ -34,12 +34,12 @@ abstract class Query extends QueryBase { /// A reference to an abstract query builder. /// /// This is usually a generated class. - Where get where; + Where? get where; /// A set of values, for an insertion or update. /// /// This is usually a generated class. - QueryValues get values; + QueryValues? get values; /// Preprends the [tableName] to the [String], [s]. String adornWithTableName(String s) { @@ -86,21 +86,21 @@ abstract class Query extends QueryBase { void andWhere(void Function(Where) f) { var w = newWhereClause(); f(w); - where.and(w); + where?.and(w); } /// Shorthand for calling [where].or with a [Where] clause. void notWhere(void Function(Where) f) { var w = newWhereClause(); f(w); - where.not(w); + where?.not(w); } /// Shorthand for calling [where].or with a [Where] clause. void orWhere(void Function(Where) f) { var w = newWhereClause(); f(w); - where.or(w); + where?.or(w); } /// Limit the number of rows to return. @@ -310,8 +310,8 @@ abstract class Query extends QueryBase { } var whereClause = - where.compile(tableName: includeTableName ? tableName : null); - if (whereClause.isNotEmpty == true) { + where?.compile(tableName: includeTableName ? tableName : null); + if (whereClause?.isNotEmpty == true) { b.write(' WHERE $whereClause'); } if (_groupBy != null) b.write(' GROUP BY $_groupBy'); @@ -355,7 +355,7 @@ abstract class Query extends QueryBase { } Future> insert(QueryExecutor executor) { - var insertion = values.compileInsert(this, tableName); + var insertion = values?.compileInsert(this, tableName); if (insertion == '') { throw StateError('No values have been specified for update.'); @@ -373,14 +373,14 @@ abstract class Query extends QueryBase { Future> update(QueryExecutor executor) async { var updateSql = StringBuffer('UPDATE $tableName '); - var valuesClause = values.compileForUpdate(this); + var valuesClause = values?.compileForUpdate(this); if (valuesClause == '') { throw StateError('No values have been specified for update.'); } else { updateSql.write(' $valuesClause'); - var whereClause = where.compile(); - if (whereClause.isNotEmpty == true) { + var whereClause = where?.compile(); + if (whereClause?.isNotEmpty == true) { updateSql.write(' WHERE $whereClause'); } if (_limit != null) updateSql.write(' LIMIT $_limit');