angel_orm@2.0.0

This commit is contained in:
Tobe O 2019-04-08 14:33:15 -04:00
parent bdba499c78
commit 11b3f3f28f
5 changed files with 68 additions and 14 deletions

View file

@ -1,3 +1,6 @@
# 2.0.0
* Add `isNull`, `isNotNull` getters to builders.
# 2.0.0-dev.24
* Fix a bug that caused syntax errors on `ORDER BY`.
* Add `pattern` to `like` on string builder. `sanitize` is optional.

View file

@ -90,6 +90,16 @@ class NumericSqlExpressionBuilder<T extends num>
operator >=(T value) => _change('>=', value);
void get isNull {
_raw = 'IS NULL';
_hasValue = true;
}
void get isNotNull {
_raw = 'IS NOT NULL';
_hasValue = true;
}
void lessThan(T value) {
_change('<', value);
}
@ -165,14 +175,14 @@ class EnumSqlExpressionBuilder<T> extends SqlExpressionBuilder<T> {
return '$_op $_value';
}
void isNull() {
void get isNull {
_raw = 'IS NULL';
_hasValue = true;
_raw = 'IS NOT NULL';
}
void isNotNull() {
_hasValue = true;
void get isNotNull {
_raw = 'IS NOT NULL';
_hasValue = true;
}
void equals(T value) {
@ -272,6 +282,16 @@ class StringSqlExpressionBuilder extends SqlExpressionBuilder<String> {
_hasValue = true;
}
void get isNull {
_raw = 'IS NULL';
_hasValue = true;
}
void get isNotNull {
_raw = 'IS NOT NULL';
_hasValue = true;
}
String _in(Iterable<String> values) {
return 'IN (' +
values.map((v) {
@ -320,9 +340,19 @@ class BooleanSqlExpressionBuilder extends SqlExpressionBuilder<bool> {
return '$_op $v';
}
Null get isTrue => equals(true);
void get isTrue => equals(true);
Null get isFalse => equals(false);
void get isFalse => equals(false);
void get isNull {
_raw = 'IS NULL';
_hasValue = true;
}
void get isNotNull {
_raw = 'IS NOT NULL';
_hasValue = true;
}
void equals(bool value) {
_change('=', value);
@ -420,6 +450,14 @@ class DateTimeSqlExpressionBuilder extends SqlExpressionBuilder<DateTime> {
_raw = "$columnName NOT BETWEEN '$l' and '$u'";
}
void get isNull {
_raw = '$columnName IS NULL';
}
void get isNotNull {
_raw = '$columnName IS NOT NULL';
}
@override
String compile() {
if (_raw?.isNotEmpty == true) return _raw;
@ -473,6 +511,16 @@ abstract class JsonSqlExpressionBuilder<T, K> extends SqlExpressionBuilder<T> {
return _hasValue = true;
}
void get isNull {
_raw = 'IS NULL';
_hasValue = true;
}
void get isNotNull {
_raw = 'IS NOT NULL';
_hasValue = true;
}
@override
String compile() {
var s = _compile();
@ -524,7 +572,7 @@ class MapSqlExpressionBuilder extends JsonSqlExpressionBuilder<Map, String> {
}
void containsKey(String key) {
this[key].isNotNull();
this[key].isNotNull;
}
void containsPair(key, value) {
@ -578,14 +626,14 @@ class JsonSqlExpressionBuilderProperty {
return '${builder.columnName}::jsonb->>$n';
}
void isNotNull() {
void get isNotNull {
builder
.._hasValue = true
.._raw ??= ''
.._raw += "$nameString IS NOT NULL";
}
void isNull() {
void get isNull {
builder
.._hasValue = true
.._raw ??= ''

View file

@ -1,5 +1,5 @@
name: angel_orm
version: 2.0.0-dev.24
version: 2.0.0
description: Runtime support for Angel's ORM. Includes base classes for queries.
author: Tobe O <thosakwe@gmail.com>
homepage: https://github.com/angel-dart/orm

View file

@ -1,3 +1,6 @@
# 2.0.0-dev.8
* `parse` -> `tryParse` where used.
# 2.0.0-dev.7
* Handle `@ManyToMany`.
* Handle cases where the class is not a `Model`.

View file

@ -189,7 +189,7 @@ class OrmGenerator extends GeneratorForAnnotation<Orm> {
.call([expr.asA(refer('String'))]).asA(type);
} else if (floatTypes.contains(ctx.columns[field.name]?.type)) {
expr = refer('double')
.property('parse')
.property('tryParse')
.call([expr.property('toString').call([])]);
} else if (fType is InterfaceType && fType.element.isEnum) {
expr = type.property('values').index(expr.asA(refer('int')));
@ -370,7 +370,7 @@ class OrmGenerator extends GeneratorForAnnotation<Orm> {
.property('equals')
.call([
(refer('int')
.property('parse')
.property('tryParse')
.call([refer('result').property('id')]))
]));
@ -672,7 +672,7 @@ class OrmGenerator extends GeneratorForAnnotation<Orm> {
.call([value.asA(refer('String'))]).asA(refer('List'));
} else if (floatTypes.contains(ctx.columns[field.name]?.type)) {
value = refer('double')
.property('parse')
.property('tryParse')
.call([value.asA(refer('String'))]);
} else {
value = value.asA(type);
@ -737,7 +737,7 @@ class OrmGenerator extends GeneratorForAnnotation<Orm> {
var parsedId = prop.property(foreignField.name);
if (isSpecialId(foreign, field)) {
parsedId = (refer('int').property('parse').call([parsedId]));
parsedId = (refer('int').property('tryParse').call([parsedId]));
}
var cond = prop.notEqualTo(literalNull);