Updated angel_orm_generator
This commit is contained in:
parent
91f405811b
commit
468513304c
5 changed files with 98 additions and 56 deletions
|
@ -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
|
* Updated home page link
|
||||||
|
|
||||||
# 4.0.0-beta.1
|
## 4.0.0-beta.1
|
||||||
|
|
||||||
* Migrated to support Dart SDK 2.12.x NNBD
|
* 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
|
* 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.
|
* 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`
|
* `OrmBuildContext` caching is now local to a `Builder`, so `watch`
|
||||||
*should* finally always run when required. Should resolve
|
*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
|
* Relationships have always generated subqueries; now these subqueries are
|
||||||
available as `Query` objects on generated classes.
|
available as `Query` objects on generated classes.
|
||||||
* Support explicitly-defined join types for relations.
|
* Support explicitly-defined join types for relations.
|
||||||
|
|
||||||
# 2.0.5
|
## 2.0.5
|
||||||
|
|
||||||
* Remove `ShimFieldImpl` check, which broke relations.
|
* Remove `ShimFieldImpl` check, which broke relations.
|
||||||
* Fix bug where primary key type would not be emitted in migrations.
|
* Fix bug where primary key type would not be emitted in migrations.
|
||||||
* Fix `ManyToMany` ignoring primary key types.
|
* Fix `ManyToMany` ignoring primary key types.
|
||||||
|
|
||||||
# 2.0.4
|
## 2.0.4
|
||||||
|
|
||||||
* Fix `reviveColumn` and element finding to properly detect all annotations now.
|
* Fix `reviveColumn` and element finding to properly detect all annotations now.
|
||||||
|
|
||||||
# 2.0.3
|
## 2.0.3
|
||||||
|
|
||||||
* Remove `targets` in `build.yaml`.
|
* Remove `targets` in `build.yaml`.
|
||||||
|
|
||||||
# 2.0.2
|
## 2.0.2
|
||||||
|
|
||||||
* Change `build_config` range to `">=0.3.0 <0.5.0"`.
|
* Change `build_config` range to `">=0.3.0 <0.5.0"`.
|
||||||
|
|
||||||
# 2.0.1
|
## 2.0.1
|
||||||
|
|
||||||
* Gracefully handle `null` in enum fields.
|
* Gracefully handle `null` in enum fields.
|
||||||
* Add `take` to wherever `skip` is used.
|
* Add `take` to wherever `skip` is used.
|
||||||
|
|
||||||
# 2.0.0+2
|
## 2.0.0+2
|
||||||
|
|
||||||
* Widen `analyzer` dependency range.
|
* Widen `analyzer` dependency range.
|
||||||
|
|
||||||
# 2.0.0+1
|
## 2.0.0+1
|
||||||
|
|
||||||
* Restore `build.yaml`, which at some point, got deleted.
|
* Restore `build.yaml`, which at some point, got deleted.
|
||||||
|
|
||||||
# 2.0.0
|
## 2.0.0
|
||||||
|
|
||||||
* `parse` -> `tryParse` where used.
|
* `parse` -> `tryParse` where used.
|
||||||
|
|
||||||
# 2.0.0-dev.7
|
## 2.0.0-dev.7
|
||||||
|
|
||||||
* Handle `@ManyToMany`.
|
* Handle `@ManyToMany`.
|
||||||
* Handle cases where the class is not a `Model`.
|
* 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.
|
* Resolve a bug where the `indexType` of `@Column` annotations. would not be found.
|
||||||
* Add `cascade: true` to drops for hasOne/hasMany/ManyToMany migrations.
|
* Add `cascade: true` to drops for hasOne/hasMany/ManyToMany migrations.
|
||||||
* Support enum default values in 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.
|
* Fix bug where an extra field would be inserted into joins and botch the result.
|
||||||
* Narrow analyzer dependency.
|
* Narrow analyzer dependency.
|
||||||
|
|
||||||
# 2.0.0-dev.5
|
## 2.0.0-dev.5
|
||||||
|
|
||||||
* Implement cast-based `double` support.
|
* Implement cast-based `double` support.
|
||||||
* Finish `ListSqlExpressionBuilder`.
|
* Finish `ListSqlExpressionBuilder`.
|
||||||
|
|
||||||
# 2.0.0-dev.4
|
## 2.0.0-dev.4
|
||||||
|
|
||||||
* List generation support.
|
* List generation support.
|
||||||
|
|
||||||
# 2.0.0-dev.3
|
## 2.0.0-dev.3
|
||||||
|
|
||||||
* Add JSON/JSONB support for Maps.
|
* 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`.
|
* 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.
|
* Generate migration files.
|
||||||
|
|
||||||
# 2.0.0-dev
|
## 2.0.0-dev
|
||||||
|
|
||||||
* Dart 2 updates, and more.
|
* Dart 2 updates, and more.
|
||||||
|
|
||||||
# 1.0.0-alpha+6
|
## 1.0.0-alpha+6
|
||||||
|
|
||||||
* `DateTime` is now `CAST` on insertion and update operations.
|
* `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`.
|
Implemented `@hasOne`, with tests. Still missing `@hasMany`.
|
||||||
`belongsToMany` will likely be scrapped.
|
`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`.
|
* Added support for `belongsTo` relationships. Still missing `hasOne`, `hasMany`, `belongsToMany`.
|
||||||
|
|
||||||
# 1.0.0-alpha+1
|
## 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 ##12. `insertX` and `updateX` now use `rc.camelCase`, instead of `rc.snakeCase`.
|
||||||
* Closed #14. Refined the `or` method (it now takes an `XQueryWhere`), and removed `and` and `not`.
|
* Closed ##13. Added `limit` and `offset` properties to `XQuery`.
|
||||||
* Closed #16. Added `sortAscending` and `sortDescending` to `XQuery`.
|
* Closed ##14. Refined the `or` method (it now takes an `XQueryWhere`), and removed `and` and `not`.
|
||||||
* Closed #17. `delete` now uses `toSql` from `XQuery`.
|
* Closed ##16. Added `sortAscending` and `sortDescending` to `XQuery`.
|
||||||
* Closed #18. `XQuery` now supports `union` and `unionAll`.
|
* Closed ##17. `delete` now uses `toSql` from `XQuery`.
|
||||||
|
* Closed ##18. `XQuery` now supports `union` and `unionAll`.
|
||||||
|
|
|
@ -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)
|
[![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)
|
[![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)
|
[![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.
|
Source code generators for Angel's ORM.
|
||||||
This package can generate:
|
This package can generate:
|
||||||
|
|
||||||
* A strongly-typed ORM
|
* A strongly-typed ORM
|
||||||
* SQL migration scripts
|
* SQL migration scripts
|
||||||
|
|
||||||
For documentation about the ORM, head to the main project repo:
|
For documentation about the ORM, see [Developer Guide](https://angel3-docs.dukefirehawk.com/guides/orm)
|
||||||
https://github.com/angel-dart/orm
|
|
||||||
|
|
|
@ -161,13 +161,13 @@ class MigrationGenerator extends GeneratorForAnnotation<Orm> {
|
||||||
if (col.length == null) {
|
if (col.length == null) {
|
||||||
methodName = 'declare';
|
methodName = 'declare';
|
||||||
provColumn = columnTypeType.newInstance([
|
provColumn = columnTypeType.newInstance([
|
||||||
literal(col.type!.name),
|
literal(col.type.name),
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
methodName = 'declareColumn';
|
methodName = 'declareColumn';
|
||||||
provColumn = colType.newInstance([], {
|
provColumn = colType.newInstance([], {
|
||||||
'type': columnTypeType.newInstance([
|
'type': columnTypeType.newInstance([
|
||||||
literal(col.type!.name),
|
literal(col.type.name),
|
||||||
]),
|
]),
|
||||||
'length': literal(col.length),
|
'length': literal(col.length),
|
||||||
});
|
});
|
||||||
|
@ -252,7 +252,7 @@ class MigrationGenerator extends GeneratorForAnnotation<Orm> {
|
||||||
var columnTypeType = refer('ColumnType');
|
var columnTypeType = refer('ColumnType');
|
||||||
var key = relationship.localKey;
|
var key = relationship.localKey;
|
||||||
var keyType = relationship
|
var keyType = relationship
|
||||||
.foreign!.columns[relationship.foreignKey!]!.type!.name;
|
.foreign!.columns[relationship.foreignKey!]!.type.name;
|
||||||
|
|
||||||
var field = table.property('declare').call([
|
var field = table.property('declare').call([
|
||||||
literal(key),
|
literal(key),
|
||||||
|
|
|
@ -120,14 +120,12 @@ Future<OrmBuildContext?> buildOrmContext(
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (column.type == null) {
|
column = Column(
|
||||||
column = Column(
|
isNullable: column.isNullable,
|
||||||
isNullable: column.isNullable,
|
length: column.length,
|
||||||
length: column.length,
|
indexType: column.indexType,
|
||||||
indexType: column.indexType,
|
type: inferColumnType(field.type),
|
||||||
type: inferColumnType(field.type),
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try to find a relationship
|
// Try to find a relationship
|
||||||
var el = _findElement(field);
|
var el = _findElement(field);
|
||||||
|
@ -286,9 +284,11 @@ Future<OrmBuildContext?> buildOrmContext(
|
||||||
|
|
||||||
ctx.relations[field.name] = relation;
|
ctx.relations[field.name] = relation;
|
||||||
} else {
|
} else {
|
||||||
|
/*
|
||||||
if (column.type == null) {
|
if (column.type == null) {
|
||||||
throw 'Cannot infer SQL column type for field "${ctx.buildContext.originalClassName}.${field.name}" with type "${field.type.getDisplayString(withNullability: true)}".';
|
throw 'Cannot infer SQL column type for field "${ctx.buildContext.originalClassName}.${field.name}" with type "${field.type.getDisplayString(withNullability: true)}".';
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// Expressions...
|
// Expressions...
|
||||||
column = Column(
|
column = Column(
|
||||||
|
@ -311,7 +311,7 @@ Future<OrmBuildContext?> buildOrmContext(
|
||||||
return ctx;
|
return ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
ColumnType? inferColumnType(DartType type) {
|
ColumnType inferColumnType(DartType type) {
|
||||||
if (const TypeChecker.fromRuntime(String).isAssignableFromType(type)) {
|
if (const TypeChecker.fromRuntime(String).isAssignableFromType(type)) {
|
||||||
return ColumnType.varChar;
|
return ColumnType.varChar;
|
||||||
}
|
}
|
||||||
|
@ -336,12 +336,16 @@ ColumnType? inferColumnType(DartType type) {
|
||||||
if (const TypeChecker.fromRuntime(List).isAssignableFromType(type)) {
|
if (const TypeChecker.fromRuntime(List).isAssignableFromType(type)) {
|
||||||
return ColumnType.jsonb;
|
return ColumnType.jsonb;
|
||||||
}
|
}
|
||||||
if (type is InterfaceType && type.element.isEnum) return ColumnType.int;
|
if (type is InterfaceType && type.element.isEnum) {
|
||||||
return null;
|
return ColumnType.int;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Default to varChar
|
||||||
|
return ColumnType.varChar;
|
||||||
}
|
}
|
||||||
|
|
||||||
Column reviveColumn(ConstantReader cr) {
|
Column reviveColumn(ConstantReader cr) {
|
||||||
ColumnType? columnType;
|
ColumnType columnType;
|
||||||
|
|
||||||
var indexTypeObj = cr.peek('indexType')?.objectValue;
|
var indexTypeObj = cr.peek('indexType')?.objectValue;
|
||||||
indexTypeObj ??= cr.revive().namedArguments['indexType'];
|
indexTypeObj ??= cr.revive().namedArguments['indexType'];
|
||||||
|
@ -358,11 +362,14 @@ Column reviveColumn(ConstantReader cr) {
|
||||||
|
|
||||||
if (columnObj != null) {
|
if (columnObj != null) {
|
||||||
columnType = _ColumnType(columnObj);
|
columnType = _ColumnType(columnObj);
|
||||||
|
} else {
|
||||||
|
// Default to varchar
|
||||||
|
columnType = ColumnType.varChar;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
isNullable: cr.peek('isNullable')?.boolValue ?? false,
|
isNullable: cr.peek('isNullable')?.boolValue ?? false,
|
||||||
length: cr.peek('length')?.intValue,
|
length: cr.peek('length')?.intValue ?? 256,
|
||||||
type: columnType,
|
type: columnType,
|
||||||
indexType: indexType,
|
indexType: indexType,
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
name: angel3_orm_generator
|
name: angel3_orm_generator
|
||||||
version: 4.0.0-beta.2
|
version: 4.0.0-beta.3
|
||||||
description: Code generators for Angel's ORM. Generates query builder classes.
|
description: Code generators for Angel3 ORM. Generates query builder classes.
|
||||||
homepage: https://github.com/dukefirehawk/angel/tree/angel3/packages/orm/angel_orm_generator
|
homepage: https://angel3-framework.web.app/
|
||||||
|
repository: https://github.com/dukefirehawk/angel/tree/angel3/packages/orm/angel_orm_generator
|
||||||
environment:
|
environment:
|
||||||
sdk: '>=2.12.0 <3.0.0'
|
sdk: '>=2.12.0 <3.0.0'
|
||||||
dependencies:
|
dependencies:
|
||||||
|
|
Loading…
Reference in a new issue