Fix health issues

This commit is contained in:
Tobe O 2019-04-02 19:19:01 -04:00
parent d1d3b05ac3
commit a5ba325583
7 changed files with 42 additions and 37 deletions

View file

@ -1,3 +1,4 @@
include: package:pedantic/analysis_options.yaml
analyzer: analyzer:
strong-mode: strong-mode:
implicit-casts: false implicit-casts: false

View file

@ -11,7 +11,7 @@ class Orm {
/// Defaults to [:true:]. /// Defaults to [:true:].
final bool generateMigrations; final bool generateMigrations;
const Orm({this.tableName, this.generateMigrations: true}); const Orm({this.tableName, this.generateMigrations = true});
} }
@deprecated @deprecated
@ -20,8 +20,8 @@ class Join {
final String foreignKey; final String foreignKey;
final JoinType type; final JoinType type;
const Join(this.against, this.foreignKey, {this.type: JoinType.inner}); const Join(this.against, this.foreignKey, {this.type = JoinType.inner});
} }
/// The various types of [Join]. /// The various types of join.
enum JoinType { inner, left, right, full, self } enum JoinType { inner, left, right, full, self }

View file

@ -372,23 +372,23 @@ class DateTimeSqlExpressionBuilder extends SqlExpressionBuilder<DateTime> {
operator >=(DateTime value) => _change('>=', value, true); operator >=(DateTime value) => _change('>=', value, true);
void equals(DateTime value, {bool includeTime: true}) { void equals(DateTime value, {bool includeTime = true}) {
_change('=', value, includeTime != false); _change('=', value, includeTime != false);
} }
void lessThan(DateTime value, {bool includeTime: true}) { void lessThan(DateTime value, {bool includeTime = true}) {
_change('<', value, includeTime != false); _change('<', value, includeTime != false);
} }
void lessThanOrEqualTo(DateTime value, {bool includeTime: true}) { void lessThanOrEqualTo(DateTime value, {bool includeTime = true}) {
_change('<=', value, includeTime != false); _change('<=', value, includeTime != false);
} }
void greaterThan(DateTime value, {bool includeTime: true}) { void greaterThan(DateTime value, {bool includeTime = true}) {
_change('>', value, includeTime != false); _change('>', value, includeTime != false);
} }
void greaterThanOrEqualTo(DateTime value, {bool includeTime: true}) { void greaterThanOrEqualTo(DateTime value, {bool includeTime = true}) {
_change('>=', value, includeTime != false); _change('>=', value, includeTime != false);
} }

View file

@ -27,10 +27,10 @@ class Column {
final IndexType indexType; final IndexType indexType;
const Column( const Column(
{this.isNullable: true, {this.isNullable = true,
this.length, this.length,
this.type, this.type,
this.indexType: IndexType.none}); this.indexType = IndexType.none});
} }
class PrimaryKey extends Column { class PrimaryKey extends Column {

View file

@ -28,7 +28,7 @@ abstract class QueryBase<T> {
}).join(', '); }).join(', ');
String compile(Set<String> trampoline, String compile(Set<String> trampoline,
{bool includeTableName: false, String preamble, bool withFields: true}); {bool includeTableName = false, String preamble, bool withFields = true});
T deserialize(List row); T deserialize(List row);
@ -56,7 +56,7 @@ class OrderBy {
final String key; final String key;
final bool descending; final bool descending;
const OrderBy(this.key, {this.descending: false}); const OrderBy(this.key, {this.descending = false});
String compile() => descending ? '$key DESC' : '$key ASC'; String compile() => descending ? '$key DESC' : '$key ASC';
} }
@ -64,7 +64,7 @@ class OrderBy {
/// The ORM prefers using substitution values, which allow for prepared queries, /// The ORM prefers using substitution values, which allow for prepared queries,
/// and prevent SQL injection attacks. /// and prevent SQL injection attacks.
@deprecated @deprecated
String toSql(Object obj, {bool withQuotes: true}) { String toSql(Object obj, {bool withQuotes = true}) {
if (obj is DateTime) { if (obj is DateTime) {
return withQuotes ? "'${dateYmdHms.format(obj)}'" : dateYmdHms.format(obj); return withQuotes ? "'${dateYmdHms.format(obj)}'" : dateYmdHms.format(obj);
} else if (obj is bool) { } else if (obj is bool) {
@ -188,7 +188,7 @@ abstract class Query<T, Where extends QueryWhere> extends QueryBase<T> {
} }
/// Sorts the results by a key. /// Sorts the results by a key.
void orderBy(String key, {bool descending: false}) { void orderBy(String key, {bool descending = false}) {
_orderBy.add(new OrderBy(key, descending: descending)); _orderBy.add(new OrderBy(key, descending: descending));
} }
@ -250,8 +250,8 @@ abstract class Query<T, Where extends QueryWhere> extends QueryBase<T> {
/// Execute an `INNER JOIN` against another table. /// Execute an `INNER JOIN` against another table.
void join(tableName, String localKey, String foreignKey, void join(tableName, String localKey, String foreignKey,
{String op: '=', {String op = '=',
List<String> additionalFields: const [], List<String> additionalFields = const [],
Set<String> trampoline}) { Set<String> trampoline}) {
_makeJoin(tableName, trampoline, JoinType.inner, localKey, foreignKey, op, _makeJoin(tableName, trampoline, JoinType.inner, localKey, foreignKey, op,
additionalFields); additionalFields);
@ -259,8 +259,8 @@ abstract class Query<T, Where extends QueryWhere> extends QueryBase<T> {
/// Execute a `LEFT JOIN` against another table. /// Execute a `LEFT JOIN` against another table.
void leftJoin(tableName, String localKey, String foreignKey, void leftJoin(tableName, String localKey, String foreignKey,
{String op: '=', {String op = '=',
List<String> additionalFields: const [], List<String> additionalFields = const [],
Set<String> trampoline}) { Set<String> trampoline}) {
_makeJoin(tableName, trampoline, JoinType.left, localKey, foreignKey, op, _makeJoin(tableName, trampoline, JoinType.left, localKey, foreignKey, op,
additionalFields); additionalFields);
@ -268,8 +268,8 @@ abstract class Query<T, Where extends QueryWhere> extends QueryBase<T> {
/// Execute a `RIGHT JOIN` against another table. /// Execute a `RIGHT JOIN` against another table.
void rightJoin(tableName, String localKey, String foreignKey, void rightJoin(tableName, String localKey, String foreignKey,
{String op: '=', {String op = '=',
List<String> additionalFields: const [], List<String> additionalFields = const [],
Set<String> trampoline}) { Set<String> trampoline}) {
_makeJoin(tableName, trampoline, JoinType.right, localKey, foreignKey, op, _makeJoin(tableName, trampoline, JoinType.right, localKey, foreignKey, op,
additionalFields); additionalFields);
@ -277,8 +277,8 @@ abstract class Query<T, Where extends QueryWhere> extends QueryBase<T> {
/// Execute a `FULL OUTER JOIN` against another table. /// Execute a `FULL OUTER JOIN` against another table.
void fullOuterJoin(tableName, String localKey, String foreignKey, void fullOuterJoin(tableName, String localKey, String foreignKey,
{String op: '=', {String op = '=',
List<String> additionalFields: const [], List<String> additionalFields = const [],
Set<String> trampoline}) { Set<String> trampoline}) {
_makeJoin(tableName, trampoline, JoinType.full, localKey, foreignKey, op, _makeJoin(tableName, trampoline, JoinType.full, localKey, foreignKey, op,
additionalFields); additionalFields);
@ -286,8 +286,8 @@ abstract class Query<T, Where extends QueryWhere> extends QueryBase<T> {
/// Execute a `SELF JOIN`. /// Execute a `SELF JOIN`.
void selfJoin(tableName, String localKey, String foreignKey, void selfJoin(tableName, String localKey, String foreignKey,
{String op: '=', {String op = '=',
List<String> additionalFields: const [], List<String> additionalFields = const [],
Set<String> trampoline}) { Set<String> trampoline}) {
_makeJoin(tableName, trampoline, JoinType.self, localKey, foreignKey, op, _makeJoin(tableName, trampoline, JoinType.self, localKey, foreignKey, op,
additionalFields); additionalFields);
@ -295,9 +295,9 @@ abstract class Query<T, Where extends QueryWhere> extends QueryBase<T> {
@override @override
String compile(Set<String> trampoline, String compile(Set<String> trampoline,
{bool includeTableName: false, {bool includeTableName = false,
String preamble, String preamble,
bool withFields: true, bool withFields = true,
String fromQuery}) { String fromQuery}) {
// One table MAY appear multiple times in a query. // One table MAY appear multiple times in a query.
if (!canCompile(trampoline)) { if (!canCompile(trampoline)) {
@ -556,7 +556,7 @@ class Union<T> extends QueryBase<T> {
@override @override
final String tableName; 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 { : this.tableName = tableName ?? left.tableName {
substitutionValues substitutionValues
..addAll(left.substitutionValues) ..addAll(left.substitutionValues)
@ -571,7 +571,9 @@ class Union<T> extends QueryBase<T> {
@override @override
String compile(Set<String> trampoline, String compile(Set<String> trampoline,
{bool includeTableName: false, String preamble, bool withFields: true}) { {bool includeTableName = false,
String preamble,
bool withFields = true}) {
var selector = all == true ? 'UNION ALL' : 'UNION'; var selector = all == true ? 'UNION ALL' : 'UNION';
var t1 = Set<String>.from(trampoline); var t1 = Set<String>.from(trampoline);
var t2 = Set<String>.from(trampoline); var t2 = Set<String>.from(trampoline);
@ -587,7 +589,7 @@ class JoinBuilder {
final List<String> additionalFields; final List<String> additionalFields;
JoinBuilder(this.type, this.from, this.to, this.key, this.value, JoinBuilder(this.type, this.from, this.to, this.key, this.value,
{this.op: '=', this.alias, this.additionalFields: const []}) { {this.op = '=', this.alias, this.additionalFields = const []}) {
assert(to != null, assert(to != null,
'computation of this join threw an error, and returned null.'); 'computation of this join threw an error, and returned null.');
} }

View file

@ -21,10 +21,10 @@ class Relationship {
class HasMany extends Relationship { class HasMany extends Relationship {
const HasMany( const HasMany(
{String localKey: 'id', {String localKey = 'id',
String foreignKey, String foreignKey,
String foreignTable, String foreignTable,
bool cascadeOnDelete: false}) bool cascadeOnDelete = false})
: super(RelationshipType.hasMany, : super(RelationshipType.hasMany,
localKey: localKey, localKey: localKey,
foreignKey: foreignKey, foreignKey: foreignKey,
@ -36,10 +36,10 @@ const HasMany hasMany = const HasMany();
class HasOne extends Relationship { class HasOne extends Relationship {
const HasOne( const HasOne(
{String localKey: 'id', {String localKey = 'id',
String foreignKey, String foreignKey,
String foreignTable, String foreignTable,
bool cascadeOnDelete: false}) bool cascadeOnDelete = false})
: super(RelationshipType.hasOne, : super(RelationshipType.hasOne,
localKey: localKey, localKey: localKey,
foreignKey: foreignKey, foreignKey: foreignKey,
@ -63,11 +63,12 @@ class ManyToMany extends Relationship {
final Type through; final Type through;
const ManyToMany(this.through, const ManyToMany(this.through,
{String localKey: 'id', {String localKey = 'id',
String foreignKey, String foreignKey,
String foreignTable, String foreignTable,
bool cascadeOnDelete: false}) bool cascadeOnDelete = false})
: super(RelationshipType.hasMany, // Many-to-Many is actually just a hasMany : super(
RelationshipType.hasMany, // Many-to-Many is actually just a hasMany
localKey: localKey, localKey: localKey,
foreignKey: foreignKey, foreignKey: foreignKey,
foreignTable: foreignTable, foreignTable: foreignTable,

View file

@ -15,4 +15,5 @@ dev_dependencies:
angel_serialize: ^2.0.0 angel_serialize: ^2.0.0
angel_serialize_generator: ^2.0.0 angel_serialize_generator: ^2.0.0
build_runner: ^1.0.0 build_runner: ^1.0.0
pedantic: ^1.0.0
test: ^1.0.0 test: ^1.0.0