mirror of https://github.com/AMT-Cheif/drift.git
Remove built_value(_generator) dependency from generator
This commit is contained in:
parent
9f1aafbcef
commit
98470109cf
|
@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
|
|
@ -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')),
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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<ColumnName, ColumnNameBuilder> {
|
||||
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<ColumnType, String> dartTypeNames = {
|
||||
|
@ -206,23 +210,24 @@ class AutoIncrement extends ColumnFeature {
|
|||
int get hashCode => 1337420;
|
||||
}
|
||||
|
||||
abstract class LimitingTextLength extends ColumnFeature
|
||||
implements Built<LimitingTextLength, LimitingTextLengthBuilder> {
|
||||
@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 {
|
||||
|
|
|
@ -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, ColumnNameBuilder> {
|
||||
_$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, LimitingTextLengthBuilder> {
|
||||
_$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
|
|
@ -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:
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue