2.0.0-dev.3
This commit is contained in:
parent
34d949d0e2
commit
e95c4d8c6b
5 changed files with 22 additions and 15 deletions
angel_orm
angel_orm_generator/test/models
|
@ -1,3 +1,7 @@
|
||||||
|
# 2.0.0-dev.3
|
||||||
|
* Brought back old-style query builder.
|
||||||
|
* Strong-mode updates, revised `Join`.
|
||||||
|
|
||||||
# 2.0.0-dev.2
|
# 2.0.0-dev.2
|
||||||
* Renamed `ORM` to `Orm`.
|
* Renamed `ORM` to `Orm`.
|
||||||
* `Orm` now requires a database type.
|
* `Orm` now requires a database type.
|
||||||
|
|
|
@ -6,12 +6,12 @@ class Orm {
|
||||||
const Orm({this.tableName});
|
const Orm({this.tableName});
|
||||||
}
|
}
|
||||||
|
|
||||||
class CanJoin {
|
class Join {
|
||||||
final Type type;
|
final Type against;
|
||||||
final String foreignKey;
|
final String foreignKey;
|
||||||
final JoinType joinType;
|
final JoinType type;
|
||||||
|
|
||||||
const CanJoin(this.type, this.foreignKey, {this.joinType: JoinType.full});
|
const Join(this.against, this.foreignKey, {this.type: JoinType.inner});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The various types of [Join].
|
/// The various types of [Join].
|
||||||
|
|
|
@ -40,7 +40,7 @@ abstract class Query<T, Where extends QueryWhere> extends QueryBase<T> {
|
||||||
final List<OrderBy> _orderBy = [];
|
final List<OrderBy> _orderBy = [];
|
||||||
String _crossJoin, _groupBy;
|
String _crossJoin, _groupBy;
|
||||||
int _limit, _offset;
|
int _limit, _offset;
|
||||||
Join _join;
|
JoinBuilder _join;
|
||||||
|
|
||||||
/// The table against which to execute this query.
|
/// The table against which to execute this query.
|
||||||
String get tableName;
|
String get tableName;
|
||||||
|
@ -84,35 +84,35 @@ abstract class Query<T, Where extends QueryWhere> extends QueryBase<T> {
|
||||||
void join(String tableName, String localKey, String foreignKey,
|
void join(String tableName, String localKey, String foreignKey,
|
||||||
{String op: '='}) {
|
{String op: '='}) {
|
||||||
_join =
|
_join =
|
||||||
new Join(JoinType.inner, this, tableName, localKey, foreignKey, op: op);
|
new JoinBuilder(JoinType.inner, this, tableName, localKey, foreignKey, op: op);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Execute a `LEFT JOIN` against another table.
|
/// Execute a `LEFT JOIN` against another table.
|
||||||
void leftJoin(String tableName, String localKey, String foreignKey,
|
void leftJoin(String tableName, String localKey, String foreignKey,
|
||||||
{String op: '='}) {
|
{String op: '='}) {
|
||||||
_join =
|
_join =
|
||||||
new Join(JoinType.left, this, tableName, localKey, foreignKey, op: op);
|
new JoinBuilder(JoinType.left, this, tableName, localKey, foreignKey, op: op);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Execute a `RIGHT JOIN` against another table.
|
/// Execute a `RIGHT JOIN` against another table.
|
||||||
void rightJoin(String tableName, String localKey, String foreignKey,
|
void rightJoin(String tableName, String localKey, String foreignKey,
|
||||||
{String op: '='}) {
|
{String op: '='}) {
|
||||||
_join =
|
_join =
|
||||||
new Join(JoinType.right, this, tableName, localKey, foreignKey, op: op);
|
new JoinBuilder(JoinType.right, this, tableName, localKey, foreignKey, op: op);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Execute a `FULL OUTER JOIN` against another table.
|
/// Execute a `FULL OUTER JOIN` against another table.
|
||||||
void fullOuterJoin(String tableName, String localKey, String foreignKey,
|
void fullOuterJoin(String tableName, String localKey, String foreignKey,
|
||||||
{String op: '='}) {
|
{String op: '='}) {
|
||||||
_join =
|
_join =
|
||||||
new Join(JoinType.full, this, tableName, localKey, foreignKey, op: op);
|
new JoinBuilder(JoinType.full, this, tableName, localKey, foreignKey, op: op);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Execute a `SELF JOIN`.
|
/// Execute a `SELF JOIN`.
|
||||||
void selfJoin(String tableName, String localKey, String foreignKey,
|
void selfJoin(String tableName, String localKey, String foreignKey,
|
||||||
{String op: '='}) {
|
{String op: '='}) {
|
||||||
_join =
|
_join =
|
||||||
new Join(JoinType.self, this, tableName, localKey, foreignKey, op: op);
|
new JoinBuilder(JoinType.self, this, tableName, localKey, foreignKey, op: op);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -201,12 +201,12 @@ class Union<T> extends QueryBase<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Builds a SQL `JOIN` query.
|
/// Builds a SQL `JOIN` query.
|
||||||
class Join {
|
class JoinBuilder {
|
||||||
final JoinType type;
|
final JoinType type;
|
||||||
final Query from;
|
final Query from;
|
||||||
final String to, key, value, op;
|
final String to, key, value, op;
|
||||||
|
|
||||||
Join(this.type, this.from, this.to, this.key, this.value, {this.op: '='});
|
JoinBuilder(this.type, this.from, this.to, this.key, this.value, {this.op: '='});
|
||||||
|
|
||||||
String compile() {
|
String compile() {
|
||||||
var b = new StringBuffer();
|
var b = new StringBuffer();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
name: angel_orm
|
name: angel_orm
|
||||||
version: 2.0.0-dev.2
|
version: 2.0.0-dev.3
|
||||||
description: Runtime support for Angel's ORM.
|
description: Runtime support for Angel's ORM.
|
||||||
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
|
||||||
|
|
|
@ -10,9 +10,12 @@ part 'order.serializer.g.dart';
|
||||||
@postgreSqlOrm
|
@postgreSqlOrm
|
||||||
@serializable
|
@serializable
|
||||||
class _Order extends Model {
|
class _Order extends Model {
|
||||||
@CanJoin(Customer, 'id')
|
@Join(Customer, CustomerFields.id)
|
||||||
int customerId;
|
int customerId;
|
||||||
|
|
||||||
int employeeId;
|
int employeeId;
|
||||||
|
|
||||||
DateTime orderDate;
|
DateTime orderDate;
|
||||||
|
|
||||||
int shipperId;
|
int shipperId;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue