2.0.0-dev.3
This commit is contained in:
parent
34d949d0e2
commit
e95c4d8c6b
5 changed files with 22 additions and 15 deletions
|
@ -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
|
||||
* Renamed `ORM` to `Orm`.
|
||||
* `Orm` now requires a database type.
|
||||
|
|
|
@ -6,12 +6,12 @@ class Orm {
|
|||
const Orm({this.tableName});
|
||||
}
|
||||
|
||||
class CanJoin {
|
||||
final Type type;
|
||||
class Join {
|
||||
final Type against;
|
||||
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].
|
||||
|
|
|
@ -40,7 +40,7 @@ abstract class Query<T, Where extends QueryWhere> extends QueryBase<T> {
|
|||
final List<OrderBy> _orderBy = [];
|
||||
String _crossJoin, _groupBy;
|
||||
int _limit, _offset;
|
||||
Join _join;
|
||||
JoinBuilder _join;
|
||||
|
||||
/// The table against which to execute this query.
|
||||
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,
|
||||
{String op: '='}) {
|
||||
_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.
|
||||
void leftJoin(String tableName, String localKey, String foreignKey,
|
||||
{String op: '='}) {
|
||||
_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.
|
||||
void rightJoin(String tableName, String localKey, String foreignKey,
|
||||
{String op: '='}) {
|
||||
_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.
|
||||
void fullOuterJoin(String tableName, String localKey, String foreignKey,
|
||||
{String op: '='}) {
|
||||
_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`.
|
||||
void selfJoin(String tableName, String localKey, String foreignKey,
|
||||
{String op: '='}) {
|
||||
_join =
|
||||
new Join(JoinType.self, this, tableName, localKey, foreignKey, op: op);
|
||||
new JoinBuilder(JoinType.self, this, tableName, localKey, foreignKey, op: op);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -201,12 +201,12 @@ class Union<T> extends QueryBase<T> {
|
|||
}
|
||||
|
||||
/// Builds a SQL `JOIN` query.
|
||||
class Join {
|
||||
class JoinBuilder {
|
||||
final JoinType type;
|
||||
final Query from;
|
||||
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() {
|
||||
var b = new StringBuffer();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
name: angel_orm
|
||||
version: 2.0.0-dev.2
|
||||
version: 2.0.0-dev.3
|
||||
description: Runtime support for Angel's ORM.
|
||||
author: Tobe O <thosakwe@gmail.com>
|
||||
homepage: https://github.com/angel-dart/orm
|
||||
|
|
|
@ -10,9 +10,12 @@ part 'order.serializer.g.dart';
|
|||
@postgreSqlOrm
|
||||
@serializable
|
||||
class _Order extends Model {
|
||||
@CanJoin(Customer, 'id')
|
||||
@Join(Customer, CustomerFields.id)
|
||||
int customerId;
|
||||
|
||||
int employeeId;
|
||||
|
||||
DateTime orderDate;
|
||||
|
||||
int shipperId;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue