diff --git a/packages/orm/angel_migration/CHANGELOG.md b/packages/orm/angel_migration/CHANGELOG.md index 375379d2..bb59d67a 100755 --- a/packages/orm/angel_migration/CHANGELOG.md +++ b/packages/orm/angel_migration/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## 6.0.1 + +* Upgraded to `lints` 2.x.x + ## 6.0.0 * Updated to SDK 2.16.x diff --git a/packages/orm/angel_migration/lib/src/table.dart b/packages/orm/angel_migration/lib/src/table.dart index 15deb5c3..c7968848 100755 --- a/packages/orm/angel_migration/lib/src/table.dart +++ b/packages/orm/angel_migration/lib/src/table.dart @@ -13,7 +13,11 @@ abstract class Table { MigrationColumn float(String name) => declare(name, ColumnType.float); - MigrationColumn numeric(String name) => declare(name, ColumnType.numeric); + MigrationColumn double(String name) => declare(name, ColumnType.double); + + MigrationColumn numeric(String name, {int precision = 17, int scale = 3}) { + return declare(name, ColumnType.numeric); + } MigrationColumn boolean(String name) => declare(name, ColumnType.boolean); @@ -23,7 +27,9 @@ abstract class Table { //MigrationColumn dateTime(String name) => timeStamp(name, timezone: true); MigrationColumn timeStamp(String name, {bool timezone = false}) { - if (timezone != true) return declare(name, ColumnType.timeStamp); + if (!timezone) { + return declare(name, ColumnType.timeStamp); + } return declare(name, ColumnType.timeStampWithTimeZone); } diff --git a/packages/orm/angel_migration/pubspec.yaml b/packages/orm/angel_migration/pubspec.yaml index 67a6dad2..a2a381db 100755 --- a/packages/orm/angel_migration/pubspec.yaml +++ b/packages/orm/angel_migration/pubspec.yaml @@ -1,5 +1,5 @@ name: angel3_migration -version: 6.0.0 +version: 6.0.1 description: Database migration runtime for Angel3 ORM. Use this package to define schemas. homepage: https://angel3-framework.web.app/ repository: https://github.com/dukefirehawk/angel/tree/master/packages/orm/angel_migration @@ -8,7 +8,7 @@ environment: dependencies: angel3_orm: ^6.0.0 dev_dependencies: - lints: ^1.0.0 -# dependency_overrides: -# angel3_orm: -# path: ../angel_orm + lints: ^2.0.0 +dependency_overrides: + angel3_orm: + path: ../angel_orm diff --git a/packages/orm/angel_migration_runner/CHANGELOG.md b/packages/orm/angel_migration_runner/CHANGELOG.md index ed9c1855..11c2d4b4 100755 --- a/packages/orm/angel_migration_runner/CHANGELOG.md +++ b/packages/orm/angel_migration_runner/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## 6.0.2 + +* Upgraded to `lints` 2.x.x + ## 6.0.1 * Added `MariaDbMigrationRunner` to support MariaDB migration with `mysql1` driver diff --git a/packages/orm/angel_migration_runner/pubspec.yaml b/packages/orm/angel_migration_runner/pubspec.yaml index 1f018cc5..0a5dfa71 100755 --- a/packages/orm/angel_migration_runner/pubspec.yaml +++ b/packages/orm/angel_migration_runner/pubspec.yaml @@ -1,5 +1,5 @@ name: angel3_migration_runner -version: 6.0.1 +version: 6.0.2 description: Command-line based database migration runner for Angel3's ORM. homepage: https://angel3-framework.web.app/ repository: https://github.com/dukefirehawk/angel/tree/master/packages/orm/angel_migration_runner @@ -15,7 +15,7 @@ dependencies: mysql1: ^0.19.0 logging: ^1.0.0 dev_dependencies: - lints: ^1.0.0 + lints: ^2.0.0 # dependency_overrides: # angel3_orm: # path: ../angel_orm diff --git a/packages/orm/angel_orm/lib/src/migration.dart b/packages/orm/angel_orm/lib/src/migration.dart index 0e48dea2..7a86e807 100644 --- a/packages/orm/angel_orm/lib/src/migration.dart +++ b/packages/orm/angel_orm/lib/src/migration.dart @@ -23,6 +23,15 @@ class Column { /// Specifies the length of a `VARCHAR`. final int length; + /// Specifies the precision of a `NUMERIC` or `DECIMAL`. + final int precision; + + /// Specifies the scale of a `NUMERIC` or `DECIMAL`. + final int scale; + + /// Specifies the timezone of a temporal field. + final String timezone; + /// Explicitly defines a SQL type for this column. final ColumnType type; @@ -35,7 +44,10 @@ class Column { const Column( {this.isNullable = true, this.length = 255, + this.precision = 17, + this.scale = 3, this.name = "", + this.timezone = "", this.type = ColumnType.varChar, this.indexType = IndexType.none, this.expression}); @@ -71,9 +83,16 @@ enum IndexType { class ColumnType { /// The name of this data type. final String name; - final bool hasSize; + final bool hasLength; + final bool hasPrecision; + final bool hasScale; + final bool hasTimezone; - const ColumnType(this.name, [this.hasSize = false]); + const ColumnType(this.name, + {this.hasLength = false, + this.hasPrecision = false, + this.hasScale = false, + this.hasTimezone = false}); static const ColumnType boolean = ColumnType('boolean'); @@ -87,13 +106,15 @@ class ColumnType { static const ColumnType smallInt = ColumnType('smallint'); static const ColumnType tinyInt = ColumnType('tinyint'); static const ColumnType bit = ColumnType('bit'); - static const ColumnType decimal = ColumnType('decimal', true); - static const ColumnType numeric = ColumnType('numeric', true); + static const ColumnType decimal = + ColumnType('decimal', hasPrecision: true, hasScale: true); + static const ColumnType numeric = + ColumnType('numeric', hasPrecision: true, hasScale: true); static const ColumnType money = ColumnType('money'); static const ColumnType smallMoney = ColumnType('smallmoney'); static const ColumnType float = ColumnType('float'); static const ColumnType real = ColumnType('real'); - static const ColumnType double = ColumnType('double'); + static const ColumnType double = ColumnType('double precision'); // Dates and times static const ColumnType dateTime = ColumnType('datetime'); @@ -102,35 +123,38 @@ class ColumnType { static const ColumnType time = ColumnType('time'); static const ColumnType timeStamp = ColumnType('timestamp'); static const ColumnType timeStampWithTimeZone = - ColumnType('timestamp with time zone'); + ColumnType('timestamptz', hasTimezone: true); // Strings - static const ColumnType char = ColumnType('char', true); - static const ColumnType varChar = ColumnType('varchar', true); + static const ColumnType char = ColumnType('char', hasLength: true); + static const ColumnType varChar = ColumnType('varchar', hasLength: true); static const ColumnType varCharMax = ColumnType('varchar(max)'); - static const ColumnType text = ColumnType('text', true); + static const ColumnType text = ColumnType('text', hasLength: true); // Unicode strings - static const ColumnType nChar = ColumnType('nchar', true); - static const ColumnType nVarChar = ColumnType('nvarchar', true); - static const ColumnType nVarCharMax = ColumnType('nvarchar(max)', true); - static const ColumnType nText = ColumnType('ntext', true); + static const ColumnType nChar = ColumnType('nchar', hasLength: true); + static const ColumnType nVarChar = ColumnType('nvarchar', hasLength: true); + static const ColumnType nVarCharMax = + ColumnType('nvarchar(max)', hasLength: true); + static const ColumnType nText = ColumnType('ntext', hasLength: true); // Binary - static const ColumnType binary = ColumnType('binary', true); - static const ColumnType varBinary = ColumnType('varbinary', true); - static const ColumnType varBinaryMax = ColumnType('varbinary(max)', true); - static const ColumnType image = ColumnType('image', true); + static const ColumnType binary = ColumnType('binary', hasLength: true); + static const ColumnType varBinary = ColumnType('varbinary', hasLength: true); + static const ColumnType varBinaryMax = + ColumnType('varbinary(max)', hasLength: true); + static const ColumnType image = ColumnType('image', hasLength: true); // JSON. - static const ColumnType json = ColumnType('json', true); - static const ColumnType jsonb = ColumnType('jsonb', true); + static const ColumnType json = ColumnType('json', hasLength: true); + static const ColumnType jsonb = ColumnType('jsonb', hasLength: true); // Misc. - static const ColumnType sqlVariant = ColumnType('sql_variant', true); + static const ColumnType sqlVariant = + ColumnType('sql_variant', hasLength: true); static const ColumnType uniqueIdentifier = - ColumnType('uniqueidentifier', true); - static const ColumnType xml = ColumnType('xml', true); - static const ColumnType cursor = ColumnType('cursor', true); - static const ColumnType table = ColumnType('table', true); + ColumnType('uniqueidentifier', hasLength: true); + static const ColumnType xml = ColumnType('xml', hasLength: true); + static const ColumnType cursor = ColumnType('cursor', hasLength: true); + static const ColumnType table = ColumnType('table', hasLength: true); } diff --git a/packages/orm/angel_orm/lib/src/query.dart b/packages/orm/angel_orm/lib/src/query.dart index b96f359e..fd07ce8b 100644 --- a/packages/orm/angel_orm/lib/src/query.dart +++ b/packages/orm/angel_orm/lib/src/query.dart @@ -377,7 +377,7 @@ abstract class Query extends QueryBase { var returningSql = ''; if (executor.dialect is PostgreSQLDialect) { var returning = fields.map(adornWithTableName).join(', '); - sql = 'WITH $tableName as ($insertion RETURNING $returning) ' + sql; + sql = 'WITH $tableName as ($insertion RETURNING $returning) $sql'; } else if (executor.dialect is MySQLDialect) { // Default to using 'id' as primary key in model if (fields.contains("id")) { @@ -422,7 +422,7 @@ abstract class Query extends QueryBase { var sql = compile({}); var returningSql = ''; if (executor.dialect is PostgreSQLDialect) { - sql = 'WITH $tableName as ($updateSql RETURNING $returning) ' + sql; + sql = 'WITH $tableName as ($updateSql RETURNING $returning) $sql'; } else if (executor.dialect is MySQLDialect) { returningSql = sql; sql = '$updateSql'; diff --git a/packages/orm/angel_orm_generator/lib/src/migration_generator.dart b/packages/orm/angel_orm_generator/lib/src/migration_generator.dart index a9a5d66c..b1f0cb79 100644 --- a/packages/orm/angel_orm_generator/lib/src/migration_generator.dart +++ b/packages/orm/angel_orm_generator/lib/src/migration_generator.dart @@ -135,7 +135,9 @@ class MigrationGenerator extends GeneratorForAnnotation { switch (col.type) { case ColumnType.varChar: methodName = 'varChar'; - named['length'] = literal(col.length); + if (col.type.hasLength) { + named['length'] = literal(col.length); + } break; case ColumnType.serial: methodName = 'serial'; @@ -148,9 +150,7 @@ class MigrationGenerator extends GeneratorForAnnotation { break; case ColumnType.numeric: methodName = 'numeric'; - break; - case ColumnType.double: - methodName = 'float'; + if (col.type.hasPrecision) {} break; case ColumnType.boolean: methodName = 'boolean'; diff --git a/packages/orm/angel_orm_generator/lib/src/orm_build_context.dart b/packages/orm/angel_orm_generator/lib/src/orm_build_context.dart index f9a12856..c9f972e8 100644 --- a/packages/orm/angel_orm_generator/lib/src/orm_build_context.dart +++ b/packages/orm/angel_orm_generator/lib/src/orm_build_context.dart @@ -342,10 +342,10 @@ ColumnType inferColumnType(DartType type) { return ColumnType.int; } if (const TypeChecker.fromRuntime(double).isAssignableFromType(type)) { - return ColumnType.double; + return ColumnType.float; } if (const TypeChecker.fromRuntime(num).isAssignableFromType(type)) { - return ColumnType.double; + return ColumnType.float; } if (const TypeChecker.fromRuntime(bool).isAssignableFromType(type)) { return ColumnType.boolean; @@ -426,7 +426,16 @@ class _ColumnType implements ColumnType { final String name; @override - final bool hasSize = false; + bool hasLength = false; + + @override + bool hasPrecision = false; + + @override + bool hasScale = false; + + @override + bool hasTimezone = false; //_ColumnType(this.name, [this.hasSize = false]); _ColumnType(this.name); diff --git a/packages/orm/angel_orm_generator/lib/src/orm_generator.dart b/packages/orm/angel_orm_generator/lib/src/orm_generator.dart index bf597ecf..8488c7f8 100644 --- a/packages/orm/angel_orm_generator/lib/src/orm_generator.dart +++ b/packages/orm/angel_orm_generator/lib/src/orm_generator.dart @@ -14,7 +14,6 @@ var floatTypes = [ ColumnType.float, ColumnType.numeric, ColumnType.real, - ColumnType.double, const ColumnType('double precision'), ]; @@ -498,7 +497,7 @@ class OrmGenerator extends GeneratorForAnnotation { // , b.write(foreignFields.isEmpty ? '' - : ', ' + foreignFields.join(', ')); + : ', ${foreignFields.join(', ')}'); // FROM users b.write(' FROM '); b.write(relationForeign.tableName); @@ -552,9 +551,8 @@ class OrmGenerator extends GeneratorForAnnotation { // There'll be a private `_field`, and then a getter, named `field`, // that returns the subquery object. - var foreignQueryType = refer(relationForeign - .buildContext.modelClassNameRecase.pascalCase + - 'Query'); + var foreignQueryType = refer( + '${relationForeign.buildContext.modelClassNameRecase.pascalCase}Query'); clazz ..fields.add(Field((b) => b diff --git a/packages/orm/angel_orm_generator/pubspec.yaml b/packages/orm/angel_orm_generator/pubspec.yaml index e417d41a..b9ac2e28 100644 --- a/packages/orm/angel_orm_generator/pubspec.yaml +++ b/packages/orm/angel_orm_generator/pubspec.yaml @@ -49,6 +49,6 @@ dependency_overrides: path: ../../serialize/angel_serialize_generator angel3_orm: path: ../angel_orm -# angel3_migration: -# path: ../angel_migration + angel3_migration: + path: ../angel_migration \ No newline at end of file diff --git a/packages/orm/angel_orm_postgres/CHANGELOG.md b/packages/orm/angel_orm_postgres/CHANGELOG.md index 55c462e6..fe6ac99c 100644 --- a/packages/orm/angel_orm_postgres/CHANGELOG.md +++ b/packages/orm/angel_orm_postgres/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## 6.0.1 + +* Upgraded to `lints` 2.x.x + ## 6.0.0 * Updated to SDK 2.16.x diff --git a/packages/orm/angel_orm_postgres/pubspec.yaml b/packages/orm/angel_orm_postgres/pubspec.yaml index cce84d47..7766554a 100644 --- a/packages/orm/angel_orm_postgres/pubspec.yaml +++ b/packages/orm/angel_orm_postgres/pubspec.yaml @@ -1,5 +1,5 @@ name: angel3_orm_postgres -version: 6.0.0 +version: 6.0.1 description: PostgreSQL support for Angel3 ORM. Includes functionality for querying and transactions. homepage: https://angel3-framework.web.app/ repository: https://github.com/dukefirehawk/angel/tree/master/packages/orm/angel_orm_postgres @@ -15,7 +15,7 @@ dev_dependencies: belatuk_pretty_logging: ^4.0.0 angel3_orm_test: ^6.0.0 test: ^1.21.0 - lints: ^1.0.0 + lints: ^2.0.0 dependency_overrides: # angel3_serialize: # path: ../../serialize/angel_serialize @@ -25,5 +25,5 @@ dependency_overrides: path: ../angel_orm_test angel3_orm: path: ../angel_orm -# angel3_migration: -# path: ../angel_migration + angel3_migration: + path: ../angel_migration diff --git a/packages/orm/angel_orm_postgres/test/migrations/person_order.sql b/packages/orm/angel_orm_postgres/test/migrations/person_order.sql index 77220ff7..9634def1 100644 --- a/packages/orm/angel_orm_postgres/test/migrations/person_order.sql +++ b/packages/orm/angel_orm_postgres/test/migrations/person_order.sql @@ -2,7 +2,7 @@ CREATE TEMPORARY TABLE "person_orders" ( "id" serial PRIMARY KEY, "person_id" int not null, "name" varchar(255), - "price" int, + "price" float, "deleted" bool not null default false, "created_at" timestamp, "updated_at" timestamp diff --git a/packages/orm/angel_orm_test/lib/src/models/bike.g.dart b/packages/orm/angel_orm_test/lib/src/models/bike.g.dart index 5ade9210..52652e76 100644 --- a/packages/orm/angel_orm_test/lib/src/models/bike.g.dart +++ b/packages/orm/angel_orm_test/lib/src/models/bike.g.dart @@ -164,7 +164,7 @@ class BikeQueryWhere extends QueryWhere { class BikeQueryValues extends MapQueryValues { @override Map get casts { - return {'price': 'double'}; + return {'price': 'float'}; } String? get id { diff --git a/packages/orm/angel_orm_test/lib/src/models/boat.g.dart b/packages/orm/angel_orm_test/lib/src/models/boat.g.dart index 1f05b986..a15cdf85 100644 --- a/packages/orm/angel_orm_test/lib/src/models/boat.g.dart +++ b/packages/orm/angel_orm_test/lib/src/models/boat.g.dart @@ -164,7 +164,7 @@ class BoatQueryWhere extends QueryWhere { class BoatQueryValues extends MapQueryValues { @override Map get casts { - return {'price': 'double'}; + return {'price': 'float'}; } String? get id { diff --git a/packages/orm/angel_orm_test/lib/src/models/leg.g.dart b/packages/orm/angel_orm_test/lib/src/models/leg.g.dart index f930d54f..d20a0306 100644 --- a/packages/orm/angel_orm_test/lib/src/models/leg.g.dart +++ b/packages/orm/angel_orm_test/lib/src/models/leg.g.dart @@ -279,7 +279,7 @@ class FootQueryWhere extends QueryWhere { class FootQueryValues extends MapQueryValues { @override Map get casts { - return {'n_toes': 'double'}; + return {'n_toes': 'float'}; } String? get id { diff --git a/packages/orm/angel_orm_test/lib/src/models/person.dart b/packages/orm/angel_orm_test/lib/src/models/person.dart index 8ea4be24..56403bd5 100644 --- a/packages/orm/angel_orm_test/lib/src/models/person.dart +++ b/packages/orm/angel_orm_test/lib/src/models/person.dart @@ -22,5 +22,5 @@ class _PersonWithLastOrder { String? lastOrderName; @Column(expression: 'po.price') - int? lastOrderPrice; + double? lastOrderPrice; } diff --git a/packages/orm/angel_orm_test/lib/src/models/person.g.dart b/packages/orm/angel_orm_test/lib/src/models/person.g.dart index b18bc29b..1b7e2622 100644 --- a/packages/orm/angel_orm_test/lib/src/models/person.g.dart +++ b/packages/orm/angel_orm_test/lib/src/models/person.g.dart @@ -179,7 +179,7 @@ class PersonWithLastOrderQuery @override Map get casts { - return {}; + return {'last_order_price': 'char'}; } @override @@ -219,7 +219,7 @@ class PersonWithLastOrderQuery lastOrderName: fields.contains('last_order_name') ? (row[1] as String?) : null, lastOrderPrice: - fields.contains('last_order_price') ? (row[2] as int?) : null); + fields.contains('last_order_price') ? mapToDouble(row[2]) : null); return Optional.of(model); } @@ -244,7 +244,7 @@ class PersonWithLastOrderQueryWhere extends QueryWhere { class PersonWithLastOrderQueryValues extends MapQueryValues { @override Map get casts { - return {}; + return {'last_order_price': 'float'}; } String? get name { @@ -333,10 +333,10 @@ class PersonWithLastOrder extends _PersonWithLastOrder { String? lastOrderName; @override - int? lastOrderPrice; + double? lastOrderPrice; PersonWithLastOrder copyWith( - {String? name, String? lastOrderName, int? lastOrderPrice}) { + {String? name, String? lastOrderName, double? lastOrderPrice}) { return PersonWithLastOrder( name: name ?? this.name, lastOrderName: lastOrderName ?? this.lastOrderName, @@ -474,7 +474,7 @@ class PersonWithLastOrderSerializer extends Codec { return PersonWithLastOrder( name: map['name'] as String?, lastOrderName: map['last_order_name'] as String?, - lastOrderPrice: map['last_order_price'] as int?); + lastOrderPrice: map['last_order_price'] as double?); } static Map toMap(_PersonWithLastOrder? model) { diff --git a/packages/orm/angel_orm_test/lib/src/models/person_order.g.dart b/packages/orm/angel_orm_test/lib/src/models/person_order.g.dart index d7908428..6f832c88 100644 --- a/packages/orm/angel_orm_test/lib/src/models/person_order.g.dart +++ b/packages/orm/angel_orm_test/lib/src/models/person_order.g.dart @@ -140,7 +140,7 @@ class PersonOrderQueryWhere extends QueryWhere { class PersonOrderQueryValues extends MapQueryValues { @override Map get casts { - return {'price': 'double'}; + return {'price': 'float'}; } String? get id { @@ -301,7 +301,7 @@ class OrderWithPersonInfoQueryWhere extends QueryWhere { class OrderWithPersonInfoQueryValues extends MapQueryValues { @override Map get casts { - return {'price': 'double'}; + return {'price': 'float'}; } String? get id { diff --git a/packages/orm/angel_orm_test/pubspec.yaml b/packages/orm/angel_orm_test/pubspec.yaml index 140beeed..7eb623b7 100644 --- a/packages/orm/angel_orm_test/pubspec.yaml +++ b/packages/orm/angel_orm_test/pubspec.yaml @@ -38,7 +38,7 @@ dependency_overrides: path: ../../serialize/angel_serialize_generator angel3_orm: path: ../angel_orm - # angel3_migration: - # path: ../angel_migration + angel3_migration: + path: ../angel_migration angel3_orm_generator: path: ../angel_orm_generator