diff --git a/CHANGELOG.md b/CHANGELOG.md index d6371aa4..2b839e6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,11 @@ * Updated angel_orm_test to 1.0.0 (in progress) * Updated angel_orm_postgres to 2.0.0 (in progress) * Update orm-sdk-2.12.x boilerplate (in progress) +* Updated angel_serialize to 4.0.0 (0/0 tests passed) +* Updated angel_serialize_generator to 4.0.0 (33/33 tests passed) +* Updated angel_orm to 4.0.0 (0/0 tests passed) +* Updated angel_migration to 3.0.0 +* Updated angel_orm_generator to 3.0.0 (use a fork of postgres) # 3.0.0 (Non NNBD) * Changed Dart SDK requirements for all packages to ">=2.10.0 <3.0.0" @@ -65,7 +70,7 @@ * Update basic-sdk-2.12.x boilerplate (1/1 tests passed) * Updated angel_serialize to 3.0.0 (0/0 tests passed) * Updated angel_serialize_generator to 3.0.0 (33/33 tests passed) -* Updated angel_orm to 3.0.0 +* Updated angel_orm to 3.0.0 (0/0 tests passed) * Updated angel_migration to 3.0.0 * Updated angel_orm_generator to 3.0.0 (use a fork of postgres) * Updated angel_migration_runner to 3.0.0 diff --git a/packages/auth_twitter/example/main.dart b/packages/auth_twitter/example/main.dart index c4a5bce6..64f23d53 100644 --- a/packages/auth_twitter/example/main.dart +++ b/packages/auth_twitter/example/main.dart @@ -38,8 +38,8 @@ main() async { 'http://localhost:3000/auth/twitter/callback', ), (twit, req, res) async { - var response = await twit.twitterClient - .get('https://api.twitter.com/1.1/account/verify_credentials.json'); + var response = await twit.twitterClient.get(Uri.parse( + 'https://api.twitter.com/1.1/account/verify_credentials.json')); var userData = json.decode(response.body) as Map; return _User(userData['screen_name'] as String); }, diff --git a/packages/auth_twitter/pubspec.yaml b/packages/auth_twitter/pubspec.yaml index 7831dc2f..ddd44c9f 100644 --- a/packages/auth_twitter/pubspec.yaml +++ b/packages/auth_twitter/pubspec.yaml @@ -1,11 +1,10 @@ name: "angel_auth_twitter" -#author: "Tobe O " +version: 3.0.0 description: "package:angel_auth strategy for Twitter login. Auto-signs requests." +homepage: "https://github.com/angel-dart/auth_twitter.git" +publish_to: none environment: sdk: ">=2.10.0 <3.0.0" -homepage: "https://github.com/angel-dart/auth_twitter.git" -version: 3.0.0 -publish_to: none dependencies: angel_auth: git: diff --git a/packages/orm/.idea/.name b/packages/orm/.idea/.name deleted file mode 100644 index 80e9d968..00000000 --- a/packages/orm/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -orm \ No newline at end of file diff --git a/packages/orm/.idea/dbnavigator.xml b/packages/orm/.idea/dbnavigator.xml deleted file mode 100644 index 11ef66c4..00000000 --- a/packages/orm/.idea/dbnavigator.xml +++ /dev/null @@ -1,451 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/orm/.idea/modules.xml b/packages/orm/.idea/modules.xml deleted file mode 100644 index 0d8a8dd2..00000000 --- a/packages/orm/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/packages/orm/.idea/orm.iml b/packages/orm/.idea/orm.iml deleted file mode 100644 index f6a57903..00000000 --- a/packages/orm/.idea/orm.iml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/orm/.idea/runConfigurations/tests_in_has_one_test.xml b/packages/orm/.idea/runConfigurations/tests_in_has_one_test.xml deleted file mode 100644 index ed8f6398..00000000 --- a/packages/orm/.idea/runConfigurations/tests_in_has_one_test.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/packages/orm/.idea/vcs.xml b/packages/orm/.idea/vcs.xml deleted file mode 100644 index 94a25f7f..00000000 --- a/packages/orm/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/packages/orm/angel_migration/AUTHORS.md b/packages/orm/angel_migration/AUTHORS.md new file mode 100644 index 00000000..2a973de6 --- /dev/null +++ b/packages/orm/angel_migration/AUTHORS.md @@ -0,0 +1,2 @@ +Tobe O +Thomas Hii \ No newline at end of file diff --git a/packages/orm/angel_migration/CHANGELOG.md b/packages/orm/angel_migration/CHANGELOG.md index 8bc775a0..a18207b8 100755 --- a/packages/orm/angel_migration/CHANGELOG.md +++ b/packages/orm/angel_migration/CHANGELOG.md @@ -1,3 +1,9 @@ +# 4.0.0 +* Migrated to support Dart SDK 2.12.x NNBD + +# 3.0.0 +* Migrated to work with Dart SDK 2.12.x Non NNBD + # 2.0.0 * Bump to `2.0.0`. diff --git a/packages/orm/angel_migration_runner/AUTHORS.md b/packages/orm/angel_migration_runner/AUTHORS.md new file mode 100644 index 00000000..2a973de6 --- /dev/null +++ b/packages/orm/angel_migration_runner/AUTHORS.md @@ -0,0 +1,2 @@ +Tobe O +Thomas Hii \ No newline at end of file diff --git a/packages/orm/angel_migration_runner/CHANGELOG.md b/packages/orm/angel_migration_runner/CHANGELOG.md index 05a727ef..90928dd2 100755 --- a/packages/orm/angel_migration_runner/CHANGELOG.md +++ b/packages/orm/angel_migration_runner/CHANGELOG.md @@ -1,3 +1,9 @@ +# 4.0.0 +* Migrated to support Dart SDK 2.12.x NNBD + +# 3.0.0 +* Migrated to work with Dart SDK 2.12.x Non NNBD + # 2.0.0 * Bump to `2.0.0`. diff --git a/packages/orm/angel_orm/AUTHORS.md b/packages/orm/angel_orm/AUTHORS.md new file mode 100644 index 00000000..2a973de6 --- /dev/null +++ b/packages/orm/angel_orm/AUTHORS.md @@ -0,0 +1,2 @@ +Tobe O +Thomas Hii \ No newline at end of file diff --git a/packages/orm/angel_orm/CHANGELOG.md b/packages/orm/angel_orm/CHANGELOG.md index 8f193561..43a98ef7 100644 --- a/packages/orm/angel_orm/CHANGELOG.md +++ b/packages/orm/angel_orm/CHANGELOG.md @@ -1,3 +1,9 @@ +# 4.0.0 +* Migrated to support Dart SDK 2.12.x NNBD + +# 3.0.0 +* Migrated to work with Dart SDK 2.12.x Non NNBD + # 2.1.0-beta.3 * Remove parentheses from `AS` when renaming raw `expressions`. diff --git a/packages/orm/angel_orm/example/main.dart b/packages/orm/angel_orm/example/main.dart index fbf6866d..c13ff6bf 100644 --- a/packages/orm/angel_orm/example/main.dart +++ b/packages/orm/angel_orm/example/main.dart @@ -7,15 +7,15 @@ import 'package:angel_serialize/angel_serialize.dart'; part 'main.g.dart'; part 'main.serializer.g.dart'; -main() async { +void main() async { var query = EmployeeQuery() - ..where.firstName.equals('Rich') - ..where.lastName.equals('Person') - ..orWhere((w) => w.salary.greaterThanOrEqualTo(75000)) + ..where?.firstName.equals('Rich') + ..where?.lastName.equals('Person') + ..orWhere((w) => w?.salary.greaterThanOrEqualTo(75000)) ..join('companies', 'company_id', 'id'); var richPerson = await query.getOne(_FakeExecutor()); - print(richPerson.toJson()); + print(richPerson?.toJson()); } class _FakeExecutor extends QueryExecutor { @@ -23,7 +23,7 @@ class _FakeExecutor extends QueryExecutor { @override Future> query( - String tableName, String query, Map substitutionValues, + String tableName, String? query, Map substitutionValues, [returningFields]) async { var now = DateTime.now(); print( @@ -42,25 +42,25 @@ class _FakeExecutor extends QueryExecutor { @orm @serializable abstract class _Employee extends Model { - String get firstName; + String? get firstName; - String get lastName; + String? get lastName; - double get salary; + double? get salary; } -class EmployeeQuery extends Query { +class EmployeeQuery extends Query { @override final QueryValues values = MapQueryValues(); - EmployeeQueryWhere _where; + EmployeeQueryWhere? _where; EmployeeQuery() { _where = EmployeeQueryWhere(this); } @override - EmployeeQueryWhere get where => _where; + EmployeeQueryWhere? get where => _where; @override String get tableName => 'employees'; diff --git a/packages/orm/angel_orm/example/main.g.dart b/packages/orm/angel_orm/example/main.g.dart index e13bd4ca..0c5634fe 100644 --- a/packages/orm/angel_orm/example/main.g.dart +++ b/packages/orm/angel_orm/example/main.g.dart @@ -17,30 +17,30 @@ class Employee extends _Employee { this.updatedAt}); @override - final String id; + final String? id; @override - final String firstName; + final String? firstName; @override - final String lastName; + final String? lastName; @override - final double salary; + final double? salary; @override - final DateTime createdAt; + final DateTime? createdAt; @override - final DateTime updatedAt; + final DateTime? updatedAt; Employee copyWith( - {String id, - String firstName, - String lastName, - double salary, - DateTime createdAt, - DateTime updatedAt}) { + {String? id, + String? firstName, + String? lastName, + double? salary, + DateTime? createdAt, + DateTime? updatedAt}) { return Employee( id: id ?? this.id, firstName: firstName ?? this.firstName, diff --git a/packages/orm/angel_orm/example/main.serializer.g.dart b/packages/orm/angel_orm/example/main.serializer.g.dart index 3fcb31f6..48e27fa8 100644 --- a/packages/orm/angel_orm/example/main.serializer.g.dart +++ b/packages/orm/angel_orm/example/main.serializer.g.dart @@ -9,26 +9,23 @@ part of 'main.dart'; abstract class EmployeeSerializer { static Employee fromMap(Map map) { return Employee( - id: map['id'] as String, - firstName: map['first_name'] as String, - lastName: map['last_name'] as String, - salary: map['salary'] as double, + id: map['id'] as String?, + firstName: map['first_name'] as String?, + lastName: map['last_name'] as String?, + salary: map['salary'] as double?, 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); } static Map toMap(Employee model) { - if (model == null) { - return null; - } return { 'id': model.id, 'first_name': model.firstName, diff --git a/packages/orm/angel_orm/lib/src/annotations.dart b/packages/orm/angel_orm/lib/src/annotations.dart index 1c06f020..891cddcd 100644 --- a/packages/orm/angel_orm/lib/src/annotations.dart +++ b/packages/orm/angel_orm/lib/src/annotations.dart @@ -17,7 +17,7 @@ class Orm { /// The name of the table to query. /// /// Inferred if not present. - final String tableName; + final String? tableName; /// Whether to generate migrations for this model. /// diff --git a/packages/orm/angel_orm/lib/src/builder.dart b/packages/orm/angel_orm/lib/src/builder.dart index 113f76f3..bf7dfa96 100644 --- a/packages/orm/angel_orm/lib/src/builder.dart +++ b/packages/orm/angel_orm/lib/src/builder.dart @@ -8,9 +8,9 @@ final DateFormat dateYmdHms = DateFormat('yyyy-MM-dd HH:mm:ss'); abstract class SqlExpressionBuilder { final Query query; final String columnName; - String _cast; + String? _cast; bool _isProperty = false; - String _substitution; + String? _substitution; SqlExpressionBuilder(this.query, this.columnName); @@ -21,15 +21,15 @@ abstract class SqlExpressionBuilder { bool get hasValue; - String compile(); + String? compile(); } class NumericSqlExpressionBuilder extends SqlExpressionBuilder { bool _hasValue = false; String _op = '='; - String _raw; - T _value; + String? _raw; + T? _value; NumericSqlExpressionBuilder(Query query, String columnName) : super(query, columnName); @@ -45,7 +45,7 @@ class NumericSqlExpressionBuilder } @override - String compile() { + String? compile() { if (_raw != null) return _raw; if (_value == null) return null; var v = _value.toString(); @@ -121,8 +121,8 @@ class EnumSqlExpressionBuilder extends SqlExpressionBuilder { final int Function(T) _getValue; bool _hasValue = false; String _op = '='; - String _raw; - int _value; + String? _raw; + int? _value; EnumSqlExpressionBuilder(Query query, String columnName, this._getValue) : super(query, columnName); @@ -141,7 +141,7 @@ class EnumSqlExpressionBuilder extends SqlExpressionBuilder { UnsupportedError('Enums do not support this operation.'); @override - String compile() { + String? compile() { if (_raw != null) return _raw; if (_value == null) return null; return '$_op $_value'; @@ -182,7 +182,7 @@ class EnumSqlExpressionBuilder extends SqlExpressionBuilder { class StringSqlExpressionBuilder extends SqlExpressionBuilder { bool _hasValue = false; - String _op = '=', _raw, _value; + String? _op = '=', _raw, _value; StringSqlExpressionBuilder(Query query, String columnName) : super(query, columnName); @@ -203,7 +203,7 @@ class StringSqlExpressionBuilder extends SqlExpressionBuilder { } @override - String compile() { + String? compile() { if (_raw != null) return _raw; if (_value == null) return null; return "$_op @$substitution"; @@ -232,7 +232,7 @@ class StringSqlExpressionBuilder extends SqlExpressionBuilder { /// carNameBuilder.like('%Mazda%'); /// carNameBuilder.like((name) => 'Mazda %$name%'); /// ``` - void like(String pattern, {String Function(String) sanitize}) { + void like(String pattern, {String Function(String)? sanitize}) { sanitize ??= (s) => pattern; _raw = 'LIKE \'' + sanitize('@$substitution') + '\''; query.substitutionValues[substitution] = pattern; @@ -287,8 +287,8 @@ class StringSqlExpressionBuilder extends SqlExpressionBuilder { class BooleanSqlExpressionBuilder extends SqlExpressionBuilder { bool _hasValue = false; - String _op = '=', _raw; - bool _value; + String? _op = '=', _raw; + bool? _value; BooleanSqlExpressionBuilder(Query query, String columnName) : super(query, columnName); @@ -304,10 +304,10 @@ class BooleanSqlExpressionBuilder extends SqlExpressionBuilder { } @override - String compile() { + String? compile() { if (_raw != null) return _raw; if (_value == null) return null; - var v = _value ? 'TRUE' : 'FALSE'; + var v = _value! ? 'TRUE' : 'FALSE'; if (_cast != null) v = 'CAST ($v AS $_cast)'; return '$_op $v'; } @@ -336,9 +336,14 @@ class BooleanSqlExpressionBuilder extends SqlExpressionBuilder { } class DateTimeSqlExpressionBuilder extends SqlExpressionBuilder { - NumericSqlExpressionBuilder _year, _month, _day, _hour, _minute, _second; + NumericSqlExpressionBuilder? _year, + _month, + _day, + _hour, + _minute, + _second; - String _raw; + String? _raw; DateTimeSqlExpressionBuilder(Query query, String columnName) : super(query, columnName); @@ -431,25 +436,25 @@ class DateTimeSqlExpressionBuilder extends SqlExpressionBuilder { } @override - String compile() { + String? compile() { if (_raw?.isNotEmpty == true) return _raw; - List parts = []; - if (year?.hasValue == true) { + var parts = []; + if (year.hasValue == true) { parts.add('YEAR($columnName) ${year.compile()}'); } - if (month?.hasValue == true) { + if (month.hasValue == true) { parts.add('MONTH($columnName) ${month.compile()}'); } - if (day?.hasValue == true) { + if (day.hasValue == true) { parts.add('DAY($columnName) ${day.compile()}'); } - if (hour?.hasValue == true) { + if (hour.hasValue == true) { parts.add('HOUR($columnName) ${hour.compile()}'); } - if (minute?.hasValue == true) { + if (minute.hasValue == true) { parts.add('MINUTE($columnName) ${minute.compile()}'); } - if (second?.hasValue == true) { + if (second.hasValue == true) { parts.add('SECOND($columnName) ${second.compile()}'); } @@ -460,9 +465,9 @@ class DateTimeSqlExpressionBuilder extends SqlExpressionBuilder { abstract class JsonSqlExpressionBuilder extends SqlExpressionBuilder { final List _properties = []; bool _hasValue = false; - T _value; - String _op; - String _raw; + T? _value; + String? _op; + String? _raw; JsonSqlExpressionBuilder(Query query, String columnName) : super(query, columnName); @@ -480,7 +485,7 @@ abstract class JsonSqlExpressionBuilder extends SqlExpressionBuilder { @override bool get hasValue => _hasValue || _properties.any((p) => p.hasValue); - _encodeValue(T v) => v; + T? _encodeValue(T? v) => v; bool _change(String op, T value) { _raw = null; @@ -501,7 +506,7 @@ abstract class JsonSqlExpressionBuilder extends SqlExpressionBuilder { } @override - String compile() { + String? compile() { var s = _compile(); if (!_properties.any((p) => p.hasValue)) return s; s ??= ''; @@ -515,7 +520,7 @@ abstract class JsonSqlExpressionBuilder extends SqlExpressionBuilder { s ??= ''; if (p.typed is! DateTimeSqlExpressionBuilder) { - s += '${p.typed.columnName} '; + s += '${p.typed!.columnName} '; } s += c; @@ -526,7 +531,7 @@ abstract class JsonSqlExpressionBuilder extends SqlExpressionBuilder { return s; } - String _compile() { + String? _compile() { if (_raw != null) return _raw; if (_value == null) return null; return "::jsonb $_op @$substitution::jsonb"; @@ -564,7 +569,7 @@ class ListSqlExpressionBuilder extends JsonSqlExpressionBuilder { : super(query, columnName); @override - _encodeValue(List v) => json.encode(v); + List? _encodeValue(List? v) => [json.encode(v)]; @override JsonSqlExpressionBuilderProperty _property(int name) { @@ -576,27 +581,27 @@ class JsonSqlExpressionBuilderProperty { final JsonSqlExpressionBuilder builder; final String name; final bool isInt; - SqlExpressionBuilder _typed; + SqlExpressionBuilder? _typed; JsonSqlExpressionBuilderProperty(this.builder, this.name, this.isInt); - SqlExpressionBuilder get typed => _typed; + SqlExpressionBuilder? get typed => _typed; bool get hasValue => _typed?.hasValue == true; - String compile() => _typed?.compile(); + String? compile() => _typed?.compile(); - T _set(T Function() value) { + T? _set(T Function() value) { if (_typed is T) { - return _typed as T; + return _typed as T?; } else if (_typed != null) { throw StateError( '$nameString is already typed as $_typed, and cannot be changed.'); } else { _typed = value() - .._cast = 'text' + ?.._cast = 'text' .._isProperty = true; - return _typed as T; + return _typed as T?; } } @@ -608,44 +613,56 @@ class JsonSqlExpressionBuilderProperty { void get isNotNull { builder .._hasValue = true - .._raw ??= '' - .._raw += "$nameString IS NOT NULL"; + .._raw ??= ''; + + var r = builder._raw; + if (r != null) { + builder._raw = r + '$nameString IS NOT NULL'; + } else { + builder._raw = '$nameString IS NOT NULL'; + } } void get isNull { builder .._hasValue = true - .._raw ??= '' - .._raw += "$nameString IS NULL"; + .._raw ??= ''; + + var r = builder._raw; + if (r != null) { + builder._raw = r + '$nameString IS NULL'; + } else { + builder._raw = '$nameString IS NULL'; + } } - StringSqlExpressionBuilder get asString { + StringSqlExpressionBuilder? get asString { return _set(() => StringSqlExpressionBuilder(builder.query, nameString)); } - BooleanSqlExpressionBuilder get asBool { + BooleanSqlExpressionBuilder? get asBool { return _set(() => BooleanSqlExpressionBuilder(builder.query, nameString)); } - DateTimeSqlExpressionBuilder get asDateTime { + DateTimeSqlExpressionBuilder? get asDateTime { return _set(() => DateTimeSqlExpressionBuilder(builder.query, nameString)); } - NumericSqlExpressionBuilder get asDouble { + NumericSqlExpressionBuilder? get asDouble { return _set( () => NumericSqlExpressionBuilder(builder.query, nameString)); } - NumericSqlExpressionBuilder get asInt { + NumericSqlExpressionBuilder? get asInt { return _set( () => NumericSqlExpressionBuilder(builder.query, nameString)); } - MapSqlExpressionBuilder get asMap { + MapSqlExpressionBuilder? get asMap { return _set(() => MapSqlExpressionBuilder(builder.query, nameString)); } - ListSqlExpressionBuilder get asList { + ListSqlExpressionBuilder? get asList { return _set(() => ListSqlExpressionBuilder(builder.query, nameString)); } } diff --git a/packages/orm/angel_orm/lib/src/join_builder.dart b/packages/orm/angel_orm/lib/src/join_builder.dart index 8a6a3ef0..d14305f8 100644 --- a/packages/orm/angel_orm/lib/src/join_builder.dart +++ b/packages/orm/angel_orm/lib/src/join_builder.dart @@ -5,12 +5,12 @@ import 'query.dart'; class JoinBuilder { final JoinType type; final Query from; - final String key, value, op, alias; + final String? key, value, op, alias; final bool aliasAllFields; /// A callback to produces the expression to join against, i.e. /// a table name, or the result of compiling a query. - final String Function() to; + final String? Function() to; final List additionalFields; JoinBuilder(this.type, this.from, this.to, this.key, this.value, @@ -39,7 +39,7 @@ class JoinBuilder { return right; } - String compile(Set trampoline) { + String? compile(Set? trampoline) { var compiledTo = to(); if (compiledTo == null) return null; var b = StringBuffer(); diff --git a/packages/orm/angel_orm/lib/src/migration.dart b/packages/orm/angel_orm/lib/src/migration.dart index 6d0dd52e..ec36dc5e 100644 --- a/packages/orm/angel_orm/lib/src/migration.dart +++ b/packages/orm/angel_orm/lib/src/migration.dart @@ -18,16 +18,16 @@ class Column { final bool isNullable; /// Specifies the length of a `VARCHAR`. - final int length; + final int? length; /// Explicitly defines a SQL type for this column. - final ColumnType type; + final ColumnType? type; /// Specifies what kind of index this column is, if any. final IndexType indexType; /// A custom SQL expression to execute, instead of a named column. - final String expression; + final String? expression; const Column( {this.isNullable = true, @@ -41,7 +41,7 @@ class Column { } class PrimaryKey extends Column { - const PrimaryKey({ColumnType columnType}) + const PrimaryKey({ColumnType? columnType}) : super(type: columnType, indexType: IndexType.primaryKey); } diff --git a/packages/orm/angel_orm/lib/src/query.dart b/packages/orm/angel_orm/lib/src/query.dart index 84ce78cf..60437a94 100644 --- a/packages/orm/angel_orm/lib/src/query.dart +++ b/packages/orm/angel_orm/lib/src/query.dart @@ -8,21 +8,21 @@ import 'query_values.dart'; import 'query_where.dart'; /// A SQL `SELECT` query builder. -abstract class Query extends QueryBase { +abstract class Query extends QueryBase { final List _joins = []; final Map _names = {}; final List _orderBy = []; // An optional "parent query". If provided, [reserveName] will operate in // the parent's context. - final Query parent; + final Query? parent; /// A map of field names to explicit SQL expressions. The expressions will be aliased /// to the given names. final Map expressions = {}; - String _crossJoin, _groupBy; - int _limit, _offset; + String? _crossJoin, _groupBy; + int? _limit, _offset; Query({this.parent}); @@ -52,10 +52,19 @@ abstract class Query extends QueryBase { /// Returns a unique version of [name], which will not produce a collision within /// the context of this [query]. String reserveName(String name) { - if (parent != null) return parent.reserveName(name); - var n = _names[name] ??= 0; - _names[name]++; - return n == 0 ? name : '${name}$n'; + if (parent != null) { + return parent!.reserveName(name); + } + // var n = _names[name] ??= 0; + // _names[name]++; + var n = 0; + var nn = _names[name]; + if (nn != null) { + n = nn; + nn++; + _names[name] = nn; + } + return n == 0 ? name : '$name$n'; } /// Makes a [Where] clause. @@ -67,27 +76,27 @@ abstract class Query extends QueryBase { /// Determines whether this query can be compiled. /// /// Used to prevent ambiguities in joins. - bool canCompile(Set trampoline) => true; + bool canCompile(Set? trampoline) => true; /// Shorthand for calling [where].or with a [Where] clause. 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. @@ -115,12 +124,12 @@ abstract class Query extends QueryBase { _crossJoin = tableName; } - String _joinAlias(Set trampoline) { + String _joinAlias(Set? trampoline) { int i = _joins.length; while (true) { var a = 'a$i'; - if (trampoline.add(a)) { + if (trampoline!.add(a)) { return a; } else { i++; @@ -128,7 +137,7 @@ abstract class Query extends QueryBase { } } - String Function() _compileJoin(tableName, Set trampoline) { + String? Function() _compileJoin(tableName, Set? trampoline) { if (tableName is String) { return () => tableName; } else if (tableName is Query) { @@ -145,7 +154,7 @@ abstract class Query extends QueryBase { void _makeJoin( tableName, - Set trampoline, + Set? trampoline, JoinType type, String localKey, String foreignKey, @@ -180,7 +189,7 @@ abstract class Query extends QueryBase { void join(tableName, String localKey, String foreignKey, {String op = '=', List additionalFields = const [], - Set trampoline}) { + Set? trampoline}) { _makeJoin(tableName, trampoline, JoinType.inner, localKey, foreignKey, op, additionalFields); } @@ -189,7 +198,7 @@ abstract class Query extends QueryBase { void leftJoin(tableName, String localKey, String foreignKey, {String op = '=', List additionalFields = const [], - Set trampoline}) { + Set? trampoline}) { _makeJoin(tableName, trampoline, JoinType.left, localKey, foreignKey, op, additionalFields); } @@ -198,7 +207,7 @@ abstract class Query extends QueryBase { void rightJoin(tableName, String localKey, String foreignKey, {String op = '=', List additionalFields = const [], - Set trampoline}) { + Set? trampoline}) { _makeJoin(tableName, trampoline, JoinType.right, localKey, foreignKey, op, additionalFields); } @@ -207,7 +216,7 @@ abstract class Query extends QueryBase { void fullOuterJoin(tableName, String localKey, String foreignKey, {String op = '=', List additionalFields = const [], - Set trampoline}) { + Set? trampoline}) { _makeJoin(tableName, trampoline, JoinType.full, localKey, foreignKey, op, additionalFields); } @@ -216,17 +225,17 @@ abstract class Query extends QueryBase { void selfJoin(tableName, String localKey, String foreignKey, {String op = '=', List additionalFields = const [], - Set trampoline}) { + Set? trampoline}) { _makeJoin(tableName, trampoline, JoinType.self, localKey, foreignKey, op, additionalFields); } @override - String compile(Set trampoline, + String? compile(Set? trampoline, {bool includeTableName = false, - String preamble, + String? preamble, bool withFields = true, - String fromQuery}) { + String? fromQuery}) { // One table MAY appear multiple times in a query. if (!canCompile(trampoline)) { return null; @@ -237,13 +246,13 @@ abstract class Query extends QueryBase { b.write(' '); List f; - var compiledJoins = {}; + var compiledJoins = {}; if (fields == null) { f = ['*']; } else { f = List.from(fields.map((s) { - var ss = includeTableName ? '$tableName.$s' : s; + String? ss = includeTableName ? '$tableName.$s' : s; if (expressions.containsKey(s)) { // ss = '(' + expressions[s] + ')'; ss = expressions[s]; @@ -297,8 +306,10 @@ abstract class Query extends QueryBase { } var whereClause = - where.compile(tableName: includeTableName ? tableName : null); - if (whereClause.isNotEmpty) b.write(' WHERE $whereClause'); + where?.compile(tableName: includeTableName ? tableName : null); + if (whereClause?.isNotEmpty == true) { + b.write(' WHERE $whereClause'); + } if (_groupBy != null) b.write(' GROUP BY $_groupBy'); for (var item in _orderBy) { b.write(' ORDER BY ${item.compile()}'); @@ -309,13 +320,13 @@ abstract class Query extends QueryBase { } @override - Future getOne(QueryExecutor executor) { + Future getOne(QueryExecutor executor) { //limit(1); return super.getOne(executor); } Future> delete(QueryExecutor executor) { - var sql = compile(Set(), preamble: 'DELETE', withFields: false); + var sql = compile({}, preamble: 'DELETE', withFields: false); if (_joins.isEmpty) { return executor @@ -334,11 +345,11 @@ abstract class Query extends QueryBase { } } - Future deleteOne(QueryExecutor executor) { + Future deleteOne(QueryExecutor executor) { return delete(executor).then((it) => it.isEmpty ? null : it.first); } - Future insert(QueryExecutor executor) { + Future insert(QueryExecutor executor) { var insertion = values.compileInsert(this, tableName); if (insertion == null) { @@ -346,7 +357,7 @@ abstract class Query extends QueryBase { } else { // TODO: How to do this in a non-Postgres DB? var returning = fields.map(adornWithTableName).join(', '); - var sql = compile(Set()); + var sql = compile({})!; sql = 'WITH $tableName as ($insertion RETURNING $returning) ' + sql; return executor .query(tableName, sql, substitutionValues) @@ -362,12 +373,14 @@ abstract class Query extends QueryBase { throw StateError('No values have been specified for update.'); } else { updateSql.write(' $valuesClause'); - var whereClause = where.compile(); - if (whereClause.isNotEmpty) updateSql.write(' WHERE $whereClause'); + var whereClause = where?.compile(); + if (whereClause?.isNotEmpty == true) { + updateSql.write(' WHERE $whereClause'); + } if (_limit != null) updateSql.write(' LIMIT $_limit'); var returning = fields.map(adornWithTableName).join(', '); - var sql = compile(Set()); + var sql = compile({})!; sql = 'WITH $tableName as ($updateSql RETURNING $returning) ' + sql; return executor @@ -376,7 +389,7 @@ abstract class Query extends QueryBase { } } - Future updateOne(QueryExecutor executor) { + Future updateOne(QueryExecutor executor) { return update(executor).then((it) => it.isEmpty ? null : it.first); } } diff --git a/packages/orm/angel_orm/lib/src/query_base.dart b/packages/orm/angel_orm/lib/src/query_base.dart index a8178195..c8a7da85 100644 --- a/packages/orm/angel_orm/lib/src/query_base.dart +++ b/packages/orm/angel_orm/lib/src/query_base.dart @@ -32,19 +32,21 @@ abstract class QueryBase { } }).join(', '); - String compile(Set trampoline, - {bool includeTableName = false, String preamble, bool withFields = true}); + String? compile(Set trampoline, + {bool includeTableName = false, + String? preamble, + bool withFields = true}); T deserialize(List row); Future> get(QueryExecutor executor) async { - var sql = compile(Set()); + var sql = compile({}); return executor .query(tableName, sql, substitutionValues) .then((it) => it.map(deserialize).toList()); } - Future getOne(QueryExecutor executor) { + Future getOne(QueryExecutor executor) { return get(executor).then((it) => it.isEmpty ? null : it.first); } diff --git a/packages/orm/angel_orm/lib/src/query_executor.dart b/packages/orm/angel_orm/lib/src/query_executor.dart index 85474365..cfb0997a 100644 --- a/packages/orm/angel_orm/lib/src/query_executor.dart +++ b/packages/orm/angel_orm/lib/src/query_executor.dart @@ -8,8 +8,8 @@ abstract class QueryExecutor { /// Executes a single query. Future> query( - String tableName, String query, Map substitutionValues, - [List returningFields]); + String tableName, String? query, Map substitutionValues, + [List? returningFields]); /// Enters a database transaction, performing the actions within, /// and returning the results of [f]. diff --git a/packages/orm/angel_orm/lib/src/query_values.dart b/packages/orm/angel_orm/lib/src/query_values.dart index 368cc8c6..34bd3157 100644 --- a/packages/orm/angel_orm/lib/src/query_values.dart +++ b/packages/orm/angel_orm/lib/src/query_values.dart @@ -14,7 +14,7 @@ abstract class QueryValues { } } - String compileInsert(Query query, String tableName) { + String? compileInsert(Query query, String tableName) { var data = Map.from(toMap()); var keys = data.keys.toList(); keys.where((k) => !query.fields.contains(k)).forEach(data.remove); @@ -37,7 +37,7 @@ abstract class QueryValues { return b.toString(); } - String compileForUpdate(Query query) { + String? compileForUpdate(Query query) { var data = toMap(); if (data.isEmpty) return null; var b = StringBuffer('SET'); diff --git a/packages/orm/angel_orm/lib/src/query_where.dart b/packages/orm/angel_orm/lib/src/query_where.dart index ebe6dd7b..e83b5eaa 100644 --- a/packages/orm/angel_orm/lib/src/query_where.dart +++ b/packages/orm/angel_orm/lib/src/query_where.dart @@ -2,25 +2,25 @@ import 'builder.dart'; /// Builds a SQL `WHERE` clause. abstract class QueryWhere { - final Set _and = Set(); - final Set _not = Set(); - final Set _or = Set(); + final Set _and = Set(); + final Set _not = Set(); + final Set _or = Set(); Iterable get expressionBuilders; - void and(QueryWhere other) { + void and(QueryWhere? other) { _and.add(other); } - void not(QueryWhere other) { + void not(QueryWhere? other) { _not.add(other); } - void or(QueryWhere other) { + void or(QueryWhere? other) { _or.add(other); } - String compile({String tableName}) { + String compile({String? tableName}) { var b = StringBuffer(); int i = 0; @@ -40,17 +40,17 @@ abstract class QueryWhere { } for (var other in _and) { - var sql = other.compile(); + var sql = other!.compile(); if (sql.isNotEmpty) b.write(' AND ($sql)'); } for (var other in _not) { - var sql = other.compile(); + var sql = other!.compile(); if (sql.isNotEmpty) b.write(' NOT ($sql)'); } for (var other in _or) { - var sql = other.compile(); + var sql = other!.compile(); if (sql.isNotEmpty) b.write(' OR ($sql)'); } diff --git a/packages/orm/angel_orm/lib/src/relations.dart b/packages/orm/angel_orm/lib/src/relations.dart index 1ca6e357..6dac4674 100644 --- a/packages/orm/angel_orm/lib/src/relations.dart +++ b/packages/orm/angel_orm/lib/src/relations.dart @@ -9,11 +9,11 @@ abstract class RelationshipType { class Relationship { final int type; - final String localKey; - final String foreignKey; - final String foreignTable; - final bool cascadeOnDelete; - final JoinType joinType; + final String? localKey; + final String? foreignKey; + final String? foreignTable; + final bool? cascadeOnDelete; + final JoinType? joinType; const Relationship(this.type, {this.localKey, @@ -25,11 +25,11 @@ class Relationship { class HasMany extends Relationship { const HasMany( - {String localKey, - String foreignKey, - String foreignTable, + {String? localKey, + String? foreignKey, + String? foreignTable, bool cascadeOnDelete = false, - JoinType joinType}) + JoinType? joinType}) : super(RelationshipType.hasMany, localKey: localKey, foreignKey: foreignKey, @@ -42,11 +42,11 @@ const HasMany hasMany = HasMany(); class HasOne extends Relationship { const HasOne( - {String localKey, - String foreignKey, - String foreignTable, + {String? localKey, + String? foreignKey, + String? foreignTable, bool cascadeOnDelete = false, - JoinType joinType}) + JoinType? joinType}) : super(RelationshipType.hasOne, localKey: localKey, foreignKey: foreignKey, @@ -59,10 +59,10 @@ const HasOne hasOne = HasOne(); class BelongsTo extends Relationship { const BelongsTo( - {String localKey, - String foreignKey, - String foreignTable, - JoinType joinType}) + {String? localKey, + String? foreignKey, + String? foreignTable, + JoinType? joinType}) : super(RelationshipType.belongsTo, localKey: localKey, foreignKey: foreignKey, @@ -76,11 +76,11 @@ class ManyToMany extends Relationship { final Type through; const ManyToMany(this.through, - {String localKey, - String foreignKey, - String foreignTable, + {String? localKey, + String? foreignKey, + String? foreignTable, bool cascadeOnDelete = false, - JoinType joinType}) + JoinType? joinType}) : super( RelationshipType.hasMany, // Many-to-Many is actually just a hasMany localKey: localKey, diff --git a/packages/orm/angel_orm/lib/src/union.dart b/packages/orm/angel_orm/lib/src/union.dart index 048ebf31..49266feb 100644 --- a/packages/orm/angel_orm/lib/src/union.dart +++ b/packages/orm/angel_orm/lib/src/union.dart @@ -11,7 +11,7 @@ class Union extends QueryBase { @override final String tableName; - Union(this.left, this.right, {this.all = false, String tableName}) + Union(this.left, this.right, {this.all = false, String? tableName}) : this.tableName = tableName ?? left.tableName { substitutionValues ..addAll(left.substitutionValues) @@ -27,7 +27,7 @@ class Union extends QueryBase { @override String compile(Set trampoline, {bool includeTableName = false, - String preamble, + String? preamble, bool withFields = true}) { var selector = all == true ? 'UNION ALL' : 'UNION'; var t1 = Set.from(trampoline); diff --git a/packages/orm/angel_orm/pubspec.yaml b/packages/orm/angel_orm/pubspec.yaml index 007081a3..3c9a9aea 100644 --- a/packages/orm/angel_orm/pubspec.yaml +++ b/packages/orm/angel_orm/pubspec.yaml @@ -1,10 +1,9 @@ name: angel_orm -version: 3.0.0 +version: 4.0.0 description: Runtime support for Angel's ORM. Includes base classes for queries. -author: Tobe O homepage: https://github.com/angel-dart/orm environment: - sdk: '>=2.10.0 <3.0.0' + sdk: '>=2.12.0 <3.0.0' dependencies: charcode: ^1.2.0 intl: ^0.17.0 @@ -14,18 +13,18 @@ dev_dependencies: angel_model: git: url: https://github.com/dukefirehawk/angel.git - ref: sdk-2.12.x + ref: sdk-2.12.x_nnbd path: packages/model angel_serialize: git: url: https://github.com/dukefirehawk/angel.git - ref: sdk-2.12.x + ref: sdk-2.12.x_nnbd path: packages/serialize/angel_serialize angel_serialize_generator: git: url: https://github.com/dukefirehawk/angel.git - ref: sdk-2.12.x + ref: sdk-2.12.x_nnbd path: packages/serialize/angel_serialize_generator - build_runner: ^1.11.5 + build_runner: ^2.0.1 pedantic: ^1.11.0 - test: ^1.16.5 + test: ^1.17.3 diff --git a/packages/orm/angel_orm_generator/AUTHORS.md b/packages/orm/angel_orm_generator/AUTHORS.md new file mode 100644 index 00000000..2a973de6 --- /dev/null +++ b/packages/orm/angel_orm_generator/AUTHORS.md @@ -0,0 +1,2 @@ +Tobe O +Thomas Hii \ No newline at end of file diff --git a/packages/orm/angel_orm_generator/CHANGELOG.md b/packages/orm/angel_orm_generator/CHANGELOG.md index 21f91417..a14bfaf9 100644 --- a/packages/orm/angel_orm_generator/CHANGELOG.md +++ b/packages/orm/angel_orm_generator/CHANGELOG.md @@ -1,3 +1,9 @@ +# 4.0.0 +* Migrated to support Dart SDK 2.12.x NNBD + +# 3.0.0 +* Migrated to work with Dart SDK 2.12.x Non NNBD + # 2.1.0-beta.2 * Support for custom SQL expressions. diff --git a/packages/orm/angel_orm_mysql/AUTHORS.md b/packages/orm/angel_orm_mysql/AUTHORS.md new file mode 100644 index 00000000..2a973de6 --- /dev/null +++ b/packages/orm/angel_orm_mysql/AUTHORS.md @@ -0,0 +1,2 @@ +Tobe O +Thomas Hii \ No newline at end of file diff --git a/packages/orm/angel_orm_mysql/CHANGELOG.md b/packages/orm/angel_orm_mysql/CHANGELOG.md new file mode 100644 index 00000000..b8984b0a --- /dev/null +++ b/packages/orm/angel_orm_mysql/CHANGELOG.md @@ -0,0 +1,8 @@ +# 3.0.0 +* Migrated to support Dart SDK 2.12.x NNBD + +# 2.0.0 +* Migrated to work with Dart SDK 2.12.x Non NNBD + +# 1.0.0 +* First version. \ No newline at end of file diff --git a/packages/orm/angel_orm_postgres/AUTHORS.md b/packages/orm/angel_orm_postgres/AUTHORS.md new file mode 100644 index 00000000..2a973de6 --- /dev/null +++ b/packages/orm/angel_orm_postgres/AUTHORS.md @@ -0,0 +1,2 @@ +Tobe O +Thomas Hii \ No newline at end of file diff --git a/packages/orm/angel_orm_postgres/CHANGELOG.md b/packages/orm/angel_orm_postgres/CHANGELOG.md index cc7baa03..36634b2f 100644 --- a/packages/orm/angel_orm_postgres/CHANGELOG.md +++ b/packages/orm/angel_orm_postgres/CHANGELOG.md @@ -1,3 +1,9 @@ +# 3.0.0 +* Migrated to support Dart SDK 2.12.x NNBD + +# 2.0.0 +* Migrated to work with Dart SDK 2.12.x Non NNBD + # 1.1.0-beta.1 * Improvements in how transactions are handled; rethrow failed exceptions after rolling back. * Remove deprecated executor classes. diff --git a/packages/orm/angel_orm_test/AUTHORS.md b/packages/orm/angel_orm_test/AUTHORS.md new file mode 100644 index 00000000..2a973de6 --- /dev/null +++ b/packages/orm/angel_orm_test/AUTHORS.md @@ -0,0 +1,2 @@ +Tobe O +Thomas Hii \ No newline at end of file diff --git a/packages/orm/angel_orm_test/CHANGELOG.md b/packages/orm/angel_orm_test/CHANGELOG.md new file mode 100644 index 00000000..b8984b0a --- /dev/null +++ b/packages/orm/angel_orm_test/CHANGELOG.md @@ -0,0 +1,8 @@ +# 3.0.0 +* Migrated to support Dart SDK 2.12.x NNBD + +# 2.0.0 +* Migrated to work with Dart SDK 2.12.x Non NNBD + +# 1.0.0 +* First version. \ No newline at end of file