* Remove parentheses from AS when renaming raw expressions.

This commit is contained in:
Tobe O 2019-10-12 23:20:07 -04:00
parent 4cdded0d87
commit e90bba935e
3 changed files with 11 additions and 5 deletions

View file

@ -1,3 +1,6 @@
# 2.1.0-beta.3
* Remove parentheses from `AS` when renaming raw `expressions`.
# 2.1.0-beta.2 # 2.1.0-beta.2
* Add `expressions` to `Query`, to support custom SQL expressions that are * Add `expressions` to `Query`, to support custom SQL expressions that are
read as normal fields. read as normal fields.

View file

@ -42,7 +42,8 @@ abstract class Query<T, Where extends QueryWhere> extends QueryBase<T> {
/// Preprends the [tableName] to the [String], [s]. /// Preprends the [tableName] to the [String], [s].
String adornWithTableName(String s) { String adornWithTableName(String s) {
if (expressions.containsKey(s)) { if (expressions.containsKey(s)) {
return '(${expressions[s]} AS $s)'; return '${expressions[s]} AS $s';
// return '(${expressions[s]} AS $s)';
} else { } else {
return '$tableName.$s'; return '$tableName.$s';
} }
@ -256,13 +257,15 @@ abstract class Query<T, Where extends QueryWhere> extends QueryBase<T> {
ss = '$ss AS ${aliases[s]}'; ss = '$ss AS ${aliases[s]}';
} }
if (expressions.containsKey(s)) { if (expressions.containsKey(s)) {
ss = '($ss)'; // ss = '($ss)';
} }
} else if (expressions.containsKey(s)) { } else if (expressions.containsKey(s)) {
if (cast != null) { if (cast != null) {
ss = '(($ss) AS $s)'; ss = '($ss) AS $s';
// ss = '(($ss) AS $s)';
} else { } else {
ss = '($ss AS $s)'; ss = '$ss AS $s';
// ss = '($ss AS $s)';
} }
} }
return ss; return ss;

View file

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