diff --git a/extras/integration_tests/tests/lib/database/database.dart b/extras/integration_tests/tests/lib/database/database.dart index a033fd37..563085f7 100644 --- a/extras/integration_tests/tests/lib/database/database.dart +++ b/extras/integration_tests/tests/lib/database/database.dart @@ -102,9 +102,10 @@ class Database extends _$Database { beforeOpen: (details) async { if (details.wasCreated) { // make sure that transactions can be used in the beforeOpen callback. - await transaction(() { - return into(users) - .insertAll([People.dash, People.duke, People.gopher]); + await transaction(() async { + for (var user in [People.dash, People.duke, People.gopher]) { + await into(users).insert(user); + } }); } }, diff --git a/moor/test/insert_test.dart b/moor/test/insert_test.dart index efeece27..9f4aff91 100644 --- a/moor/test/insert_test.dart +++ b/moor/test/insert_test.dart @@ -72,6 +72,7 @@ void main() { }); test('runs bulk inserts', () async { + // ignore: deprecated_member_use_from_same_package await db.into(db.todosTable).insertAll(const [ TodosTableCompanion(content: Value('a')), TodosTableCompanion(title: Value('title'), content: Value('b')), @@ -95,6 +96,7 @@ void main() { }); test('runs bulk inserts with OR REPLACE', () async { + // ignore: deprecated_member_use_from_same_package await db.into(db.todosTable).insertAll(const [ TodosTableCompanion(content: Value('a')), TodosTableCompanion(title: Value('title'), content: Value('b')), diff --git a/moor_generator/lib/src/analyzer/dart/column_parser.dart b/moor_generator/lib/src/analyzer/dart/column_parser.dart index 33893df1..b5e8f056 100644 --- a/moor_generator/lib/src/analyzer/dart/column_parser.dart +++ b/moor_generator/lib/src/analyzer/dart/column_parser.dart @@ -112,9 +112,9 @@ class ColumnParser { final minArg = base.findNamedArgument(args, 'min'); final maxArg = base.findNamedArgument(args, 'max'); - foundFeatures.add(LimitingTextLength.withLength( - min: base.readIntLiteral(minArg, () {}), - max: base.readIntLiteral(maxArg, () {}), + foundFeatures.add(LimitingTextLength( + minLength: base.readIntLiteral(minArg, () {}), + maxLength: base.readIntLiteral(maxArg, () {}), )); break; case _methodAutoIncrement: diff --git a/moor_generator/lib/src/model/specified_column.dart b/moor_generator/lib/src/model/specified_column.dart index 4e1a31cc..5acfd9c6 100644 --- a/moor_generator/lib/src/model/specified_column.dart +++ b/moor_generator/lib/src/model/specified_column.dart @@ -1,34 +1,38 @@ -import 'package:built_value/built_value.dart'; import 'package:moor_generator/src/analyzer/sql_queries/meta/declarations.dart'; import 'package:moor_generator/src/backends/build/moor_builder.dart'; import 'package:moor_generator/src/model/used_type_converter.dart'; -part 'specified_column.g.dart'; - enum ColumnType { integer, text, boolean, datetime, blob, real } /// Name of a column. Contains additional info on whether the name was chosen /// implicitly (based on the dart getter name) or explicitly (via an named()) /// call in the column builder dsl. -abstract class ColumnName implements Built { +class ColumnName { /// A column name is implicit if it has been looked up with the associated /// field name in the table class. It's explicit if `.named()` was called in /// the column builder. - bool get implicit; + final bool implicit; - String get name; + final String name; - ColumnName._(); + ColumnName.implicitly(this.name) : implicit = true; + ColumnName.explicitly(this.name) : implicit = false; - factory ColumnName([updates(ColumnNameBuilder b)]) = _$ColumnName; + @override + int get hashCode => name.hashCode + implicit.hashCode * 31; - factory ColumnName.implicitly(String name) => ColumnName((b) => b - ..implicit = true - ..name = name); + @override + bool operator ==(other) { + if (other.runtimeType != runtimeType) return false; + // ignore: test_types_in_equals + final typedOther = other as ColumnName; + return typedOther.implicit == implicit && typedOther.name == name; + } - factory ColumnName.explicitly(String name) => ColumnName((b) => b - ..implicit = false - ..name = name); + @override + String toString() { + return 'ColumnName($name, implicit = $implicit)'; + } } const Map dartTypeNames = { @@ -206,23 +210,24 @@ class AutoIncrement extends ColumnFeature { int get hashCode => 1337420; } -abstract class LimitingTextLength extends ColumnFeature - implements Built { - @nullable - int get minLength; +class LimitingTextLength extends ColumnFeature { + final int minLength; - @nullable - int get maxLength; + final int maxLength; - LimitingTextLength._(); + LimitingTextLength({this.minLength, this.maxLength}); - factory LimitingTextLength(void updates(LimitingTextLengthBuilder b)) = - _$LimitingTextLength; + @override + int get hashCode => minLength.hashCode ^ maxLength.hashCode; - factory LimitingTextLength.withLength({int min, int max}) => - LimitingTextLength((b) => b - ..minLength = min - ..maxLength = max); + @override + bool operator ==(other) { + if (other.runtimeType != runtimeType) return false; + // ignore: test_types_in_equals + final typedOther = other as LimitingTextLength; + return typedOther.minLength == minLength && + typedOther.maxLength == maxLength; + } } class Reference extends ColumnFeature { diff --git a/moor_generator/lib/src/model/specified_column.g.dart b/moor_generator/lib/src/model/specified_column.g.dart deleted file mode 100644 index b9dcd6e2..00000000 --- a/moor_generator/lib/src/model/specified_column.g.dart +++ /dev/null @@ -1,187 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'specified_column.dart'; - -// ************************************************************************** -// BuiltValueGenerator -// ************************************************************************** - -class _$ColumnName extends ColumnName { - @override - final bool implicit; - @override - final String name; - - factory _$ColumnName([void Function(ColumnNameBuilder) updates]) => - (new ColumnNameBuilder()..update(updates)).build(); - - _$ColumnName._({this.implicit, this.name}) : super._() { - if (implicit == null) { - throw new BuiltValueNullFieldError('ColumnName', 'implicit'); - } - if (name == null) { - throw new BuiltValueNullFieldError('ColumnName', 'name'); - } - } - - @override - ColumnName rebuild(void Function(ColumnNameBuilder) updates) => - (toBuilder()..update(updates)).build(); - - @override - ColumnNameBuilder toBuilder() => new ColumnNameBuilder()..replace(this); - - @override - bool operator ==(Object other) { - if (identical(other, this)) return true; - return other is ColumnName && - implicit == other.implicit && - name == other.name; - } - - @override - int get hashCode { - return $jf($jc($jc(0, implicit.hashCode), name.hashCode)); - } - - @override - String toString() { - return (newBuiltValueToStringHelper('ColumnName') - ..add('implicit', implicit) - ..add('name', name)) - .toString(); - } -} - -class ColumnNameBuilder implements Builder { - _$ColumnName _$v; - - bool _implicit; - bool get implicit => _$this._implicit; - set implicit(bool implicit) => _$this._implicit = implicit; - - String _name; - String get name => _$this._name; - set name(String name) => _$this._name = name; - - ColumnNameBuilder(); - - ColumnNameBuilder get _$this { - if (_$v != null) { - _implicit = _$v.implicit; - _name = _$v.name; - _$v = null; - } - return this; - } - - @override - void replace(ColumnName other) { - if (other == null) { - throw new ArgumentError.notNull('other'); - } - _$v = other as _$ColumnName; - } - - @override - void update(void Function(ColumnNameBuilder) updates) { - if (updates != null) updates(this); - } - - @override - _$ColumnName build() { - final _$result = _$v ?? new _$ColumnName._(implicit: implicit, name: name); - replace(_$result); - return _$result; - } -} - -class _$LimitingTextLength extends LimitingTextLength { - @override - final int minLength; - @override - final int maxLength; - - factory _$LimitingTextLength( - [void Function(LimitingTextLengthBuilder) updates]) => - (new LimitingTextLengthBuilder()..update(updates)).build(); - - _$LimitingTextLength._({this.minLength, this.maxLength}) : super._(); - - @override - LimitingTextLength rebuild( - void Function(LimitingTextLengthBuilder) updates) => - (toBuilder()..update(updates)).build(); - - @override - LimitingTextLengthBuilder toBuilder() => - new LimitingTextLengthBuilder()..replace(this); - - @override - bool operator ==(Object other) { - if (identical(other, this)) return true; - return other is LimitingTextLength && - minLength == other.minLength && - maxLength == other.maxLength; - } - - @override - int get hashCode { - return $jf($jc($jc(0, minLength.hashCode), maxLength.hashCode)); - } - - @override - String toString() { - return (newBuiltValueToStringHelper('LimitingTextLength') - ..add('minLength', minLength) - ..add('maxLength', maxLength)) - .toString(); - } -} - -class LimitingTextLengthBuilder - implements Builder { - _$LimitingTextLength _$v; - - int _minLength; - int get minLength => _$this._minLength; - set minLength(int minLength) => _$this._minLength = minLength; - - int _maxLength; - int get maxLength => _$this._maxLength; - set maxLength(int maxLength) => _$this._maxLength = maxLength; - - LimitingTextLengthBuilder(); - - LimitingTextLengthBuilder get _$this { - if (_$v != null) { - _minLength = _$v.minLength; - _maxLength = _$v.maxLength; - _$v = null; - } - return this; - } - - @override - void replace(LimitingTextLength other) { - if (other == null) { - throw new ArgumentError.notNull('other'); - } - _$v = other as _$LimitingTextLength; - } - - @override - void update(void Function(LimitingTextLengthBuilder) updates) { - if (updates != null) updates(this); - } - - @override - _$LimitingTextLength build() { - final _$result = _$v ?? - new _$LimitingTextLength._(minLength: minLength, maxLength: maxLength); - replace(_$result); - return _$result; - } -} - -// ignore_for_file: always_put_control_body_on_new_line,always_specify_types,annotate_overrides,avoid_annotating_with_dynamic,avoid_as,avoid_catches_without_on_clauses,avoid_returning_this,lines_longer_than_80_chars,omit_local_variable_types,prefer_expression_function_bodies,sort_constructors_first,test_types_in_equals,unnecessary_const,unnecessary_new diff --git a/moor_generator/pubspec.yaml b/moor_generator/pubspec.yaml index 871a4aef..10684ca2 100644 --- a/moor_generator/pubspec.yaml +++ b/moor_generator/pubspec.yaml @@ -18,7 +18,6 @@ dependencies: analyzer_plugin: '>=0.1.0 <0.3.0' collection: ^1.14.0 recase: ^2.0.1 - built_value: ^6.3.0 source_gen: ^0.9.4 source_span: ^1.5.5 build: ^1.1.0 @@ -32,7 +31,6 @@ dev_dependencies: test: ^1.6.0 test_core: ^0.2.0 build_runner: ^1.6.7 - built_value_generator: ^6.3.0 build_test: ^0.10.0 dependency_overrides: diff --git a/moor_generator/test/analyzer/dart/table_parser_test.dart b/moor_generator/test/analyzer/dart/table_parser_test.dart index 475da1f0..82d91c32 100644 --- a/moor_generator/test/analyzer/dart/table_parser_test.dart +++ b/moor_generator/test/analyzer/dart/table_parser_test.dart @@ -126,7 +126,7 @@ void main() { table.columns.singleWhere((col) => col.name.name == 'user_name'); expect(idColumn.features, - contains(LimitingTextLength.withLength(min: 6, max: 32))); + contains(LimitingTextLength(minLength: 6, maxLength: 32))); }); test('should only parse max length when relevant', () async { @@ -134,8 +134,7 @@ void main() { final idColumn = table.columns.singleWhere((col) => col.dartGetterName == 'onlyMax'); - expect( - idColumn.features, contains(LimitingTextLength.withLength(max: 100))); + expect(idColumn.features, contains(LimitingTextLength(maxLength: 100))); }); test('parses custom constraints', () async {