diff --git a/packages/orm/angel_orm_generator/example/main.g.dart b/packages/orm/angel_orm_generator/example/main.g.dart index 447f4863..517890a9 100644 --- a/packages/orm/angel_orm_generator/example/main.g.dart +++ b/packages/orm/angel_orm_generator/example/main.g.dart @@ -11,12 +11,13 @@ class EmployeeMigration extends Migration { void up(Schema schema) { schema.create('employees', (table) { table.serial('id').primaryKey(); + table.varChar('error', length: 256); table.timeStamp('created_at'); table.timeStamp('updated_at'); - table.varChar('unique_id'); - table.varChar('first_name'); - table.varChar('last_name'); - table.declare('salary', ColumnType('decimal')); + table.varChar('unique_id', length: 256).unique(); + table.varChar('first_name', length: 256); + table.varChar('last_name', length: 256); + table.declareColumn('salary', Column(type: ColumnType('decimal'))); }); } @@ -31,8 +32,9 @@ class EmployeeMigration extends Migration { // ************************************************************************** class EmployeeQuery extends Query { - EmployeeQuery({Set? trampoline}) { - trampoline ??= {}; + EmployeeQuery({Query? parent, Set? trampoline}) + : super(parent: parent) { + trampoline ??= {}; trampoline.add(tableName); _where = EmployeeQueryWhere(this); } @@ -56,6 +58,7 @@ class EmployeeQuery extends Query { List get fields { return const [ 'id', + 'error', 'created_at', 'updated_at', 'unique_id', @@ -75,30 +78,30 @@ class EmployeeQuery extends Query { return EmployeeQueryWhere(this); } - static Optional parseRow(List row) { - if (row.every((x) => x == null)) { - return Optional.empty(); - } + static Employee? parseRow(List row) { + if (row.every((x) => x == null)) return null; var model = Employee( - id: (row[0] as String?), - createdAt: (row[1] as DateTime?), - updatedAt: (row[2] as DateTime?), - uniqueId: (row[3] as String?), - firstName: (row[4] as String?), - lastName: (row[5] as String?), - salary: double.tryParse(row[6].toString())); - return Optional.of(model); + id: row[0].toString(), + error: (row[1] as String?), + createdAt: (row[2] as DateTime?), + updatedAt: (row[3] as DateTime?), + uniqueId: (row[4] as String?), + firstName: (row[5] as String?), + lastName: (row[6] as String?), + salary: double.tryParse(row[7].toString())); + return model; } @override Optional deserialize(List row) { - return parseRow(row); + return Optional.ofNullable(parseRow(row)); } } class EmployeeQueryWhere extends QueryWhere { EmployeeQueryWhere(EmployeeQuery query) - : id = StringSqlExpressionBuilder(query, 'id'), + : id = NumericSqlExpressionBuilder(query, 'id'), + error = StringSqlExpressionBuilder(query, 'error'), createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'), updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'), uniqueId = StringSqlExpressionBuilder(query, 'unique_id'), @@ -106,7 +109,9 @@ class EmployeeQueryWhere extends QueryWhere { lastName = StringSqlExpressionBuilder(query, 'last_name'), salary = NumericSqlExpressionBuilder(query, 'salary'); - final StringSqlExpressionBuilder id; + final NumericSqlExpressionBuilder id; + + final StringSqlExpressionBuilder error; final DateTimeSqlExpressionBuilder createdAt; @@ -122,7 +127,16 @@ class EmployeeQueryWhere extends QueryWhere { @override List get expressionBuilders { - return [id, createdAt, updatedAt, uniqueId, firstName, lastName, salary]; + return [ + id, + error, + createdAt, + updatedAt, + uniqueId, + firstName, + lastName, + salary + ]; } } @@ -137,6 +151,11 @@ class EmployeeQueryValues extends MapQueryValues { } set id(String? value) => values['id'] = value; + String? get error { + return (values['error'] as String?); + } + + set error(String? value) => values['error'] = value; DateTime? get createdAt { return (values['created_at'] as DateTime?); } @@ -168,7 +187,7 @@ class EmployeeQueryValues extends MapQueryValues { set salary(double? value) => values['salary'] = value.toString(); void copyFrom(Employee model) { - id = model.id; + error = model.error; createdAt = model.createdAt; updatedAt = model.updatedAt; uniqueId = model.uniqueId; @@ -186,6 +205,7 @@ class EmployeeQueryValues extends MapQueryValues { class Employee extends _Employee { Employee( {this.id, + this.error, this.createdAt, this.updatedAt, this.uniqueId, @@ -197,6 +217,9 @@ class Employee extends _Employee { @override String? id; + @override + String? error; + /// The time at which this item was created. @override DateTime? createdAt; @@ -209,16 +232,17 @@ class Employee extends _Employee { String? uniqueId; @override - final String? firstName; + String? firstName; @override - final String? lastName; + String? lastName; @override - final double? salary; + double? salary; Employee copyWith( {String? id, + String? error, DateTime? createdAt, DateTime? updatedAt, String? uniqueId, @@ -227,6 +251,7 @@ class Employee extends _Employee { double? salary}) { return Employee( id: id ?? this.id, + error: error ?? this.error, createdAt: createdAt ?? this.createdAt, updatedAt: updatedAt ?? this.updatedAt, uniqueId: uniqueId ?? this.uniqueId, @@ -239,6 +264,7 @@ class Employee extends _Employee { bool operator ==(other) { return other is _Employee && other.id == id && + other.error == error && other.createdAt == createdAt && other.updatedAt == updatedAt && other.uniqueId == uniqueId && @@ -249,13 +275,21 @@ class Employee extends _Employee { @override int get hashCode { - return hashObjects( - [id, createdAt, updatedAt, uniqueId, firstName, lastName, salary]); + return hashObjects([ + id, + error, + createdAt, + updatedAt, + uniqueId, + firstName, + lastName, + salary + ]); } @override String toString() { - return 'Employee(id=$id, createdAt=$createdAt, updatedAt=$updatedAt, uniqueId=$uniqueId, firstName=$firstName, lastName=$lastName, salary=$salary)'; + return 'Employee(id=$id, error=$error, createdAt=$createdAt, updatedAt=$updatedAt, uniqueId=$uniqueId, firstName=$firstName, lastName=$lastName, salary=$salary)'; } Map toJson() { @@ -292,26 +326,28 @@ class EmployeeSerializer extends Codec { EmployeeDecoder get decoder => const EmployeeDecoder(); static Employee fromMap(Map map) { return Employee( - id: map['id'] as String?, + id: map['id'] as String, + error: map['error'] as String, createdAt: map['created_at'] != null ? (map['created_at'] is DateTime - ? (map['created_at'] as DateTime?) + ? (map['created_at'] as DateTime) : DateTime.parse(map['created_at'].toString())) : null, updatedAt: map['updated_at'] != null ? (map['updated_at'] is DateTime - ? (map['updated_at'] as DateTime?) + ? (map['updated_at'] as DateTime) : DateTime.parse(map['updated_at'].toString())) : null, - uniqueId: map['unique_id'] as String?, - firstName: map['first_name'] as String?, - lastName: map['last_name'] as String?, - salary: map['salary'] as double?); + uniqueId: map['unique_id'] as String, + firstName: map['first_name'] as String, + lastName: map['last_name'] as String, + salary: map['salary'] as double); } static Map toMap(_Employee model) { return { 'id': model.id, + 'error': model.error, 'created_at': model.createdAt?.toIso8601String(), 'updated_at': model.updatedAt?.toIso8601String(), 'unique_id': model.uniqueId, @@ -325,6 +361,7 @@ class EmployeeSerializer extends Codec { abstract class EmployeeFields { static const List allFields = [ id, + error, createdAt, updatedAt, uniqueId, @@ -335,6 +372,8 @@ abstract class EmployeeFields { static const String id = 'id'; + static const String error = 'error'; + static const String createdAt = 'created_at'; static const String updatedAt = 'updated_at'; diff --git a/packages/orm/angel_orm_mysql/example/main.dart b/packages/orm/angel_orm_mysql/example/main.dart index 279f4fb5..e9837d77 100644 --- a/packages/orm/angel_orm_mysql/example/main.dart +++ b/packages/orm/angel_orm_mysql/example/main.dart @@ -28,7 +28,7 @@ void main() async { var todo = await query.insert(executor); print(todo.value.toJson()); - var query2 = TodoQuery()..where!.id.equals(todo.value.idAsInt!); + var query2 = TodoQuery()..where!.id.equals(todo.value.idAsInt); var todo2 = await query2.getOne(executor); print(todo2.value.toJson()); print(todo == todo2); diff --git a/packages/orm/angel_orm_service/CHANGELOG.md b/packages/orm/angel_orm_service/CHANGELOG.md index 36650424..cc700055 100644 --- a/packages/orm/angel_orm_service/CHANGELOG.md +++ b/packages/orm/angel_orm_service/CHANGELOG.md @@ -1,5 +1,13 @@ -# 2.0.0-beta.1 +# Change Log + +## 2.0.0 + +* Fixed NNBD issues + +## 2.0.0-beta.1 + * Migrated to support Dart SDK 2.12.x NNBD -# 1.0.0 -* First version. \ No newline at end of file +## 1.0.0 + +* First version. diff --git a/packages/orm/angel_orm_service/README.md b/packages/orm/angel_orm_service/README.md index e341ba49..600ffa6b 100644 --- a/packages/orm/angel_orm_service/README.md +++ b/packages/orm/angel_orm_service/README.md @@ -1,21 +1,24 @@ -# angel3_orm_service +# Angel3 ORM Service + [![version](https://img.shields.io/badge/pub-v2.0.0-brightgreen)](https://pub.dartlang.org/packages/angel3_orm_service) [![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety) [![Gitter](https://img.shields.io/gitter/room/angel_dart/discussion)](https://gitter.im/angel_dart/discussion) [![License](https://img.shields.io/github/license/dukefirehawk/angel)](https://github.com/dukefirehawk/angel/tree/angel3/packages/orm/angel_orm_service/LICENSE) -Service implementation that wraps over Angel ORM Query classes. +Service implementation that wraps over Angel3 ORM Query classes. ## Installation + In your `pubspec.yaml`: ```yaml dependencies: - angel3_orm_service: ^2.0.0-beta.1 + angel3_orm_service: ^2.0.0 ``` ## Usage + Brief snippet (check `example/main.dart` for setup, etc.): ```dart @@ -30,4 +33,4 @@ Brief snippet (check `example/main.dart` for setup, etc.): // ** app.use>( '/api/todos', todoService); -``` \ No newline at end of file +``` diff --git a/packages/orm/angel_orm_service/pubspec.yaml b/packages/orm/angel_orm_service/pubspec.yaml index c93fcf3a..b800da87 100644 --- a/packages/orm/angel_orm_service/pubspec.yaml +++ b/packages/orm/angel_orm_service/pubspec.yaml @@ -1,25 +1,22 @@ name: angel3_orm_service version: 2.0.0-beta.1 description: Service implementation that wraps over Angel3 ORM Query classes. -homepage: https://github.com/dukefirehawk/angel/tree/angel3/packages/orm/angel_orm_service +homepage: https://angel3-framework.web.app/ +repository: https://github.com/dukefirehawk/angel/tree/angel3/packages/orm/angel_orm_service environment: sdk: '>=2.12.0 <3.0.0' dependencies: angel3_framework: ^4.0.0 - angel3_orm: ^4.0.0-beta.1 - postgres: ^2.3.2 - optional: ^6.0.0-nullsafety.2 + angel3_orm: ^4.0.0 + postgres: ^2.4.0 + optional: ^6.0.0 dev_dependencies: - angel3_migration: ^4.0.0-beta.1 - angel3_migration_runner: ^4.0.0-beta.1 - angel3_orm_generator: ^4.0.0-beta.1 - angel3_orm_postgres: ^3.0.0-beta.1 + angel3_migration: ^4.0.0 + angel3_migration_runner: ^4.0.0 + angel3_orm_generator: ^4.0.0 + angel3_orm_postgres: ^3.0.0 angel3_serialize: ^4.0.0 angel3_orm_test: - git: - url: https://github.com/dukefirehawk/angel.git - ref: angel3 - path: packages/orm/angel_orm_test build_runner: ^2.0.4 logging: ^1.0.1 pedantic: ^1.11.0 diff --git a/packages/orm/angel_orm_test/lib/src/has_one_test.dart b/packages/orm/angel_orm_test/lib/src/has_one_test.dart index cd133c74..627227ba 100644 --- a/packages/orm/angel_orm_test/lib/src/has_one_test.dart +++ b/packages/orm/angel_orm_test/lib/src/has_one_test.dart @@ -114,8 +114,8 @@ void hasOneTests(FutureOr Function() createExecutor, test('sets null on false subquery', () async { var legQuery = LegQuery() - ..where!.id.equals(originalLeg!.idAsInt!) - ..foot!.where!.legId.equals(originalLeg!.idAsInt! + 1024); + ..where!.id.equals(originalLeg!.idAsInt) + ..foot!.where!.legId.equals(originalLeg!.idAsInt + 1024); var legOpt = await (legQuery.getOne(executor)); expect(legOpt.isPresent, true); legOpt.ifPresent((leg) { diff --git a/packages/orm/angel_orm_test/lib/src/many_to_many_test.dart b/packages/orm/angel_orm_test/lib/src/many_to_many_test.dart index cdf622b9..43b54316 100644 --- a/packages/orm/angel_orm_test/lib/src/many_to_many_test.dart +++ b/packages/orm/angel_orm_test/lib/src/many_to_many_test.dart @@ -115,7 +115,7 @@ void manyToManyTests(FutureOr Function() createExecutor, test('fetch users for role', () async { for (var role in [canPub, canSub]) { - var query = RoleQuery()..where!.id.equals(role!.idAsInt!); + var query = RoleQuery()..where!.id.equals(role!.idAsInt); var rOpt = await query.getOne(executor); expect(rOpt.isPresent, true); rOpt.ifPresent((r) async { @@ -139,7 +139,7 @@ void manyToManyTests(FutureOr Function() createExecutor, expect(user.roles, isEmpty); // Fetch again, just to be doubly sure. - var query = UserQuery()..where!.id.equals(user.idAsInt!); + var query = UserQuery()..where!.id.equals(user.idAsInt); var fetchedOpt = await query.getOne(executor); expect(fetchedOpt.isPresent, true); fetchedOpt.ifPresent((fetched) {