merge from master

This commit is contained in:
Tobe O 2019-04-28 14:55:31 -04:00
commit 5186ae8111
3 changed files with 68 additions and 29 deletions

View file

@ -2,3 +2,7 @@ include: package:pedantic/analysis_options.yaml
analyzer: analyzer:
strong-mode: strong-mode:
implicit-casts: false implicit-casts: false
linter:
rules:
- unnecessary_const
- unnecessary_new

View file

@ -28,15 +28,22 @@ class GreetingMigration extends Migration {
// ************************************************************************** // **************************************************************************
class GreetingQuery extends Query<Greeting, GreetingQueryWhere> { class GreetingQuery extends Query<Greeting, GreetingQueryWhere> {
GreetingQuery() { GreetingQuery({Set<String> trampoline}) {
_where = new GreetingQueryWhere(this); trampoline ??= Set();
trampoline.add(tableName);
_where = GreetingQueryWhere(this);
} }
@override @override
final GreetingQueryValues values = new GreetingQueryValues(); final GreetingQueryValues values = GreetingQueryValues();
GreetingQueryWhere _where; GreetingQueryWhere _where;
@override
get casts {
return {};
}
@override @override
get tableName { get tableName {
return 'greetings'; return 'greetings';
@ -54,12 +61,12 @@ class GreetingQuery extends Query<Greeting, GreetingQueryWhere> {
@override @override
GreetingQueryWhere newWhereClause() { GreetingQueryWhere newWhereClause() {
return new GreetingQueryWhere(this); return GreetingQueryWhere(this);
} }
static Greeting parseRow(List row) { static Greeting parseRow(List row) {
if (row.every((x) => x == null)) return null; if (row.every((x) => x == null)) return null;
var model = new Greeting( var model = Greeting(
id: row[0].toString(), id: row[0].toString(),
message: (row[1] as String), message: (row[1] as String),
createdAt: (row[2] as DateTime), createdAt: (row[2] as DateTime),
@ -75,10 +82,10 @@ class GreetingQuery extends Query<Greeting, GreetingQueryWhere> {
class GreetingQueryWhere extends QueryWhere { class GreetingQueryWhere extends QueryWhere {
GreetingQueryWhere(GreetingQuery query) GreetingQueryWhere(GreetingQuery query)
: id = new NumericSqlExpressionBuilder<int>(query, 'id'), : id = NumericSqlExpressionBuilder<int>(query, 'id'),
message = new StringSqlExpressionBuilder(query, 'message'), message = StringSqlExpressionBuilder(query, 'message'),
createdAt = new DateTimeSqlExpressionBuilder(query, 'created_at'), createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
updatedAt = new DateTimeSqlExpressionBuilder(query, 'updated_at'); updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at');
final NumericSqlExpressionBuilder<int> id; final NumericSqlExpressionBuilder<int> id;
@ -95,11 +102,16 @@ class GreetingQueryWhere extends QueryWhere {
} }
class GreetingQueryValues extends MapQueryValues { class GreetingQueryValues extends MapQueryValues {
int get id { @override
return (values['id'] as int); get casts {
return {};
} }
set id(int value) => values['id'] = value; String get id {
return (values['id'] as String);
}
set id(String value) => values['id'] = value;
String get message { String get message {
return (values['message'] as String); return (values['message'] as String);
} }
@ -116,11 +128,9 @@ class GreetingQueryValues extends MapQueryValues {
set updatedAt(DateTime value) => values['updated_at'] = value; set updatedAt(DateTime value) => values['updated_at'] = value;
void copyFrom(Greeting model) { void copyFrom(Greeting model) {
values.addAll({ message = model.message;
'message': model.message, createdAt = model.createdAt;
'created_at': model.createdAt, updatedAt = model.updatedAt;
'updated_at': model.updatedAt
});
} }
} }
@ -146,7 +156,7 @@ class Greeting extends _Greeting {
Greeting copyWith( Greeting copyWith(
{String id, String message, DateTime createdAt, DateTime updatedAt}) { {String id, String message, DateTime createdAt, DateTime updatedAt}) {
return new Greeting( return Greeting(
id: id ?? this.id, id: id ?? this.id,
message: message ?? this.message, message: message ?? this.message,
createdAt: createdAt ?? this.createdAt, createdAt: createdAt ?? this.createdAt,
@ -166,6 +176,11 @@ class Greeting extends _Greeting {
return hashObjects([id, message, createdAt, updatedAt]); return hashObjects([id, message, createdAt, updatedAt]);
} }
@override
String toString() {
return "Greeting(id=$id, message=$message, createdAt=$createdAt, updatedAt=$updatedAt)";
}
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
return GreetingSerializer.toMap(this); return GreetingSerializer.toMap(this);
} }
@ -175,14 +190,35 @@ class Greeting extends _Greeting {
// SerializerGenerator // SerializerGenerator
// ************************************************************************** // **************************************************************************
abstract class GreetingSerializer { const GreetingSerializer greetingSerializer = GreetingSerializer();
class GreetingEncoder extends Converter<Greeting, Map> {
const GreetingEncoder();
@override
Map convert(Greeting model) => GreetingSerializer.toMap(model);
}
class GreetingDecoder extends Converter<Map, Greeting> {
const GreetingDecoder();
@override
Greeting convert(Map map) => GreetingSerializer.fromMap(map);
}
class GreetingSerializer extends Codec<Greeting, Map> {
const GreetingSerializer();
@override
get encoder => const GreetingEncoder();
@override
get decoder => const GreetingDecoder();
static Greeting fromMap(Map map) { static Greeting fromMap(Map map) {
if (map['message'] == null) { if (map['message'] == null) {
throw new FormatException( throw FormatException("Missing required field 'message' on Greeting.");
"Missing required field 'message' on Greeting.");
} }
return new Greeting( return Greeting(
id: map['id'] as String, id: map['id'] as String,
message: map['message'] as String, message: map['message'] as String,
createdAt: map['created_at'] != null createdAt: map['created_at'] != null
@ -202,8 +238,7 @@ abstract class GreetingSerializer {
return null; return null;
} }
if (model.message == null) { if (model.message == null) {
throw new FormatException( throw FormatException("Missing required field 'message' on Greeting.");
"Missing required field 'message' on Greeting.");
} }
return { return {
@ -216,7 +251,7 @@ abstract class GreetingSerializer {
} }
abstract class GreetingFields { abstract class GreetingFields {
static const List<String> allFields = const <String>[ static const List<String> allFields = <String>[
id, id,
message, message,
createdAt, createdAt,

View file

@ -13,7 +13,7 @@ dependencies:
angel_orm: ^2.0.0-dev # Migration runtime support angel_orm: ^2.0.0-dev # Migration runtime support
angel_orm_postgres: ^1.0.0-dev # PostgreSQL support for Angel ORM angel_orm_postgres: ^1.0.0-dev # PostgreSQL support for Angel ORM
angel_serialize: ^2.0.0 # Serialization runtime support angel_serialize: ^2.0.0 # Serialization runtime support
angel_production: ^1.0.0-alpha angel_production: ^1.0.0 # Production application runner.
angel_static: ^2.0.0 # Static file server angel_static: ^2.0.0 # Static file server
angel_validate: ^2.0.0 # Allows for validation of input data angel_validate: ^2.0.0 # Allows for validation of input data
dev_dependencies: dev_dependencies:
@ -23,6 +23,6 @@ dev_dependencies:
angel_serialize_generator: ^2.0.0 # Generates model serialization code angel_serialize_generator: ^2.0.0 # Generates model serialization code
angel_test: ^2.0.0 # Utilities for testing Angel servers. angel_test: ^2.0.0 # Utilities for testing Angel servers.
build_runner: ^1.0.0 # Runs builds build_runner: ^1.0.0 # Runs builds
io: ^0.3.2 io: ^0.3.2 # For pretty printing.
pedantic: ^1.0.0 pedantic: ^1.0.0 # Enforces Dart style conventions.
test: ^1.0.0 test: ^1.0.0 # For unit testing.