Updated angel_orm_generator

This commit is contained in:
thomashii 2021-07-19 13:00:00 +08:00
parent 91f405811b
commit 468513304c
5 changed files with 98 additions and 56 deletions

View file

@ -1,97 +1,130 @@
# 4.0.0-beta.2
# Change Log
## 4.0.0-beta.3
* Updated README
* Fixed NNBD issues
## 4.0.0-beta.2
* Updated home page link
# 4.0.0-beta.1
## 4.0.0-beta.1
* Migrated to support Dart SDK 2.12.x NNBD
# 3.0.0
## 3.0.0
* Migrated to work with Dart SDK 2.12.x Non NNBD
# 2.1.0-beta.2
## 2.1.0-beta.2
* Support for custom SQL expressions.
# 2.1.0-beta.1
## 2.1.0-beta.1
* `OrmBuildContext` caching is now local to a `Builder`, so `watch`
*should* finally always run when required. Should resolve
[#85](https://github.com/angel-dart/orm/issues/85).
[##85](https://github.com/angel-dart/orm/issues/85).
## 2.1.0-beta
# 2.1.0-beta
* Relationships have always generated subqueries; now these subqueries are
available as `Query` objects on generated classes.
* Support explicitly-defined join types for relations.
# 2.0.5
## 2.0.5
* Remove `ShimFieldImpl` check, which broke relations.
* Fix bug where primary key type would not be emitted in migrations.
* Fix `ManyToMany` ignoring primary key types.
# 2.0.4
## 2.0.4
* Fix `reviveColumn` and element finding to properly detect all annotations now.
# 2.0.3
## 2.0.3
* Remove `targets` in `build.yaml`.
# 2.0.2
## 2.0.2
* Change `build_config` range to `">=0.3.0 <0.5.0"`.
# 2.0.1
## 2.0.1
* Gracefully handle `null` in enum fields.
* Add `take` to wherever `skip` is used.
# 2.0.0+2
## 2.0.0+2
* Widen `analyzer` dependency range.
# 2.0.0+1
## 2.0.0+1
* Restore `build.yaml`, which at some point, got deleted.
# 2.0.0
## 2.0.0
* `parse` -> `tryParse` where used.
# 2.0.0-dev.7
## 2.0.0-dev.7
* Handle `@ManyToMany`.
* Handle cases where the class is not a `Model`.
* Stop assuming things have `id`, etc.
* Stop assuming things have `id`, etc.
* Resolve a bug where the `indexType` of `@Column` annotations. would not be found.
* Add `cascade: true` to drops for hasOne/hasMany/ManyToMany migrations.
* Support enum default values in migrations.
# 2.0.0-dev.6
## 2.0.0-dev.6
* Fix bug where an extra field would be inserted into joins and botch the result.
* Narrow analyzer dependency.
# 2.0.0-dev.5
## 2.0.0-dev.5
* Implement cast-based `double` support.
* Finish `ListSqlExpressionBuilder`.
# 2.0.0-dev.4
## 2.0.0-dev.4
* List generation support.
# 2.0.0-dev.3
## 2.0.0-dev.3
* Add JSON/JSONB support for Maps.
# 2.0.0-dev.2
## 2.0.0-dev.2
* Changes to work with `package:angel_orm@2.0.0-dev.15`.
# 2.0.0-dev.1
## 2.0.0-dev.1
* Generate migration files.
# 2.0.0-dev
## 2.0.0-dev
* Dart 2 updates, and more.
# 1.0.0-alpha+6
## 1.0.0-alpha+6
* `DateTime` is now `CAST` on insertion and update operations.
# 1.0.0-alpha+3
## 1.0.0-alpha+3
Implemented `@hasOne`, with tests. Still missing `@hasMany`.
`belongsToMany` will likely be scrapped.
# 1.0.0-alpha+2
## 1.0.0-alpha+2
* Added support for `belongsTo` relationships. Still missing `hasOne`, `hasMany`, `belongsToMany`.
# 1.0.0-alpha+1
* Closed #12. `insertX` and `updateX` now use `rc.camelCase`, instead of `rc.snakeCase`.
* Closed #13. Added `limit` and `offset` properties to `XQuery`.
* Closed #14. Refined the `or` method (it now takes an `XQueryWhere`), and removed `and` and `not`.
* Closed #16. Added `sortAscending` and `sortDescending` to `XQuery`.
* Closed #17. `delete` now uses `toSql` from `XQuery`.
* Closed #18. `XQuery` now supports `union` and `unionAll`.
## 1.0.0-alpha+1
* Closed ##12. `insertX` and `updateX` now use `rc.camelCase`, instead of `rc.snakeCase`.
* Closed ##13. Added `limit` and `offset` properties to `XQuery`.
* Closed ##14. Refined the `or` method (it now takes an `XQueryWhere`), and removed `and` and `not`.
* Closed ##16. Added `sortAscending` and `sortDescending` to `XQuery`.
* Closed ##17. `delete` now uses `toSql` from `XQuery`.
* Closed ##18. `XQuery` now supports `union` and `unionAll`.

View file

@ -1,4 +1,5 @@
# angel3_orm_generator
# Angel3 ORM Generator
[![version](https://img.shields.io/badge/pub-v4.0.0-brightgreen)](https://pub.dartlang.org/packages/angel3_orm_generator)
[![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety)
[![Gitter](https://img.shields.io/gitter/room/angel_dart/discussion)](https://gitter.im/angel_dart/discussion)
@ -7,8 +8,8 @@
Source code generators for Angel's ORM.
This package can generate:
* A strongly-typed ORM
* SQL migration scripts
For documentation about the ORM, head to the main project repo:
https://github.com/angel-dart/orm
For documentation about the ORM, see [Developer Guide](https://angel3-docs.dukefirehawk.com/guides/orm)

View file

@ -161,13 +161,13 @@ class MigrationGenerator extends GeneratorForAnnotation<Orm> {
if (col.length == null) {
methodName = 'declare';
provColumn = columnTypeType.newInstance([
literal(col.type!.name),
literal(col.type.name),
]);
} else {
methodName = 'declareColumn';
provColumn = colType.newInstance([], {
'type': columnTypeType.newInstance([
literal(col.type!.name),
literal(col.type.name),
]),
'length': literal(col.length),
});
@ -252,7 +252,7 @@ class MigrationGenerator extends GeneratorForAnnotation<Orm> {
var columnTypeType = refer('ColumnType');
var key = relationship.localKey;
var keyType = relationship
.foreign!.columns[relationship.foreignKey!]!.type!.name;
.foreign!.columns[relationship.foreignKey!]!.type.name;
var field = table.property('declare').call([
literal(key),

View file

@ -120,14 +120,12 @@ Future<OrmBuildContext?> buildOrmContext(
),
);
if (column.type == null) {
column = Column(
isNullable: column.isNullable,
length: column.length,
indexType: column.indexType,
type: inferColumnType(field.type),
);
}
column = Column(
isNullable: column.isNullable,
length: column.length,
indexType: column.indexType,
type: inferColumnType(field.type),
);
// Try to find a relationship
var el = _findElement(field);
@ -286,9 +284,11 @@ Future<OrmBuildContext?> buildOrmContext(
ctx.relations[field.name] = relation;
} else {
/*
if (column.type == null) {
throw 'Cannot infer SQL column type for field "${ctx.buildContext.originalClassName}.${field.name}" with type "${field.type.getDisplayString(withNullability: true)}".';
}
*/
// Expressions...
column = Column(
@ -311,7 +311,7 @@ Future<OrmBuildContext?> buildOrmContext(
return ctx;
}
ColumnType? inferColumnType(DartType type) {
ColumnType inferColumnType(DartType type) {
if (const TypeChecker.fromRuntime(String).isAssignableFromType(type)) {
return ColumnType.varChar;
}
@ -336,12 +336,16 @@ ColumnType? inferColumnType(DartType type) {
if (const TypeChecker.fromRuntime(List).isAssignableFromType(type)) {
return ColumnType.jsonb;
}
if (type is InterfaceType && type.element.isEnum) return ColumnType.int;
return null;
if (type is InterfaceType && type.element.isEnum) {
return ColumnType.int;
}
// Default to varChar
return ColumnType.varChar;
}
Column reviveColumn(ConstantReader cr) {
ColumnType? columnType;
ColumnType columnType;
var indexTypeObj = cr.peek('indexType')?.objectValue;
indexTypeObj ??= cr.revive().namedArguments['indexType'];
@ -358,11 +362,14 @@ Column reviveColumn(ConstantReader cr) {
if (columnObj != null) {
columnType = _ColumnType(columnObj);
} else {
// Default to varchar
columnType = ColumnType.varChar;
}
return Column(
isNullable: cr.peek('isNullable')?.boolValue ?? false,
length: cr.peek('length')?.intValue,
length: cr.peek('length')?.intValue ?? 256,
type: columnType,
indexType: indexType,
);

View file

@ -1,7 +1,8 @@
name: angel3_orm_generator
version: 4.0.0-beta.2
description: Code generators for Angel's ORM. Generates query builder classes.
homepage: https://github.com/dukefirehawk/angel/tree/angel3/packages/orm/angel_orm_generator
version: 4.0.0-beta.3
description: Code generators for Angel3 ORM. Generates query builder classes.
homepage: https://angel3-framework.web.app/
repository: https://github.com/dukefirehawk/angel/tree/angel3/packages/orm/angel_orm_generator
environment:
sdk: '>=2.12.0 <3.0.0'
dependencies: