diff --git a/.gitignore b/.gitignore index 589a652..ee5a63c 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ .dart_tool/ .packages build/ +.vscode/ pubspec.lock diff --git a/example/pubspec.yaml b/example/pubspec.yaml index bec7009..353ed68 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -8,5 +8,5 @@ dependencies: path: ../ dev_dependencies: - build_runner: ^2.1.7 - lints: ^1.0.1 \ No newline at end of file + build_runner: ^2.2.1 + lints: ^2.0.0 \ No newline at end of file diff --git a/pubspec.yaml b/pubspec.yaml index ee39c1f..784e58d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,21 +5,21 @@ repository: https://github.com/schultek/stormberry issue_tracker: https://github.com/schultek/stormberry/issues dependencies: - analyzer: ^3.3.1 + analyzer: ">=4.2.0 <5.0.0" args: ^2.3.1 - build: ^2.2.1 + build: ^2.3.1 collection: ^1.16.0 - crypto: ^3.0.1 - dart_style: ^2.2.2 + crypto: ^3.0.2 + dart_style: ^2.2.4 path: ^1.8.2 - postgres: ^2.4.3 - source_gen: ^1.2.1 - yaml: ^3.1.0 + postgres: ^2.5.1 + source_gen: ^1.2.3 + yaml: ^3.1.1 dev_dependencies: build_runner: ^2.2.0 - lints: ^1.0.1 - test: ^1.21.1 + lints: ^2.0.0 + test: ^1.21.6 environment: - sdk: '>=2.12.0 <3.0.0' + sdk: '>=2.16.0 <3.0.0' diff --git a/test/packages/multi_schema/lib/modelsA.schema.g.dart b/test/packages/multi_schema/lib/modelsA.schema.g.dart index 4f2ab3d..5ce47b5 100644 --- a/test/packages/multi_schema/lib/modelsA.schema.g.dart +++ b/test/packages/multi_schema/lib/modelsA.schema.g.dart @@ -1,6 +1,7 @@ // ignore_for_file: prefer_relative_imports import 'package:stormberry/internals.dart'; -import 'package:multi_schema_test/modelsA.dart'; + +import 'modelsA.dart'; extension Repositories on Database { ModelARepository get modelAs => ModelARepository._(this); @@ -12,7 +13,7 @@ abstract class ModelARepository implements ModelRepository, ModelRepositoryInsert, ModelRepositoryUpdate { factory ModelARepository._(Database db) = _ModelARepository; - Future> queryViewaViews([QueryParams? params]); + Future> queryViewAViews([QueryParams? params]); } class _ModelARepository extends BaseRepository @@ -21,30 +22,30 @@ class _ModelARepository extends BaseRepository _ModelARepository(Database db) : super(db: db); @override - Future> queryViewaViews([QueryParams? params]) { - return queryMany(ViewaModelAViewQueryable(), params); + Future> queryViewAViews([QueryParams? params]) { + return queryMany(ViewAModelAViewQueryable(), params); } @override Future insert(Database db, List requests) async { if (requests.isEmpty) return; - await db.query(""" - INSERT INTO "model_as" ( "data" ) - VALUES ${requests.map((r) => '( ${registry.encode(r.data)} )').join(', ')} - - """); + + await db.query( + 'INSERT INTO "model_as" ( "data" )\n' + 'VALUES ${requests.map((r) => '( ${registry.encode(r.data)} )').join(', ')}\n', + ); } @override Future update(Database db, List requests) async { if (requests.isEmpty) return; - await db.query(""" - UPDATE "model_as" - SET "data" = COALESCE(UPDATED."data"::text, "model_as"."data") - FROM ( VALUES ${requests.map((r) => '( ${registry.encode(r.data)} )').join(', ')} ) - AS UPDATED("data") - WHERE - """); + await db.query( + 'UPDATE "model_as"\n' + 'SET "data" = COALESCE(UPDATED."data"::text, "model_as"."data")\n' + 'FROM ( VALUES ${requests.map((r) => '( ${registry.encode(r.data)} )').join(', ')} )\n' + 'AS UPDATED("data")\n' + 'WHERE ', + ); } } @@ -58,17 +59,17 @@ class ModelAUpdateRequest { String? data; } -class ViewaModelAViewQueryable extends ViewQueryable { +class ViewAModelAViewQueryable extends ViewQueryable { @override - String get tableName => 'viewa_model_as_view'; + String get tableName => 'view_a_model_as_view'; @override String get tableAlias => 'model_as'; @override - ViewaModelAView decode(TypedMap map) => ViewaModelAView(); + ViewAModelAView decode(TypedMap map) => ViewAModelAView(); } -class ViewaModelAView { - ViewaModelAView(); +class ViewAModelAView { + ViewAModelAView(); } diff --git a/test/packages/multi_schema/lib/modelsB.schema.g.dart b/test/packages/multi_schema/lib/modelsB.schema.g.dart index 553195a..21f47f5 100644 --- a/test/packages/multi_schema/lib/modelsB.schema.g.dart +++ b/test/packages/multi_schema/lib/modelsB.schema.g.dart @@ -1,6 +1,7 @@ // ignore_for_file: prefer_relative_imports import 'package:stormberry/internals.dart'; -import 'package:multi_schema_test/modelsB.dart'; + +import 'modelsB.dart'; extension Repositories on Database { ModelBRepository get modelBs => ModelBRepository._(this); @@ -12,7 +13,7 @@ abstract class ModelBRepository implements ModelRepository, ModelRepositoryInsert, ModelRepositoryUpdate { factory ModelBRepository._(Database db) = _ModelBRepository; - Future> queryViewbViews([QueryParams? params]); + Future> queryViewBViews([QueryParams? params]); } class _ModelBRepository extends BaseRepository @@ -21,30 +22,30 @@ class _ModelBRepository extends BaseRepository _ModelBRepository(Database db) : super(db: db); @override - Future> queryViewbViews([QueryParams? params]) { - return queryMany(ViewbModelBViewQueryable(), params); + Future> queryViewBViews([QueryParams? params]) { + return queryMany(ViewBModelBViewQueryable(), params); } @override Future insert(Database db, List requests) async { if (requests.isEmpty) return; - await db.query(""" - INSERT INTO "model_bs" ( "data" ) - VALUES ${requests.map((r) => '( ${registry.encode(r.data)} )').join(', ')} - - """); + + await db.query( + 'INSERT INTO "model_bs" ( "data" )\n' + 'VALUES ${requests.map((r) => '( ${registry.encode(r.data)} )').join(', ')}\n', + ); } @override Future update(Database db, List requests) async { if (requests.isEmpty) return; - await db.query(""" - UPDATE "model_bs" - SET "data" = COALESCE(UPDATED."data"::text, "model_bs"."data") - FROM ( VALUES ${requests.map((r) => '( ${registry.encode(r.data)} )').join(', ')} ) - AS UPDATED("data") - WHERE - """); + await db.query( + 'UPDATE "model_bs"\n' + 'SET "data" = COALESCE(UPDATED."data"::text, "model_bs"."data")\n' + 'FROM ( VALUES ${requests.map((r) => '( ${registry.encode(r.data)} )').join(', ')} )\n' + 'AS UPDATED("data")\n' + 'WHERE ', + ); } } @@ -58,17 +59,17 @@ class ModelBUpdateRequest { String? data; } -class ViewbModelBViewQueryable extends ViewQueryable { +class ViewBModelBViewQueryable extends ViewQueryable { @override - String get tableName => 'viewb_model_bs_view'; + String get tableName => 'view_b_model_bs_view'; @override String get tableAlias => 'model_bs'; @override - ViewbModelBView decode(TypedMap map) => ViewbModelBView(); + ViewBModelBView decode(TypedMap map) => ViewBModelBView(); } -class ViewbModelBView { - ViewbModelBView(); +class ViewBModelBView { + ViewBModelBView(); } diff --git a/test/packages/multi_schema/pubspec.yaml b/test/packages/multi_schema/pubspec.yaml index 7529fcc..df95241 100644 --- a/test/packages/multi_schema/pubspec.yaml +++ b/test/packages/multi_schema/pubspec.yaml @@ -8,5 +8,5 @@ dependencies: path: ../../../ dev_dependencies: - build_runner: ^2.1.7 - lints: ^1.0.1 \ No newline at end of file + build_runner: ^2.2.1 + lints: ^2.0.0 \ No newline at end of file diff --git a/test/packages/serialization/lib/models.mapper.g.dart b/test/packages/serialization/lib/models.mapper.g.dart index e1f8875..d89f90a 100644 --- a/test/packages/serialization/lib/models.mapper.g.dart +++ b/test/packages/serialization/lib/models.mapper.g.dart @@ -25,15 +25,15 @@ class UserInsertRequestMapper extends BaseMapper { @override Function get decoder => decode; UserInsertRequest decode(dynamic v) => checked(v, (Map map) => fromMap(map)); - UserInsertRequest fromMap(Map map) => UserInsertRequest(companyId: Mapper.i.$getOpt(map, 'companyId'), id: Mapper.i.$get(map, 'id'), name: Mapper.i.$get(map, 'name'), securityNumber: Mapper.i.$get(map, 'securityNumber')); + UserInsertRequest fromMap(Map map) => UserInsertRequest(id: Mapper.i.$get(map, 'id'), name: Mapper.i.$get(map, 'name'), securityNumber: Mapper.i.$get(map, 'securityNumber')); @override Function get encoder => (UserInsertRequest v) => encode(v); dynamic encode(UserInsertRequest v) => toMap(v); - Map toMap(UserInsertRequest u) => {'companyId': Mapper.i.$enc(u.companyId, 'companyId'), 'id': Mapper.i.$enc(u.id, 'id'), 'name': Mapper.i.$enc(u.name, 'name'), 'securityNumber': Mapper.i.$enc(u.securityNumber, 'securityNumber')}; + Map toMap(UserInsertRequest u) => {'id': Mapper.i.$enc(u.id, 'id'), 'name': Mapper.i.$enc(u.name, 'name'), 'securityNumber': Mapper.i.$enc(u.securityNumber, 'securityNumber')}; - @override String stringify(UserInsertRequest self) => 'UserInsertRequest(companyId: ${Mapper.asString(self.companyId)}, id: ${Mapper.asString(self.id)}, name: ${Mapper.asString(self.name)}, securityNumber: ${Mapper.asString(self.securityNumber)})'; - @override int hash(UserInsertRequest self) => Mapper.hash(self.companyId) ^ Mapper.hash(self.id) ^ Mapper.hash(self.name) ^ Mapper.hash(self.securityNumber); - @override bool equals(UserInsertRequest self, UserInsertRequest other) => Mapper.isEqual(self.companyId, other.companyId) && Mapper.isEqual(self.id, other.id) && Mapper.isEqual(self.name, other.name) && Mapper.isEqual(self.securityNumber, other.securityNumber); + @override String stringify(UserInsertRequest self) => 'UserInsertRequest(id: ${Mapper.asString(self.id)}, name: ${Mapper.asString(self.name)}, securityNumber: ${Mapper.asString(self.securityNumber)})'; + @override int hash(UserInsertRequest self) => Mapper.hash(self.id) ^ Mapper.hash(self.name) ^ Mapper.hash(self.securityNumber); + @override bool equals(UserInsertRequest self, UserInsertRequest other) => Mapper.isEqual(self.id, other.id) && Mapper.isEqual(self.name, other.name) && Mapper.isEqual(self.securityNumber, other.securityNumber); @override Function get typeFactory => (f) => f(); } @@ -46,14 +46,14 @@ extension UserInsertRequestMapperExtension on UserInsertRequest { abstract class UserInsertRequestCopyWith<$R> { factory UserInsertRequestCopyWith(UserInsertRequest value, Then then) = _UserInsertRequestCopyWithImpl<$R>; - $R call({String? companyId, String? id, String? name, String? securityNumber}); + $R call({String? id, String? name, String? securityNumber}); $R apply(UserInsertRequest Function(UserInsertRequest) transform); } class _UserInsertRequestCopyWithImpl<$R> extends BaseCopyWith implements UserInsertRequestCopyWith<$R> { _UserInsertRequestCopyWithImpl(UserInsertRequest value, Then then) : super(value, then); - @override $R call({Object? companyId = $none, String? id, String? name, String? securityNumber}) => $then(UserInsertRequest(companyId: or(companyId, $value.companyId), id: id ?? $value.id, name: name ?? $value.name, securityNumber: securityNumber ?? $value.securityNumber)); + @override $R call({String? id, String? name, String? securityNumber}) => $then(UserInsertRequest(id: id ?? $value.id, name: name ?? $value.name, securityNumber: securityNumber ?? $value.securityNumber)); } class UserUpdateRequestMapper extends BaseMapper { @@ -61,15 +61,15 @@ class UserUpdateRequestMapper extends BaseMapper { @override Function get decoder => decode; UserUpdateRequest decode(dynamic v) => checked(v, (Map map) => fromMap(map)); - UserUpdateRequest fromMap(Map map) => UserUpdateRequest(companyId: Mapper.i.$getOpt(map, 'companyId'), id: Mapper.i.$get(map, 'id'), name: Mapper.i.$getOpt(map, 'name'), securityNumber: Mapper.i.$getOpt(map, 'securityNumber')); + UserUpdateRequest fromMap(Map map) => UserUpdateRequest(id: Mapper.i.$get(map, 'id'), name: Mapper.i.$getOpt(map, 'name'), securityNumber: Mapper.i.$getOpt(map, 'securityNumber')); @override Function get encoder => (UserUpdateRequest v) => encode(v); dynamic encode(UserUpdateRequest v) => toMap(v); - Map toMap(UserUpdateRequest u) => {'companyId': Mapper.i.$enc(u.companyId, 'companyId'), 'id': Mapper.i.$enc(u.id, 'id'), 'name': Mapper.i.$enc(u.name, 'name'), 'securityNumber': Mapper.i.$enc(u.securityNumber, 'securityNumber')}; + Map toMap(UserUpdateRequest u) => {'id': Mapper.i.$enc(u.id, 'id'), 'name': Mapper.i.$enc(u.name, 'name'), 'securityNumber': Mapper.i.$enc(u.securityNumber, 'securityNumber')}; - @override String stringify(UserUpdateRequest self) => 'UserUpdateRequest(companyId: ${Mapper.asString(self.companyId)}, id: ${Mapper.asString(self.id)}, name: ${Mapper.asString(self.name)}, securityNumber: ${Mapper.asString(self.securityNumber)})'; - @override int hash(UserUpdateRequest self) => Mapper.hash(self.companyId) ^ Mapper.hash(self.id) ^ Mapper.hash(self.name) ^ Mapper.hash(self.securityNumber); - @override bool equals(UserUpdateRequest self, UserUpdateRequest other) => Mapper.isEqual(self.companyId, other.companyId) && Mapper.isEqual(self.id, other.id) && Mapper.isEqual(self.name, other.name) && Mapper.isEqual(self.securityNumber, other.securityNumber); + @override String stringify(UserUpdateRequest self) => 'UserUpdateRequest(id: ${Mapper.asString(self.id)}, name: ${Mapper.asString(self.name)}, securityNumber: ${Mapper.asString(self.securityNumber)})'; + @override int hash(UserUpdateRequest self) => Mapper.hash(self.id) ^ Mapper.hash(self.name) ^ Mapper.hash(self.securityNumber); + @override bool equals(UserUpdateRequest self, UserUpdateRequest other) => Mapper.isEqual(self.id, other.id) && Mapper.isEqual(self.name, other.name) && Mapper.isEqual(self.securityNumber, other.securityNumber); @override Function get typeFactory => (f) => f(); } @@ -82,14 +82,14 @@ extension UserUpdateRequestMapperExtension on UserUpdateRequest { abstract class UserUpdateRequestCopyWith<$R> { factory UserUpdateRequestCopyWith(UserUpdateRequest value, Then then) = _UserUpdateRequestCopyWithImpl<$R>; - $R call({String? companyId, String? id, String? name, String? securityNumber}); + $R call({String? id, String? name, String? securityNumber}); $R apply(UserUpdateRequest Function(UserUpdateRequest) transform); } class _UserUpdateRequestCopyWithImpl<$R> extends BaseCopyWith implements UserUpdateRequestCopyWith<$R> { _UserUpdateRequestCopyWithImpl(UserUpdateRequest value, Then then) : super(value, then); - @override $R call({Object? companyId = $none, String? id, Object? name = $none, Object? securityNumber = $none}) => $then(UserUpdateRequest(companyId: or(companyId, $value.companyId), id: id ?? $value.id, name: or(name, $value.name), securityNumber: or(securityNumber, $value.securityNumber))); + @override $R call({String? id, Object? name = $none, Object? securityNumber = $none}) => $then(UserUpdateRequest(id: id ?? $value.id, name: or(name, $value.name), securityNumber: or(securityNumber, $value.securityNumber))); } class DefaultUserViewMapper extends BaseMapper { diff --git a/test/packages/serialization/lib/models.schema.g.dart b/test/packages/serialization/lib/models.schema.g.dart index 4da80ca..9ccaa35 100644 --- a/test/packages/serialization/lib/models.schema.g.dart +++ b/test/packages/serialization/lib/models.schema.g.dart @@ -1,6 +1,7 @@ // ignore_for_file: prefer_relative_imports import 'package:stormberry/internals.dart'; -import 'package:serialization_test/models.dart'; + +import 'models.dart'; extension Repositories on Database { UserRepository get users => UserRepository._(this); @@ -55,32 +56,32 @@ class _UserRepository extends BaseRepository Future insert(Database db, List requests) async { if (requests.isEmpty) return; - await db.query(""" - INSERT INTO "users" ( "company_id", "id", "name", "security_number" ) - VALUES ${requests.map((r) => '( ${registry.encode(r.companyId)}, ${registry.encode(r.id)}, ${registry.encode(r.name)}, ${registry.encode(r.securityNumber)} )').join(', ')} -ON CONFLICT ( "id" ) DO UPDATE SET "company_id" = EXCLUDED."company_id", "name" = EXCLUDED."name", "security_number" = EXCLUDED."security_number" - """); + await db.query( + 'INSERT INTO "users" ( "id", "name", "security_number" )\n' + 'VALUES ${requests.map((r) => '( ${registry.encode(r.id)}, ${registry.encode(r.name)}, ${registry.encode(r.securityNumber)} )').join(', ')}\n' + 'ON CONFLICT ( "id" ) DO UPDATE SET "name" = EXCLUDED."name", "security_number" = EXCLUDED."security_number"', + ); } @override Future update(Database db, List requests) async { if (requests.isEmpty) return; - await db.query(""" - UPDATE "users" - SET "company_id" = COALESCE(UPDATED."company_id"::text, "users"."company_id"), "name" = COALESCE(UPDATED."name"::text, "users"."name"), "security_number" = COALESCE(UPDATED."security_number"::text, "users"."security_number") - FROM ( VALUES ${requests.map((r) => '( ${registry.encode(r.companyId)}, ${registry.encode(r.id)}, ${registry.encode(r.name)}, ${registry.encode(r.securityNumber)} )').join(', ')} ) - AS UPDATED("company_id", "id", "name", "security_number") - WHERE "users"."id" = UPDATED."id" - """); + await db.query( + 'UPDATE "users"\n' + 'SET "name" = COALESCE(UPDATED."name"::text, "users"."name"), "security_number" = COALESCE(UPDATED."security_number"::text, "users"."security_number")\n' + 'FROM ( VALUES ${requests.map((r) => '( ${registry.encode(r.id)}, ${registry.encode(r.name)}, ${registry.encode(r.securityNumber)} )').join(', ')} )\n' + 'AS UPDATED("id", "name", "security_number")\n' + 'WHERE "users"."id" = UPDATED."id"', + ); } @override Future delete(Database db, List keys) async { if (keys.isEmpty) return; - await db.query(""" - DELETE FROM "users" - WHERE "users"."id" IN ( ${keys.map((k) => registry.encode(k)).join(',')} ) - """); + await db.query( + 'DELETE FROM "users"\n' + 'WHERE "users"."id" IN ( ${keys.map((k) => registry.encode(k)).join(',')} )', + ); } } @@ -118,39 +119,38 @@ class _CompanyRepository extends BaseRepository Future insert(Database db, List requests) async { if (requests.isEmpty) return; - await db.query(""" - INSERT INTO "companies" ( "id", "member_id" ) - VALUES ${requests.map((r) => '( ${registry.encode(r.id)}, ${registry.encode(r.memberId)} )').join(', ')} -ON CONFLICT ( "id" ) DO UPDATE SET "member_id" = EXCLUDED."member_id" - """); + await db.query( + 'INSERT INTO "companies" ( "id", "member_id" )\n' + 'VALUES ${requests.map((r) => '( ${registry.encode(r.id)}, ${registry.encode(r.memberId)} )').join(', ')}\n' + 'ON CONFLICT ( "id" ) DO UPDATE SET "member_id" = EXCLUDED."member_id"', + ); } @override Future update(Database db, List requests) async { if (requests.isEmpty) return; - await db.query(""" - UPDATE "companies" - SET "member_id" = COALESCE(UPDATED."member_id"::text, "companies"."member_id") - FROM ( VALUES ${requests.map((r) => '( ${registry.encode(r.id)}, ${registry.encode(r.memberId)} )').join(', ')} ) - AS UPDATED("id", "member_id") - WHERE "companies"."id" = UPDATED."id" - """); + await db.query( + 'UPDATE "companies"\n' + 'SET "member_id" = COALESCE(UPDATED."member_id"::text, "companies"."member_id")\n' + 'FROM ( VALUES ${requests.map((r) => '( ${registry.encode(r.id)}, ${registry.encode(r.memberId)} )').join(', ')} )\n' + 'AS UPDATED("id", "member_id")\n' + 'WHERE "companies"."id" = UPDATED."id"', + ); } @override Future delete(Database db, List keys) async { if (keys.isEmpty) return; - await db.query(""" - DELETE FROM "companies" - WHERE "companies"."id" IN ( ${keys.map((k) => registry.encode(k)).join(',')} ) - """); + await db.query( + 'DELETE FROM "companies"\n' + 'WHERE "companies"."id" IN ( ${keys.map((k) => registry.encode(k)).join(',')} )', + ); } } @MappableClass() class UserInsertRequest { - UserInsertRequest({this.companyId, required this.id, required this.name, required this.securityNumber}); - String? companyId; + UserInsertRequest({required this.id, required this.name, required this.securityNumber}); String id; String name; String securityNumber; @@ -164,17 +164,16 @@ class CompanyInsertRequest { @MappableClass() class UserUpdateRequest { - UserUpdateRequest({this.companyId, required this.id, this.name, this.securityNumber}); - String? companyId; + UserUpdateRequest({required this.id, this.name, this.securityNumber}); String id; String? name; String? securityNumber; } class CompanyUpdateRequest { - CompanyUpdateRequest({required this.id, required this.memberId}); + CompanyUpdateRequest({required this.id, this.memberId}); String id; - String memberId; + String? memberId; } class DefaultUserViewQueryable extends KeyedViewQueryable {