diff --git a/example/lib/main.dart b/example/lib/main.dart index b5cb732..96f9f59 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -27,11 +27,12 @@ Future main() async { await db.accounts.deleteMany([0, 1, 2]); var accountId = await db.accounts.insertOne(AccountInsertRequest( - firstName: 'Test', - lastName: 'User', - location: LatLng(1, 2), - billingAddress: BillingAddress(name: 'Test User', street: 'SomeRoad 1', city: 'New York', postcode: '123'), - companyId: 'abc', + firstName: 'Test', + lastName: 'User', + location: LatLng(1, 2), + billingAddress: + BillingAddress(name: 'Test User', street: 'SomeRoad 1', city: 'New York', postcode: '123'), + companyId: 'abc', )); var account = await db.accounts.queryUserView(accountId); diff --git a/example/lib/model.dart b/example/lib/model.dart index 5867605..04386aa 100644 --- a/example/lib/model.dart +++ b/example/lib/model.dart @@ -16,4 +16,4 @@ abstract class B { String get id; A? get a; -} \ No newline at end of file +} diff --git a/example/lib/model.schema.dart b/example/lib/model.schema.dart index d7bc6ad..61db2db 100644 --- a/example/lib/model.schema.dart +++ b/example/lib/model.schema.dart @@ -18,7 +18,10 @@ abstract class ARepository } class _ARepository extends BaseRepository - with RepositoryInsertMixin, RepositoryUpdateMixin, RepositoryDeleteMixin + with + RepositoryInsertMixin, + RepositoryUpdateMixin, + RepositoryDeleteMixin implements ARepository { _ARepository(super.db) : super(tableName: 'as', keyName: 'id'); @@ -72,7 +75,10 @@ abstract class BRepository } class _BRepository extends BaseRepository - with RepositoryInsertMixin, RepositoryUpdateMixin, RepositoryDeleteMixin + with + RepositoryInsertMixin, + RepositoryUpdateMixin, + RepositoryDeleteMixin implements BRepository { _BRepository(super.db) : super(tableName: 'bs', keyName: 'id'); diff --git a/example/lib/models/account.dart b/example/lib/models/account.dart index df54253..179bd3d 100644 --- a/example/lib/models/account.dart +++ b/example/lib/models/account.dart @@ -7,6 +7,7 @@ import 'latlng.dart'; import 'party.dart'; part 'account.schema.dart'; + //a @Model(views: [#Full, #User, #Company]) abstract class Account { diff --git a/example/lib/models/account.schema.dart b/example/lib/models/account.schema.dart index 54f3b67..82c9265 100644 --- a/example/lib/models/account.schema.dart +++ b/example/lib/models/account.schema.dart @@ -66,19 +66,18 @@ class _AccountRepository extends BaseRepository var values = QueryValues(); await db.query( - 'INSERT INTO "accounts" ( "company_id", "id", "first_name", "last_name", "location" )\n' - 'VALUES ${requests.map((r) => '( ${values.add(r.companyId)}, ${values.add(autoIncrements[requests.indexOf(r)]['id'])}, ${values.add(r.firstName)}, ${values.add(r.lastName)}, ${values.add(LatLngConverter().tryEncode(r.location))} )').join(', ')}\n', + 'INSERT INTO "accounts" ( "id", "first_name", "last_name", "location", "company_id" )\n' + 'VALUES ${requests.map((r) => '( ${values.add(autoIncrements[requests.indexOf(r)]['id'])}, ${values.add(r.firstName)}, ${values.add(r.lastName)}, ${values.add(LatLngConverter().tryEncode(r.location))}, ${values.add(r.companyId)} )').join(', ')}\n', values.values, ); await db.billingAddresses.insertMany(requests.where((r) => r.billingAddress != null).map((r) { return BillingAddressInsertRequest( - companyId: null, - accountId: TextEncoder.i.decode(autoIncrements[requests.indexOf(r)]['id']), - city: r.billingAddress!.city, - postcode: r.billingAddress!.postcode, - name: r.billingAddress!.name, - street: r.billingAddress!.street, - ); + city: r.billingAddress!.city, + postcode: r.billingAddress!.postcode, + name: r.billingAddress!.name, + street: r.billingAddress!.street, + accountId: TextEncoder.i.decode(autoIncrements[requests.indexOf(r)]['id']), + companyId: null); }).toList()); return autoIncrements.map((m) => TextEncoder.i.decode(m['id'])).toList(); @@ -90,9 +89,9 @@ class _AccountRepository extends BaseRepository var values = QueryValues(); await db.query( 'UPDATE "accounts"\n' - 'SET "company_id" = COALESCE(UPDATED."company_id"::text, "accounts"."company_id"), "first_name" = COALESCE(UPDATED."first_name"::text, "accounts"."first_name"), "last_name" = COALESCE(UPDATED."last_name"::text, "accounts"."last_name"), "location" = COALESCE(UPDATED."location"::point, "accounts"."location")\n' - 'FROM ( VALUES ${requests.map((r) => '( ${values.add(r.companyId)}, ${values.add(r.id)}, ${values.add(r.firstName)}, ${values.add(r.lastName)}, ${values.add(LatLngConverter().tryEncode(r.location))} )').join(', ')} )\n' - 'AS UPDATED("company_id", "id", "first_name", "last_name", "location")\n' + 'SET "first_name" = COALESCE(UPDATED."first_name"::text, "accounts"."first_name"), "last_name" = COALESCE(UPDATED."last_name"::text, "accounts"."last_name"), "location" = COALESCE(UPDATED."location"::point, "accounts"."location"), "company_id" = COALESCE(UPDATED."company_id"::text, "accounts"."company_id")\n' + 'FROM ( VALUES ${requests.map((r) => '( ${values.add(r.id)}, ${values.add(r.firstName)}, ${values.add(r.lastName)}, ${values.add(LatLngConverter().tryEncode(r.location))}, ${values.add(r.companyId)} )').join(', ')} )\n' + 'AS UPDATED("id", "first_name", "last_name", "location", "company_id")\n' 'WHERE "accounts"."id" = UPDATED."id"', values.values, ); @@ -109,36 +108,36 @@ class _AccountRepository extends BaseRepository class AccountInsertRequest { AccountInsertRequest({ - this.companyId, required this.firstName, required this.lastName, required this.location, this.billingAddress, + this.companyId, }); - String? companyId; String firstName; String lastName; LatLng location; BillingAddress? billingAddress; + String? companyId; } class AccountUpdateRequest { AccountUpdateRequest({ - this.companyId, required this.id, this.firstName, this.lastName, this.location, this.billingAddress, + this.companyId, }); - String? companyId; int id; String? firstName; String? lastName; LatLng? location; BillingAddress? billingAddress; + String? companyId; } class FullAccountViewQueryable extends KeyedViewQueryable { @@ -178,9 +177,9 @@ class FullAccountViewQueryable extends KeyedViewQueryable @override FullAccountView decode(TypedMap map) => FullAccountView( - id: map.get('id', TextEncoder.i.decode), - firstName: map.get('first_name', TextEncoder.i.decode), - lastName: map.get('last_name', TextEncoder.i.decode), + id: map.get('id'), + firstName: map.get('first_name'), + lastName: map.get('last_name'), location: map.get('location', LatLngConverter().decode), billingAddress: map.getOpt('billingAddress', BillingAddressQueryable().decoder), invoices: map.getListOpt('invoices', OwnerInvoiceViewQueryable().decoder) ?? const [], @@ -247,9 +246,9 @@ class UserAccountViewQueryable extends KeyedViewQueryable @override UserAccountView decode(TypedMap map) => UserAccountView( - id: map.get('id', TextEncoder.i.decode), - firstName: map.get('first_name', TextEncoder.i.decode), - lastName: map.get('last_name', TextEncoder.i.decode), + id: map.get('id'), + firstName: map.get('first_name'), + lastName: map.get('last_name'), location: map.get('location', LatLngConverter().decode), billingAddress: map.getOpt('billingAddress', BillingAddressQueryable().decoder), invoices: map.getListOpt('invoices', OwnerInvoiceViewQueryable().decoder) ?? const [], diff --git a/example/lib/models/address.schema.dart b/example/lib/models/address.schema.dart index 3eee810..0195e43 100644 --- a/example/lib/models/address.schema.dart +++ b/example/lib/models/address.schema.dart @@ -15,7 +15,9 @@ abstract class BillingAddressRepository } class _BillingAddressRepository extends BaseRepository - with RepositoryInsertMixin, RepositoryUpdateMixin + with + RepositoryInsertMixin, + RepositoryUpdateMixin implements BillingAddressRepository { _BillingAddressRepository(super.db) : super(tableName: 'billing_addresses'); @@ -30,8 +32,8 @@ class _BillingAddressRepository extends BaseRepository var values = QueryValues(); await db.query( - 'INSERT INTO "billing_addresses" ( "company_id", "account_id", "city", "postcode", "name", "street" )\n' - 'VALUES ${requests.map((r) => '( ${values.add(r.companyId)}, ${values.add(r.accountId)}, ${values.add(r.city)}, ${values.add(r.postcode)}, ${values.add(r.name)}, ${values.add(r.street)} )').join(', ')}\n', + 'INSERT INTO "billing_addresses" ( "city", "postcode", "name", "street", "account_id", "company_id" )\n' + 'VALUES ${requests.map((r) => '( ${values.add(r.city)}, ${values.add(r.postcode)}, ${values.add(r.name)}, ${values.add(r.street)}, ${values.add(r.accountId)}, ${values.add(r.companyId)} )').join(', ')}\n', values.values, ); } @@ -43,9 +45,9 @@ class _BillingAddressRepository extends BaseRepository await db.query( 'UPDATE "billing_addresses"\n' 'SET "city" = COALESCE(UPDATED."city"::text, "billing_addresses"."city"), "postcode" = COALESCE(UPDATED."postcode"::text, "billing_addresses"."postcode"), "name" = COALESCE(UPDATED."name"::text, "billing_addresses"."name"), "street" = COALESCE(UPDATED."street"::text, "billing_addresses"."street")\n' - 'FROM ( VALUES ${requests.map((r) => '( ${values.add(r.companyId)}, ${values.add(r.accountId)}, ${values.add(r.city)}, ${values.add(r.postcode)}, ${values.add(r.name)}, ${values.add(r.street)} )').join(', ')} )\n' - 'AS UPDATED("company_id", "account_id", "city", "postcode", "name", "street")\n' - 'WHERE "billing_addresses"."company_id" = UPDATED."company_id" AND "billing_addresses"."account_id" = UPDATED."account_id"', + 'FROM ( VALUES ${requests.map((r) => '( ${values.add(r.city)}, ${values.add(r.postcode)}, ${values.add(r.name)}, ${values.add(r.street)}, ${values.add(r.accountId)}, ${values.add(r.companyId)} )').join(', ')} )\n' + 'AS UPDATED("city", "postcode", "name", "street", "account_id", "company_id")\n' + 'WHERE "billing_addresses"."account_id" = UPDATED."account_id" AND "billing_addresses"."company_id" = UPDATED."company_id"', values.values, ); } @@ -53,38 +55,38 @@ class _BillingAddressRepository extends BaseRepository class BillingAddressInsertRequest { BillingAddressInsertRequest({ - this.companyId, - this.accountId, required this.city, required this.postcode, required this.name, required this.street, + this.accountId, + this.companyId, }); - String? companyId; - int? accountId; String city; String postcode; String name; String street; + int? accountId; + String? companyId; } class BillingAddressUpdateRequest { BillingAddressUpdateRequest({ - this.companyId, - this.accountId, this.city, this.postcode, this.name, this.street, + this.accountId, + this.companyId, }); - String? companyId; - int? accountId; String? city; String? postcode; String? name; String? street; + int? accountId; + String? companyId; } class BillingAddressQueryable extends ViewQueryable { @@ -97,7 +99,10 @@ class BillingAddressQueryable extends ViewQueryable { @override BillingAddress decode(TypedMap map) => BillingAddressView( - city: map.get('city'), postcode: map.get('postcode'), name: map.get('name'), street: map.get('street')); + city: map.get('city'), + postcode: map.get('postcode'), + name: map.get('name'), + street: map.get('street')); } class BillingAddressView with BillingAddress { diff --git a/example/lib/models/company.dart b/example/lib/models/company.dart index ca6fac7..db68c66 100644 --- a/example/lib/models/company.dart +++ b/example/lib/models/company.dart @@ -9,7 +9,6 @@ part 'company.schema.dart'; @Model(views: [#Full, #Member]) abstract class Company { - @PrimaryKey() String get id; @@ -28,4 +27,4 @@ abstract class Company { @HiddenIn(#Member) @ViewedIn(#Full, as: #Company) List get parties; -} \ No newline at end of file +} diff --git a/example/lib/models/company.schema.dart b/example/lib/models/company.schema.dart index 561fc24..4693d5f 100644 --- a/example/lib/models/company.schema.dart +++ b/example/lib/models/company.schema.dart @@ -58,7 +58,7 @@ class _CompanyRepository extends BaseRepository ); await db.billingAddresses.insertMany(requests.expand((r) { return r.addresses.map((rr) => BillingAddressInsertRequest( - companyId: r.id, accountId: null, city: rr.city, postcode: rr.postcode, name: rr.name, street: rr.street)); + city: rr.city, postcode: rr.postcode, name: rr.name, street: rr.street, accountId: null, companyId: r.id)); }).toList()); } @@ -150,12 +150,12 @@ class FullCompanyViewQueryable extends KeyedViewQueryable FullCompanyView( + id: map.get('id'), + name: map.get('name'), + addresses: map.getListOpt('addresses', BillingAddressQueryable().decoder) ?? const [], members: map.getListOpt('members', CompanyAccountViewQueryable().decoder) ?? const [], - parties: map.getListOpt('parties', CompanyPartyViewQueryable().decoder) ?? const [], invoices: map.getListOpt('invoices', OwnerInvoiceViewQueryable().decoder) ?? const [], - id: map.get('id', TextEncoder.i.decode), - name: map.get('name', TextEncoder.i.decode), - addresses: map.getListOpt('addresses', BillingAddressQueryable().decoder) ?? const [],); + parties: map.getListOpt('parties', CompanyPartyViewQueryable().decoder) ?? const []); } class FullCompanyView { diff --git a/example/lib/models/invoice.dart b/example/lib/models/invoice.dart index 8e7d5ea..011396f 100644 --- a/example/lib/models/invoice.dart +++ b/example/lib/models/invoice.dart @@ -1,4 +1,3 @@ - import 'package:stormberry/stormberry.dart'; import 'account.dart'; @@ -18,4 +17,4 @@ abstract class Invoice { @HiddenIn(#Owner) Company? get company; -} \ No newline at end of file +} diff --git a/example/lib/models/invoice.schema.dart b/example/lib/models/invoice.schema.dart index b0334f4..a128c47 100644 --- a/example/lib/models/invoice.schema.dart +++ b/example/lib/models/invoice.schema.dart @@ -40,8 +40,8 @@ class _InvoiceRepository extends BaseRepository var values = QueryValues(); await db.query( - 'INSERT INTO "invoices" ( "account_id", "id", "title", "invoice_id", "company_id" )\n' - 'VALUES ${requests.map((r) => '( ${values.add(r.accountId)}, ${values.add(r.id)}, ${values.add(r.title)}, ${values.add(r.invoiceId)}, ${values.add(r.companyId)} )').join(', ')}\n', + 'INSERT INTO "invoices" ( "id", "title", "invoice_id", "account_id", "company_id" )\n' + 'VALUES ${requests.map((r) => '( ${values.add(r.id)}, ${values.add(r.title)}, ${values.add(r.invoiceId)}, ${values.add(r.accountId)}, ${values.add(r.companyId)} )').join(', ')}\n', values.values, ); } @@ -52,9 +52,9 @@ class _InvoiceRepository extends BaseRepository var values = QueryValues(); await db.query( 'UPDATE "invoices"\n' - 'SET "account_id" = COALESCE(UPDATED."account_id"::int8, "invoices"."account_id"), "title" = COALESCE(UPDATED."title"::text, "invoices"."title"), "invoice_id" = COALESCE(UPDATED."invoice_id"::text, "invoices"."invoice_id"), "company_id" = COALESCE(UPDATED."company_id"::text, "invoices"."company_id")\n' - 'FROM ( VALUES ${requests.map((r) => '( ${values.add(r.accountId)}, ${values.add(r.id)}, ${values.add(r.title)}, ${values.add(r.invoiceId)}, ${values.add(r.companyId)} )').join(', ')} )\n' - 'AS UPDATED("account_id", "id", "title", "invoice_id", "company_id")\n' + 'SET "title" = COALESCE(UPDATED."title"::text, "invoices"."title"), "invoice_id" = COALESCE(UPDATED."invoice_id"::text, "invoices"."invoice_id"), "account_id" = COALESCE(UPDATED."account_id"::int8, "invoices"."account_id"), "company_id" = COALESCE(UPDATED."company_id"::text, "invoices"."company_id")\n' + 'FROM ( VALUES ${requests.map((r) => '( ${values.add(r.id)}, ${values.add(r.title)}, ${values.add(r.invoiceId)}, ${values.add(r.accountId)}, ${values.add(r.companyId)} )').join(', ')} )\n' + 'AS UPDATED("id", "title", "invoice_id", "account_id", "company_id")\n' 'WHERE "invoices"."id" = UPDATED."id"', values.values, ); @@ -63,33 +63,33 @@ class _InvoiceRepository extends BaseRepository class InvoiceInsertRequest { InvoiceInsertRequest({ - this.accountId, required this.id, required this.title, required this.invoiceId, + this.accountId, this.companyId, }); - int? accountId; String id; String title; String invoiceId; + int? accountId; String? companyId; } class InvoiceUpdateRequest { InvoiceUpdateRequest({ - this.accountId, required this.id, this.title, this.invoiceId, + this.accountId, this.companyId, }); - int? accountId; String id; String? title; String? invoiceId; + int? accountId; String? companyId; } diff --git a/example/lib/models/latlng.dart b/example/lib/models/latlng.dart index 81afc01..59c38db 100644 --- a/example/lib/models/latlng.dart +++ b/example/lib/models/latlng.dart @@ -1,4 +1,3 @@ - import 'package:stormberry/stormberry.dart'; class LatLng { diff --git a/example/lib/models/party.schema.dart b/example/lib/models/party.schema.dart index a8243e9..1ec07c1 100644 --- a/example/lib/models/party.schema.dart +++ b/example/lib/models/party.schema.dart @@ -52,8 +52,8 @@ class _PartyRepository extends BaseRepository var values = QueryValues(); await db.query( - 'INSERT INTO "parties" ( "sponsor_id", "id", "name", "date" )\n' - 'VALUES ${requests.map((r) => '( ${values.add(r.sponsorId)}, ${values.add(r.id)}, ${values.add(r.name)}, ${values.add(r.date)} )').join(', ')}\n', + 'INSERT INTO "parties" ( "id", "name", "sponsor_id", "date" )\n' + 'VALUES ${requests.map((r) => '( ${values.add(r.id)}, ${values.add(r.name)}, ${values.add(r.sponsorId)}, ${values.add(r.date)} )').join(', ')}\n', values.values, ); } @@ -64,9 +64,9 @@ class _PartyRepository extends BaseRepository var values = QueryValues(); await db.query( 'UPDATE "parties"\n' - 'SET "sponsor_id" = COALESCE(UPDATED."sponsor_id"::text, "parties"."sponsor_id"), "name" = COALESCE(UPDATED."name"::text, "parties"."name"), "date" = COALESCE(UPDATED."date"::int8, "parties"."date")\n' - 'FROM ( VALUES ${requests.map((r) => '( ${values.add(r.sponsorId)}, ${values.add(r.id)}, ${values.add(r.name)}, ${values.add(r.date)} )').join(', ')} )\n' - 'AS UPDATED("sponsor_id", "id", "name", "date")\n' + 'SET "name" = COALESCE(UPDATED."name"::text, "parties"."name"), "sponsor_id" = COALESCE(UPDATED."sponsor_id"::text, "parties"."sponsor_id"), "date" = COALESCE(UPDATED."date"::int8, "parties"."date")\n' + 'FROM ( VALUES ${requests.map((r) => '( ${values.add(r.id)}, ${values.add(r.name)}, ${values.add(r.sponsorId)}, ${values.add(r.date)} )').join(', ')} )\n' + 'AS UPDATED("id", "name", "sponsor_id", "date")\n' 'WHERE "parties"."id" = UPDATED."id"', values.values, ); @@ -75,29 +75,29 @@ class _PartyRepository extends BaseRepository class PartyInsertRequest { PartyInsertRequest({ - this.sponsorId, required this.id, required this.name, + this.sponsorId, required this.date, }); - String? sponsorId; String id; String name; + String? sponsorId; int date; } class PartyUpdateRequest { PartyUpdateRequest({ - this.sponsorId, required this.id, this.name, + this.sponsorId, this.date, }); - String? sponsorId; String id; String? name; + String? sponsorId; int? date; } @@ -119,23 +119,23 @@ class GuestPartyViewQueryable extends KeyedViewQueryable @override GuestPartyView decode(TypedMap map) => GuestPartyView( + id: map.get('id'), + name: map.get('name'), sponsor: map.getOpt('sponsor', MemberCompanyViewQueryable().decoder), - id: map.get('id', TextEncoder.i.decode), - name: map.get('name', TextEncoder.i.decode), - date: map.get('date', TextEncoder.i.decode)); + date: map.get('date')); } class GuestPartyView { GuestPartyView({ - this.sponsor, required this.id, required this.name, + this.sponsor, required this.date, }); - final MemberCompanyView? sponsor; final String id; final String name; + final MemberCompanyView? sponsor; final int date; } diff --git a/lib/builder.dart b/lib/builder.dart index 0be7867..2c0514d 100644 --- a/lib/builder.dart +++ b/lib/builder.dart @@ -1,4 +1,3 @@ - import 'package:build/build.dart'; import 'src/builder/builders/runner_builder.dart'; @@ -11,4 +10,4 @@ Builder analyzeSchema(BuilderOptions options) => AnalyzingBuilder(options); Builder buildSchema(BuilderOptions options) => SchemaBuilder(options); -Builder buildRunner(BuilderOptions options) => RunnerBuilder(options); \ No newline at end of file +Builder buildRunner(BuilderOptions options) => RunnerBuilder(options); diff --git a/lib/src/builder/builders/analyzing_builder.dart b/lib/src/builder/builders/analyzing_builder.dart index 9f13586..13e4158 100644 --- a/lib/src/builder/builders/analyzing_builder.dart +++ b/lib/src/builder/builders/analyzing_builder.dart @@ -7,7 +7,6 @@ import '../elements/table_element.dart'; import '../schema.dart'; import '../utils.dart'; - /// The main builder used for code generation class AnalyzingBuilder implements Builder { /// The global options defined in the 'build.yaml' file @@ -30,7 +29,9 @@ class AnalyzingBuilder implements Builder { } @override - Map> get buildExtensions => const {'.dart': ['___']}; + Map> get buildExtensions => const { + '.dart': ['___'] + }; Future analyze(LibraryElement library, BuildStep buildStep) async { SchemaState schema = await buildStep.fetchResource(schemaResource); @@ -52,4 +53,3 @@ class AnalyzingBuilder implements Builder { } } } - diff --git a/lib/src/builder/builders/output_builder.dart b/lib/src/builder/builders/output_builder.dart index 63b5500..2fd4eab 100644 --- a/lib/src/builder/builders/output_builder.dart +++ b/lib/src/builder/builders/output_builder.dart @@ -5,7 +5,8 @@ import '../schema.dart'; import '../utils.dart'; abstract class OutputBuilder implements Builder { - OutputBuilder(this.target, BuilderOptions options) : options = GlobalOptions.parse(options.config); + OutputBuilder(this.target, BuilderOptions options) + : options = GlobalOptions.parse(options.config); final String target; final GlobalOptions options; diff --git a/lib/src/builder/builders/schema_builder.dart b/lib/src/builder/builders/schema_builder.dart index 5f201b7..68798a1 100644 --- a/lib/src/builder/builders/schema_builder.dart +++ b/lib/src/builder/builders/schema_builder.dart @@ -1,4 +1,3 @@ - import 'package:build/build.dart'; import 'package:path/path.dart' as path; import '../generators/repository_generator.dart'; diff --git a/lib/src/builder/elements/column/column_element.dart b/lib/src/builder/elements/column/column_element.dart index f691460..3821f3a 100644 --- a/lib/src/builder/elements/column/column_element.dart +++ b/lib/src/builder/elements/column/column_element.dart @@ -25,7 +25,8 @@ abstract class RelationalColumnElement implements ColumnElement { @override void checkModifiers() { - var groupedModifiers = modifiers.groupListsBy((m) => Object.hash(m.read('name').objectValue.toSymbolValue(), m.objectValue.type)); + var groupedModifiers = modifiers.groupListsBy( + (m) => Object.hash(m.read('name').objectValue.toSymbolValue(), m.objectValue.type)); if (groupedModifiers.values.any((l) => l.length > 1)) { var duplicated = groupedModifiers.values.where((l) => l.length > 1).first; throw 'Column field was annotated with duplicate view modifiers, which is not supported.\n' diff --git a/lib/src/builder/elements/column/field_column_element.dart b/lib/src/builder/elements/column/field_column_element.dart index 1377c79..3efcd5c 100644 --- a/lib/src/builder/elements/column/field_column_element.dart +++ b/lib/src/builder/elements/column/field_column_element.dart @@ -15,15 +15,15 @@ class FieldColumnElement extends ColumnElement with NamedColumnElement { late final bool isAutoIncrement; - FieldColumnElement(this.parameter, TableElement parentTable, BuilderState state) : super(parentTable, state) { + FieldColumnElement(this.parameter, TableElement parentTable, BuilderState state) + : super(parentTable, state) { isAutoIncrement = (autoIncrementChecker.firstAnnotationOf(parameter) ?? - autoIncrementChecker.firstAnnotationOf(parameter.getter ?? parameter)) != + autoIncrementChecker.firstAnnotationOf(parameter.getter ?? parameter)) != null; if (isAutoIncrement && !parameter.type.isDartCoreInt) { throw 'The following field is annotated with @AutoIncrement() but has an unallowed type:\n' - ' - "${parameter.getDisplayString(withNullability: true)}" in class "${parentTable.element - .getDisplayString(withNullability: true)}"\n' + ' - "${parameter.getDisplayString(withNullability: true)}" in class "${parentTable.element.getDisplayString(withNullability: true)}"\n' 'A field annotated with @AutoIncrement() must be of type int.'; } } @@ -46,7 +46,8 @@ class FieldColumnElement extends ColumnElement with NamedColumnElement { @override void checkModifiers() { if (modifiers.isNotEmpty) { - print('Column field was annotated with "${modifiers.first.toSource()}", which is not supported.\n' + print( + 'Column field was annotated with "${modifiers.first.toSource()}", which is not supported.\n' ' - ${parameter.getDisplayString(withNullability: true)}'); } } diff --git a/lib/src/builder/elements/column/foreign_column_element.dart b/lib/src/builder/elements/column/foreign_column_element.dart index 8455fe8..f92dccf 100644 --- a/lib/src/builder/elements/column/foreign_column_element.dart +++ b/lib/src/builder/elements/column/foreign_column_element.dart @@ -6,7 +6,8 @@ import '../../schema.dart'; import '../table_element.dart'; import 'column_element.dart'; -class ForeignColumnElement extends ColumnElement with RelationalColumnElement, ReferencingColumnElement, NamedColumnElement { +class ForeignColumnElement extends ColumnElement + with RelationalColumnElement, ReferencingColumnElement, NamedColumnElement { @override final FieldElement? parameter; @override @@ -15,7 +16,8 @@ class ForeignColumnElement extends ColumnElement with RelationalColumnElement, R @override late ReferencingColumnElement referencedColumn; - ForeignColumnElement(this.parameter, this.linkedTable, TableElement parentTable, BuilderState state) + ForeignColumnElement( + this.parameter, this.linkedTable, TableElement parentTable, BuilderState state) : super(parentTable, state); @override diff --git a/lib/src/builder/elements/column/join_column_element.dart b/lib/src/builder/elements/column/join_column_element.dart index 2371c25..7987d05 100644 --- a/lib/src/builder/elements/column/join_column_element.dart +++ b/lib/src/builder/elements/column/join_column_element.dart @@ -14,7 +14,8 @@ class JoinColumnElement extends ColumnElement with RelationalColumnElement, Link late JoinColumnElement referencedColumn; - JoinColumnElement(this.parameter, this.linkedTable, this.joinTable, TableElement parentBuilder, BuilderState state) + JoinColumnElement(this.parameter, this.linkedTable, this.joinTable, TableElement parentBuilder, + BuilderState state) : super(parentBuilder, state) { if (converter != null) { print('Relational field was annotated with @UseConverter(...), which is not supported.\n' diff --git a/lib/src/builder/elements/column/reference_column_element.dart b/lib/src/builder/elements/column/reference_column_element.dart index d3f8812..ce9ac2b 100644 --- a/lib/src/builder/elements/column/reference_column_element.dart +++ b/lib/src/builder/elements/column/reference_column_element.dart @@ -6,7 +6,8 @@ import '../table_element.dart'; import 'column_element.dart'; import 'foreign_column_element.dart'; -class ReferenceColumnElement extends ColumnElement with RelationalColumnElement, ReferencingColumnElement { +class ReferenceColumnElement extends ColumnElement + with RelationalColumnElement, ReferencingColumnElement { @override final FieldElement? parameter; @override @@ -15,7 +16,8 @@ class ReferenceColumnElement extends ColumnElement with RelationalColumnElement, @override covariant late ForeignColumnElement referencedColumn; - ReferenceColumnElement(this.parameter, this.linkedTable, TableElement parentTable, BuilderState state) + ReferenceColumnElement( + this.parameter, this.linkedTable, TableElement parentTable, BuilderState state) : super(parentTable, state); @override diff --git a/lib/src/builder/elements/index_element.dart b/lib/src/builder/elements/index_element.dart index 9f8eeb9..9f431a8 100644 --- a/lib/src/builder/elements/index_element.dart +++ b/lib/src/builder/elements/index_element.dart @@ -11,7 +11,8 @@ class IndexElement { Map toMap() { return { 'name': annotation.getField('name')?.toStringValue(), - 'columns': annotation.getField('columns')?.toListValue()?.map((o) => o.toStringValue()).toList(), + 'columns': + annotation.getField('columns')?.toListValue()?.map((o) => o.toStringValue()).toList(), 'unique': annotation.getField('unique')?.toBoolValue(), 'algorithm': annotation.getField('algorithm')?.getField('index')?.toIntValue(), 'condition': annotation.getField('condition')?.toStringValue(), diff --git a/lib/src/builder/elements/table_element.dart b/lib/src/builder/elements/table_element.dart index 1665953..a27691d 100644 --- a/lib/src/builder/elements/table_element.dart +++ b/lib/src/builder/elements/table_element.dart @@ -37,7 +37,9 @@ class TableElement { repoName = _getRepoName(); primaryKeyParameter = element.fields - .where((p) => primaryKeyChecker.hasAnnotationOf(p) || primaryKeyChecker.hasAnnotationOf(p.getter ?? p)) + .where((p) => + primaryKeyChecker.hasAnnotationOf(p) || + primaryKeyChecker.hasAnnotationOf(p.getter ?? p)) .firstOrNull; views = {}; @@ -85,7 +87,10 @@ class TableElement { List columns = []; FieldColumnElement? get primaryKeyColumn => primaryKeyParameter != null - ? columns.whereType().where((c) => c.parameter == primaryKeyParameter).firstOrNull + ? columns + .whereType() + .where((c) => c.parameter == primaryKeyParameter) + .firstOrNull : null; late List allFields = element.fields @@ -111,7 +116,8 @@ class TableElement { var otherParam = otherBuilder.findMatchingParam(param); var selfIsList = param.type.isDartCoreList; - var otherIsList = otherParam != null ? otherParam.type.isDartCoreList : otherHasKey && !selfIsList; + var otherIsList = + otherParam != null ? otherParam.type.isDartCoreList : otherHasKey && !selfIsList; if (!selfHasKey && !otherHasKey) { throw 'Model ${otherBuilder.element.name} cannot have a relation to model ${element.name} because neither model' diff --git a/lib/src/builder/elements/view_element.dart b/lib/src/builder/elements/view_element.dart index f5f7333..79265f9 100644 --- a/lib/src/builder/elements/view_element.dart +++ b/lib/src/builder/elements/view_element.dart @@ -24,7 +24,8 @@ class ViewColumn { var c = column; if (c is LinkedColumnElement) { if (viewAs != null) { - return c.linkedTable.views.values.firstWhere((v) => v.name.toLowerCase() == viewAs!.toLowerCase()); + return c.linkedTable.views.values + .firstWhere((v) => v.name.toLowerCase() == viewAs!.toLowerCase()); } else { return c.linkedTable.views.values.firstWhere((v) => v.isDefaultView); } @@ -58,12 +59,13 @@ class ViewElement { bool get isDefaultView => name.isEmpty; - String get className => - CaseStyle.pascalCase.transform('${!isDefaultView ? '${name}_' : ''}${table.element.name}_view'); + String get className => CaseStyle.pascalCase + .transform('${!isDefaultView ? '${name}_' : ''}${table.element.name}_view'); String get entityName => isDefaultView ? table.element.name : className; - String get viewName => CaseStyle.pascalCase.transform(isDefaultView ? entityName : '${name}_view'); + String get viewName => + CaseStyle.pascalCase.transform(isDefaultView ? entityName : '${name}_view'); String get viewTableName => CaseStyle.snakeCase.transform('${!isDefaultView ? '${name}_' : ''}${table.tableName}_view'); @@ -76,15 +78,20 @@ class ViewElement { continue; } - var modifiers = column.modifiers - .where((m) => m.read('name').objectValue.toSymbolValue()!.toLowerCase() == name.toLowerCase()); + var modifiers = column.modifiers.where( + (m) => m.read('name').objectValue.toSymbolValue()!.toLowerCase() == name.toLowerCase()); if (modifiers.isNotEmpty) { var isHidden = modifiers.any((m) => m.instanceOf(hiddenInChecker)); if (isHidden) { continue; } - var viewAs = modifiers.where((m) => m.instanceOf(viewedInChecker)).firstOrNull?.read('as').objectValue.toSymbolValue(); + var viewAs = modifiers + .where((m) => m.instanceOf(viewedInChecker)) + .firstOrNull + ?.read('as') + .objectValue + .toSymbolValue(); if (viewAs == null && column is LinkedColumnElement) { if (!column.linkedTable.views.values.any((v) => v.isDefaultView)) { @@ -92,7 +99,8 @@ class ViewElement { } } - var transformer = modifiers.where((m) => m.instanceOf(transformedInChecker)).firstOrNull?.read('by'); + var transformer = + modifiers.where((m) => m.instanceOf(transformedInChecker)).firstOrNull?.read('by'); String? transformerCode; if (transformer != null && !transformer.isNull) { diff --git a/lib/src/builder/generators/insert_generator.dart b/lib/src/builder/generators/insert_generator.dart index 6001a38..0133f05 100644 --- a/lib/src/builder/generators/insert_generator.dart +++ b/lib/src/builder/generators/insert_generator.dart @@ -9,8 +9,9 @@ class InsertGenerator { String generateInsertMethod(TableElement table) { var deepInserts = []; - for (var column - in table.columns.whereType().where((c) => c.linkedTable.primaryKeyColumn == null)) { + for (var column in table.columns + .whereType() + .where((c) => c.linkedTable.primaryKeyColumn == null)) { if (column.linkedTable.columns .where((c) => c is ForeignColumnElement && c.linkedTable != table && !c.isNullable) .isNotEmpty) { @@ -69,7 +70,8 @@ class InsertGenerator { } } - var autoIncrementCols = table.columns.whereType().where((c) => c.isAutoIncrement); + var autoIncrementCols = + table.columns.whereType().where((c) => c.isAutoIncrement); String? autoIncrementStatement, keyReturnStatement; if (autoIncrementCols.isNotEmpty) { @@ -123,7 +125,8 @@ class InsertGenerator { for (var column in table.columns) { if (column is FieldColumnElement) { if (!column.isAutoIncrement) { - requestFields.add(MapEntry(column.parameter.type.getDisplayString(withNullability: true), column.paramName)); + requestFields.add(MapEntry( + column.parameter.type.getDisplayString(withNullability: true), column.paramName)); } } else if (column is ReferenceColumnElement && column.linkedTable.primaryKeyColumn == null) { if (column.linkedTable.columns @@ -131,7 +134,8 @@ class InsertGenerator { .isNotEmpty) { continue; } - requestFields.add(MapEntry(column.parameter!.type.getDisplayString(withNullability: true), column.paramName)); + requestFields.add(MapEntry( + column.parameter!.type.getDisplayString(withNullability: true), column.paramName)); } else if (column is ForeignColumnElement) { var fieldNullSuffix = column.isNullable ? '?' : ''; String fieldType; @@ -147,8 +151,9 @@ class InsertGenerator { } } - var constructorParameters = - requestFields.map((f) => '${f.key.endsWith('?') ? '' : 'required '}this.${f.value},').join(' '); + var constructorParameters = requestFields + .map((f) => '${f.key.endsWith('?') ? '' : 'required '}this.${f.value},') + .join(' '); return ''' ${table.annotateWith ?? ''} diff --git a/lib/src/builder/generators/table_json_generator.dart b/lib/src/builder/generators/table_json_generator.dart index 7718244..cab1f85 100644 --- a/lib/src/builder/generators/table_json_generator.dart +++ b/lib/src/builder/generators/table_json_generator.dart @@ -24,7 +24,8 @@ class TableJsonGenerator { { 'type': 'foreign_key', 'column': column.columnName, - 'target': '${column.linkedTable.tableName}.${column.linkedTable.primaryKeyColumn!.columnName}', + 'target': + '${column.linkedTable.tableName}.${column.linkedTable.primaryKeyColumn!.columnName}', 'on_delete': table.primaryKeyColumn != null ? 'set_null' : 'cascade', 'on_update': 'cascade', }, diff --git a/lib/src/builder/generators/update_generator.dart b/lib/src/builder/generators/update_generator.dart index 786bc57..70234f0 100644 --- a/lib/src/builder/generators/update_generator.dart +++ b/lib/src/builder/generators/update_generator.dart @@ -9,8 +9,9 @@ class UpdateGenerator { String generateUpdateMethod(TableElement table) { var deepUpdates = []; - for (var column - in table.columns.whereType().where((c) => c.linkedTable.primaryKeyColumn == null)) { + for (var column in table.columns + .whereType() + .where((c) => c.linkedTable.primaryKeyColumn == null)) { if (column.linkedTable.columns .where((c) => c is ForeignColumnElement && c.linkedTable != table && !c.isNullable) .isNotEmpty) { @@ -63,9 +64,8 @@ class UpdateGenerator { (hasPrimaryKey ? c != table.primaryKeyColumn : c is FieldColumnElement) && (c is! FieldColumnElement || !c.isAutoIncrement)); - var updateColumns = table.columns - .whereType() - .where((c) => table.primaryKeyColumn == c || c is! FieldColumnElement || !c.isAutoIncrement); + var updateColumns = table.columns.whereType().where( + (c) => table.primaryKeyColumn == c || c is! FieldColumnElement || !c.isAutoIncrement); String toUpdateValue(NamedColumnElement c) { if (c.converter != null) { @@ -143,8 +143,9 @@ class UpdateGenerator { } } - final constructorParameters = - requestFields.map((f) => '${f.key.endsWith('?') ? '' : 'required '}this.${f.value},').join(' '); + final constructorParameters = requestFields + .map((f) => '${f.key.endsWith('?') ? '' : 'required '}this.${f.value},') + .join(' '); return ''' ${table.annotateWith ?? ''} diff --git a/lib/src/builder/generators/view_generator.dart b/lib/src/builder/generators/view_generator.dart index df28589..dbe2423 100644 --- a/lib/src/builder/generators/view_generator.dart +++ b/lib/src/builder/generators/view_generator.dart @@ -27,11 +27,13 @@ class ViewGenerator { } } - var signature = 'Future> query$viewName${viewName.endsWith('s') ? 'e' : ''}s([QueryParams? params])'; + var signature = + 'Future> query$viewName${viewName.endsWith('s') ? 'e' : ''}s([QueryParams? params])'; if (abstract) { str.writeln('$signature;'); } else { - str.writeln('@override $signature {\nreturn queryMany(${view.entityName}Queryable(), params);\n}'); + str.writeln( + '@override $signature {\nreturn queryMany(${view.entityName}Queryable(), params);\n}'); } } diff --git a/lib/src/builder/generators/view_query_generator.dart b/lib/src/builder/generators/view_query_generator.dart index 93f3148..d6dcc1b 100644 --- a/lib/src/builder/generators/view_query_generator.dart +++ b/lib/src/builder/generators/view_query_generator.dart @@ -18,7 +18,8 @@ String buildViewQuery(ViewElement view) { for (var viewColumn in columns) { String? transform; if (viewColumn.transformer != null) { - transform = '\${${viewColumn.transformer!}.transform(\'${viewColumn.paramName}\', \'$tableName\')}'; + transform = + '\${${viewColumn.transformer!}.transform(\'${viewColumn.paramName}\', \'$tableName\')}'; } var column = viewColumn.column; @@ -42,18 +43,18 @@ String buildViewQuery(ViewElement view) { joins.add(MapEntry( transform ?? 'row_to_json("${column.parameter!.name}".*) as "${column.parameter!.name}"', 'LEFT JOIN $tableReference "${column.parameter!.name}"\n' - 'ON "$tableName"."$primaryKeyName" = "${column.parameter!.name}"."${column.referencedColumn.columnName}"', + 'ON "$tableName"."$primaryKeyName" = "${column.parameter!.name}"."${column.referencedColumn.columnName}"', )); } else { joins.add(MapEntry( transform ?? '"${column.parameter!.name}"."data" as "${column.parameter!.name}"', 'LEFT JOIN (\n' - ' SELECT "${column.linkedTable.tableName}"."${column.referencedColumn.columnName}",\n' - ' to_jsonb(array_agg("${column.linkedTable.tableName}".*)) as data\n' - ' FROM $tableReference "${column.linkedTable.tableName}"\n' - ' GROUP BY "${column.linkedTable.tableName}"."${column.referencedColumn.columnName}"\n' - ') "${column.parameter!.name}"\n' - 'ON "$tableName"."$primaryKeyName" = "${column.parameter!.name}"."${column.referencedColumn.columnName}"', + ' SELECT "${column.linkedTable.tableName}"."${column.referencedColumn.columnName}",\n' + ' to_jsonb(array_agg("${column.linkedTable.tableName}".*)) as data\n' + ' FROM $tableReference "${column.linkedTable.tableName}"\n' + ' GROUP BY "${column.linkedTable.tableName}"."${column.referencedColumn.columnName}"\n' + ') "${column.parameter!.name}"\n' + 'ON "$tableName"."$primaryKeyName" = "${column.parameter!.name}"."${column.referencedColumn.columnName}"', )); } } else if (column is JoinColumnElement) { diff --git a/lib/src/builder/schema.dart b/lib/src/builder/schema.dart index 0743f96..f78f965 100644 --- a/lib/src/builder/schema.dart +++ b/lib/src/builder/schema.dart @@ -12,7 +12,8 @@ class SchemaState { final Map _assets = {}; bool _didFinalize = false; - Map get tables => _assets.values.map((a) => a.tables).reduce((a, b) => {...a, ...b}); + Map get tables => + _assets.values.map((a) => a.tables).reduce((a, b) => {...a, ...b}); Map get joinTables => _assets.values.map((a) => a.joinTables).reduce((a, b) => {...a, ...b}); diff --git a/lib/src/builder/utils.dart b/lib/src/builder/utils.dart index 132fbfb..3011acc 100644 --- a/lib/src/builder/utils.dart +++ b/lib/src/builder/utils.dart @@ -22,11 +22,13 @@ class GlobalOptions { int lineLength; GlobalOptions.parse(Map options) - : tableCaseStyle = CaseStyle.fromString( - options['tableCaseStyle'] as String? ?? options['table_case_style'] as String? ?? 'snakeCase'), - columnCaseStyle = CaseStyle.fromString( - options['columnCaseStyle'] as String? ?? options['column_case_style'] as String? ?? 'snakeCase'), - lineLength = options['lineLength'] as int? ?? options['line_length'] as int? ?? 120; + : tableCaseStyle = CaseStyle.fromString(options['tableCaseStyle'] as String? ?? + options['table_case_style'] as String? ?? + 'snakeCase'), + columnCaseStyle = CaseStyle.fromString(options['columnCaseStyle'] as String? ?? + options['column_case_style'] as String? ?? + 'snakeCase'), + lineLength = options['lineLength'] as int? ?? options['line_length'] as int? ?? 100; } extension GetNode on Element { @@ -60,8 +62,9 @@ String? getAnnotationCode(Element annotatedElement, Type annotationType, String for (var annotation in annotations) { if (annotation.name.name == annotationType.toString()) { - var props = - annotation.arguments!.arguments.whereType().where((e) => e.name.label.name == property); + var props = annotation.arguments!.arguments + .whereType() + .where((e) => e.name.label.name == property); if (props.isNotEmpty) { return props.first.expression.toSource(); @@ -154,7 +157,8 @@ String writeImports(Set imports, AssetId input) { package.sort(); relative.sort(); - String joined(List s) => s.isNotEmpty ? '${s.map((s) => "import '$s';").join('\n')}\n\n' : ''; + String joined(List s) => + s.isNotEmpty ? '${s.map((s) => "import '$s';").join('\n')}\n\n' : ''; return joined(sdk) + joined(package) + joined(relative); } diff --git a/lib/src/cli/migration/differentiator.dart b/lib/src/cli/migration/differentiator.dart index 01a2b9e..7f9575c 100644 --- a/lib/src/cli/migration/differentiator.dart +++ b/lib/src/cli/migration/differentiator.dart @@ -84,8 +84,10 @@ void printDiff(DatabaseSchemaDiff diff) { for (var column in table.columns.modified) { var prev = column.prev; var newly = column.newly; - print("- COLUMN ${table.name}.${prev.name} ${prev.type} ${prev.isNullable ? 'NULL' : 'NOT NULL'}"); - print("+ COLUMN ${table.name}.${newly.name} ${newly.type} ${newly.isNullable ? 'NULL' : 'NOT NULL'}"); + print( + "- COLUMN ${table.name}.${prev.name} ${prev.type} ${prev.isNullable ? 'NULL' : 'NOT NULL'}"); + print( + "+ COLUMN ${table.name}.${newly.name} ${newly.type} ${newly.isNullable ? 'NULL' : 'NOT NULL'}"); } for (var column in table.columns.removed) { @@ -93,11 +95,13 @@ void printDiff(DatabaseSchemaDiff diff) { } for (var constr in table.constraints.added) { - print("++ CONSTRAINT ON ${table.name} ${constr.toString().replaceAll(RegExp("[\n\\s]+"), " ")}"); + print( + "++ CONSTRAINT ON ${table.name} ${constr.toString().replaceAll(RegExp("[\n\\s]+"), " ")}"); } for (var constr in table.constraints.removed) { - print("-- CONSTRAINT ON ${table.name} ${constr.toString().replaceAll(RegExp("[\n\\s]+"), " ")}"); + print( + "-- CONSTRAINT ON ${table.name} ${constr.toString().replaceAll(RegExp("[\n\\s]+"), " ")}"); } for (var index in table.indexes.added) { @@ -142,7 +146,9 @@ class Diff { List removed = []; bool hasChanges([bool Function(U modified)? fn]) { - return added.isNotEmpty || removed.isNotEmpty || (fn != null ? modified.any(fn) : modified.isNotEmpty); + return added.isNotEmpty || + removed.isNotEmpty || + (fn != null ? modified.any(fn) : modified.isNotEmpty); } } diff --git a/lib/src/cli/migration/inspector.dart b/lib/src/cli/migration/inspector.dart index 23ef740..7ae50e7 100644 --- a/lib/src/cli/migration/inspector.dart +++ b/lib/src/cli/migration/inspector.dart @@ -6,8 +6,8 @@ Future inspectDatabaseSchema(Database db) async { //ignore: prefer_const_constructors var schema = DatabaseSchema({}); - var tables = await db - .query("SELECT * FROM information_schema.tables WHERE table_schema = 'public' AND table_type = 'BASE TABLE'"); + var tables = await db.query( + "SELECT * FROM information_schema.tables WHERE table_schema = 'public' AND table_type = 'BASE TABLE'"); for (var row in tables) { var tableMap = row.toColumnMap(); var tableName = tableMap['table_name'] as String; @@ -15,13 +15,15 @@ Future inspectDatabaseSchema(Database db) async { var tableScheme = TableSchema(tableName, columns: {}, constraints: [], indexes: []); schema.tables[tableName] = tableScheme; - var columns = await db.query("SELECT * FROM information_schema.columns WHERE table_name = '$tableName'"); + var columns = + await db.query("SELECT * FROM information_schema.columns WHERE table_name = '$tableName'"); for (var row in columns) { var columnMap = row.toColumnMap(); var columnName = columnMap['column_name'] as String; var columnType = columnMap['udt_name'] as String; var columnIsNullable = columnMap['is_nullable']; - var columnIsAutoIncrement = (columnMap['column_default'] as String?)?.startsWith('nextval') ?? false; + var columnIsAutoIncrement = + (columnMap['column_default'] as String?)?.startsWith('nextval') ?? false; tableScheme.columns[columnName] = ColumnSchema( columnName, type: columnIsAutoIncrement && columnType == 'int8' ? 'serial' : columnType, @@ -68,8 +70,12 @@ Future inspectDatabaseSchema(Database db) async { srcColumns[0] as String, constraintMap['target_table'] as String, targetColumns[0] as String, - constraintMap['delete_rule'] == 'CASCADE' ? ForeignKeyAction.cascade : ForeignKeyAction.setNull, - constraintMap['update_rule'] == 'CASCADE' ? ForeignKeyAction.cascade : ForeignKeyAction.setNull, + constraintMap['delete_rule'] == 'CASCADE' + ? ForeignKeyAction.cascade + : ForeignKeyAction.setNull, + constraintMap['update_rule'] == 'CASCADE' + ? ForeignKeyAction.cascade + : ForeignKeyAction.setNull, ); } if (constraint != null) { @@ -85,7 +91,8 @@ Future inspectDatabaseSchema(Database db) async { var indexMap = row.toColumnMap(); var indexName = (indexMap['indexname'] as String).substring(2); var tableName = indexMap['tablename']; - var defRegex = RegExp(r'^CREATE( UNIQUE)? INDEX \w+ ON public.\w+ USING (\w+) \((\w+)\)(?: WHERE (.+))?$'); + var defRegex = + RegExp(r'^CREATE( UNIQUE)? INDEX \w+ ON public.\w+ USING (\w+) \((\w+)\)(?: WHERE (.+))?$'); var defMatch = defRegex.firstMatch(indexMap['indexdef'] as String); if (defMatch == null || defMatch.groupCount != 4) continue; var unique = defMatch.group(1) != null; diff --git a/lib/src/cli/migration/output.dart b/lib/src/cli/migration/output.dart index f3b2c6f..cf0e392 100644 --- a/lib/src/cli/migration/output.dart +++ b/lib/src/cli/migration/output.dart @@ -68,7 +68,8 @@ Future outputSchema(Directory dir, DatabaseSchemaDiff diff) async { }), ]; - for (var c in table.columns.modified.where((c) => c.prev.type != 'serial' && c.newly.type == 'serial')) { + for (var c in table.columns.modified + .where((c) => c.prev.type != 'serial' && c.newly.type == 'serial')) { appendStatement('CREATE SEQUENCE IF NOT EXISTS ${table.name}_${c.newly.name}_seq ' 'OWNED BY "public"."${table.name}"."${c.newly.name}";'); } @@ -79,8 +80,9 @@ Future outputSchema(Directory dir, DatabaseSchemaDiff diff) async { } for (var table in diff.tables.modified) { - var uniqueConstraints = - table.constraints.added.where((c) => c is PrimaryKeyConstraint || c is UniqueConstraint).toList(); + var uniqueConstraints = table.constraints.added + .where((c) => c is PrimaryKeyConstraint || c is UniqueConstraint) + .toList(); if (uniqueConstraints.isNotEmpty) { appendStatement('ALTER TABLE "${table.name}"\n' ' ${uniqueConstraints.map((c) => 'ADD ${c.toString()}').join(",\n ")};'); @@ -88,7 +90,8 @@ Future outputSchema(Directory dir, DatabaseSchemaDiff diff) async { } for (var table in diff.tables.added) { - var uniqueConstraints = table.constraints.where((c) => c is PrimaryKeyConstraint || c is UniqueConstraint).toList(); + var uniqueConstraints = + table.constraints.where((c) => c is PrimaryKeyConstraint || c is UniqueConstraint).toList(); if (uniqueConstraints.isNotEmpty) { appendStatement('ALTER TABLE "${table.name}"\n' ' ${uniqueConstraints.map((c) => 'ADD ${c.toString()}').join(",\n ")};'); diff --git a/lib/src/cli/migration/patcher.dart b/lib/src/cli/migration/patcher.dart index 5639a54..7c38793 100644 --- a/lib/src/cli/migration/patcher.dart +++ b/lib/src/cli/migration/patcher.dart @@ -44,7 +44,8 @@ Future patchSchema(Database db, DatabaseSchemaDiff diff) async { }), ]; - for (var c in table.columns.modified.where((c) => c.prev.type != 'serial' && c.newly.type == 'serial')) { + for (var c in table.columns.modified + .where((c) => c.prev.type != 'serial' && c.newly.type == 'serial')) { await db.query(''' CREATE SEQUENCE IF NOT EXISTS ${table.name}_${c.newly.name}_seq OWNED BY "public"."${table.name}"."${c.newly.name}"; '''); @@ -58,8 +59,9 @@ Future patchSchema(Database db, DatabaseSchemaDiff diff) async { } for (var table in diff.tables.modified) { - var uniqueConstraints = - table.constraints.added.where((c) => c is PrimaryKeyConstraint || c is UniqueConstraint).toList(); + var uniqueConstraints = table.constraints.added + .where((c) => c is PrimaryKeyConstraint || c is UniqueConstraint) + .toList(); if (uniqueConstraints.isNotEmpty) { await db.query(""" ALTER TABLE "${table.name}" @@ -69,7 +71,8 @@ Future patchSchema(Database db, DatabaseSchemaDiff diff) async { } for (var table in diff.tables.added) { - var uniqueConstraints = table.constraints.where((c) => c is PrimaryKeyConstraint || c is UniqueConstraint).toList(); + var uniqueConstraints = + table.constraints.where((c) => c is PrimaryKeyConstraint || c is UniqueConstraint).toList(); if (uniqueConstraints.isNotEmpty) { await db.query(""" ALTER TABLE "${table.name}" @@ -139,4 +142,4 @@ Future removeUnused(Database db, DatabaseSchemaDiff diff) async { for (var table in diff.tables.removed) { await db.query('DROP TABLE "${table.name}" CASCADE'); } -} \ No newline at end of file +} diff --git a/lib/src/cli/migration/schema.dart b/lib/src/cli/migration/schema.dart index 9400055..72ec764 100644 --- a/lib/src/cli/migration/schema.dart +++ b/lib/src/cli/migration/schema.dart @@ -19,11 +19,14 @@ class DatabaseSchema { key, columns: (table['columns'] as Map) .map((k, v) => MapEntry(k, ColumnSchema.fromMap(k, v as Map))), - constraints: - (table['constraints'] as List?)?.map((c) => TableConstraint.fromMap(c as Map)).toList() ?? - [], - indexes: - (table['indexes'] as List?)?.map((i) => TableIndexParser.fromMap(i as Map)).toList() ?? [], + constraints: (table['constraints'] as List?) + ?.map((c) => TableConstraint.fromMap(c as Map)) + .toList() ?? + [], + indexes: (table['indexes'] as List?) + ?.map((i) => TableIndexParser.fromMap(i as Map)) + .toList() ?? + [], ); } return DatabaseSchema(tables); @@ -75,7 +78,8 @@ class ColumnSchema { final bool isNullable; final bool isAutoIncrement; - const ColumnSchema(this.name, {required this.type, this.isNullable = false, bool? isAutoIncrement}) + const ColumnSchema(this.name, + {required this.type, this.isNullable = false, bool? isAutoIncrement}) : isAutoIncrement = isAutoIncrement ?? (type == 'serial'); factory ColumnSchema.fromMap(String name, Map map) { @@ -139,7 +143,8 @@ class ForeignKeyConstraint extends TableConstraint { final ForeignKeyAction onDelete; final ForeignKeyAction onUpdate; - const ForeignKeyConstraint(String? name, this.srcColumn, this.table, this.column, this.onDelete, this.onUpdate) + const ForeignKeyConstraint( + String? name, this.srcColumn, this.table, this.column, this.onDelete, this.onUpdate) : super(name); @override @@ -169,7 +174,8 @@ class ForeignKeyConstraint extends TableConstraint { onUpdate == other.onUpdate; @override - int get hashCode => name.hashCode ^ table.hashCode ^ column.hashCode ^ onDelete.hashCode ^ onUpdate.hashCode; + int get hashCode => + name.hashCode ^ table.hashCode ^ column.hashCode ^ onDelete.hashCode ^ onUpdate.hashCode; } class UniqueConstraint extends TableConstraint { @@ -183,7 +189,8 @@ class UniqueConstraint extends TableConstraint { @override bool operator ==(Object other) => - identical(this, other) || other is UniqueConstraint && runtimeType == other.runtimeType && column == other.column; + identical(this, other) || + other is UniqueConstraint && runtimeType == other.runtimeType && column == other.column; @override int get hashCode => name.hashCode; @@ -205,4 +212,4 @@ extension TableIndexParser on TableIndex { 'ON "$tableName" USING ${algorithm.toString().split(".")[1]} ( $joinedColumns ) ' '${condition != null ? 'WHERE $condition' : ''}'; } -} \ No newline at end of file +} diff --git a/lib/src/cli/runner.dart b/lib/src/cli/runner.dart index 1aae4a8..9208836 100644 --- a/lib/src/cli/runner.dart +++ b/lib/src/cli/runner.dart @@ -113,16 +113,21 @@ class MigrateCommand extends Command { exit(1); } - var dbName = resolveProperty(arg: 'db', env: 'DB_NAME', prompt: 'Select a database to update: '); - var dbHost = - resolveProperty(arg: 'host', env: 'DB_HOST_ADDRESS', prompt: 'Enter the database host address: '); - var dbPort = resolveProperty(arg: 'port', env: 'DB_PORT', prompt: 'Enter the database port: '); - var dbUser = resolveProperty(arg: 'username', env: 'DB_USERNAME', prompt: 'Enter the database username: '); + var dbName = + resolveProperty(arg: 'db', env: 'DB_NAME', prompt: 'Select a database to update: '); + var dbHost = resolveProperty( + arg: 'host', env: 'DB_HOST_ADDRESS', prompt: 'Enter the database host address: '); + var dbPort = + resolveProperty(arg: 'port', env: 'DB_PORT', prompt: 'Enter the database port: '); + var dbUser = resolveProperty( + arg: 'username', env: 'DB_USERNAME', prompt: 'Enter the database username: '); var dbPassword = resolveProperty( - arg: 'password', env: 'DB_PASSWORD', prompt: 'Enter the database password: ', obscureInput: true); + arg: 'password', + env: 'DB_PASSWORD', + prompt: 'Enter the database password: ', + obscureInput: true); var useSSL = resolveProperty(arg: 'ssl', env: 'DB_SSL'); - var isUnixSocket = - resolveProperty(arg: 'unix-socket', env: 'DB_SOCKET'); + var isUnixSocket = resolveProperty(arg: 'unix-socket', env: 'DB_SOCKET'); var db = Database( host: dbHost, @@ -250,8 +255,8 @@ class MigrateCommand extends Command { return input == 'yes' ? true as T : input == 'no' - ? false as T - : null; + ? false as T + : null; } } } diff --git a/lib/src/core/annotations.dart b/lib/src/core/annotations.dart index e4729bd..e88c786 100644 --- a/lib/src/core/annotations.dart +++ b/lib/src/core/annotations.dart @@ -92,7 +92,11 @@ class TableIndex { @override int get hashCode => - joinedColumns.hashCode ^ name.hashCode ^ unique.hashCode ^ algorithm.hashCode ^ condition.hashCode; + joinedColumns.hashCode ^ + name.hashCode ^ + unique.hashCode ^ + algorithm.hashCode ^ + condition.hashCode; } // ignore: constant_identifier_names diff --git a/lib/src/core/case_style.dart b/lib/src/core/case_style.dart index 03cbf76..d9cfe1e 100644 --- a/lib/src/core/case_style.dart +++ b/lib/src/core/case_style.dart @@ -67,7 +67,8 @@ class CaseStyle { static const unmodified = 'unmodified'; /// Transforms to 'fieldName' - static const camelCase = CaseStyle(head: TextTransform.lowerCase, tail: TextTransform.capitalCase); + static const camelCase = + CaseStyle(head: TextTransform.lowerCase, tail: TextTransform.capitalCase); /// Transforms to 'FieldName' static const pascalCase = CaseStyle(tail: TextTransform.capitalCase); @@ -94,7 +95,10 @@ extension CaseStyleTransform on CaseStyle? { } else { var words = text.split(splitter); if (style.head != null) { - words = [style.head.transform(words[0]), ...words.skip(1).map((w) => style.tail.transform(w))]; + words = [ + style.head.transform(words[0]), + ...words.skip(1).map((w) => style.tail.transform(w)) + ]; } else if (style.tail != null) { words = words.map((w) => style.tail.transform(w)).toList(); } diff --git a/lib/src/core/database.dart b/lib/src/core/database.dart index 3c18bda..8896443 100644 --- a/lib/src/core/database.dart +++ b/lib/src/core/database.dart @@ -43,8 +43,7 @@ class Database { user = user ?? Platform.environment['DB_USERNAME'] ?? DB_USERNAME, password = password ?? Platform.environment['DB_PASSWORD'] ?? DB_PASSWORD, useSSL = useSSL ?? (Platform.environment['DB_SSL'] != DB_SSL), - isUnixSocket = isUnixSocket ?? (Platform.environment['DB_SOCKET'] == DB_SOCKET) - { + isUnixSocket = isUnixSocket ?? (Platform.environment['DB_SOCKET'] == DB_SOCKET) { _cachedConnection ??= connection(); } @@ -68,11 +67,13 @@ class Database { String get name => _cachedConnection!.databaseName; Future open() => _tryOpen(); - Future close() async => !_cachedConnection!.isClosed ? await _cachedConnection!.close() : null; + Future close() async => + !_cachedConnection!.isClosed ? await _cachedConnection!.close() : null; Future _tryOpen() async { if (_cachedConnection!.isClosed) { - print('Database: connecting to ${_cachedConnection!.databaseName} at ${_cachedConnection!.host}...'); + print( + 'Database: connecting to ${_cachedConnection!.databaseName} at ${_cachedConnection!.host}...'); try { await _cachedConnection!.open(); } catch (e) { diff --git a/lib/src/core/query_params.dart b/lib/src/core/query_params.dart index 560bcf9..564d528 100644 --- a/lib/src/core/query_params.dart +++ b/lib/src/core/query_params.dart @@ -14,6 +14,6 @@ class QueryValues { String add(dynamic value) { values[key.toString()] = value; key += 1; - return '@${key-1}'; + return '@${key - 1}'; } -} \ No newline at end of file +} diff --git a/lib/src/core/transformer.dart b/lib/src/core/transformer.dart index da0085b..114ab28 100644 --- a/lib/src/core/transformer.dart +++ b/lib/src/core/transformer.dart @@ -1,4 +1,3 @@ - abstract class Transformer { const Transformer(); @@ -45,4 +44,4 @@ abstract class FilterByValue extends ListTransformer { String? where(String column, String table) { return "($column -> '$key') $operand to_jsonb (${value(column, table)})"; } -} \ No newline at end of file +} diff --git a/lib/src/internals/base_repository.dart b/lib/src/internals/base_repository.dart index 0314e81..426c51d 100644 --- a/lib/src/internals/base_repository.dart +++ b/lib/src/internals/base_repository.dart @@ -25,7 +25,8 @@ abstract class BaseRepository implements ModelRepository { BaseRepository(this.db, {required this.tableName, this.keyName}); Future queryOne(K key, KeyedViewQueryable q) async { - var params = QueryParams(where: '"${q.tableAlias}"."${q.keyName}" = ${q.encodeKey(key)}', limit: 1); + var params = + QueryParams(where: '"${q.tableAlias}"."${q.keyName}" = ${q.encodeKey(key)}', limit: 1); return (await queryMany(q, params)).firstOrNull; } @@ -47,4 +48,3 @@ abstract class BaseRepository implements ModelRepository { return transaction(() => action.apply(db, request)); } } - diff --git a/lib/src/internals/delete_repository.dart b/lib/src/internals/delete_repository.dart index eaf9c2d..ac47f35 100644 --- a/lib/src/internals/delete_repository.dart +++ b/lib/src/internals/delete_repository.dart @@ -1,4 +1,3 @@ - import '../core/query_params.dart'; import 'base_repository.dart'; @@ -7,14 +6,14 @@ abstract class ModelRepositoryDelete { Future deleteMany(List ids); } - -mixin RepositoryDeleteMixin on BaseRepository implements ModelRepositoryDelete { +mixin RepositoryDeleteMixin on BaseRepository + implements ModelRepositoryDelete { Future delete(List keys) async { if (keys.isEmpty) return; var values = QueryValues(); await db.query( 'DELETE FROM "$tableName"\n' - 'WHERE "$tableName"."$keyName" IN ( ${keys.map((k) => values.add(k)).join(', ')} )', + 'WHERE "$tableName"."$keyName" IN ( ${keys.map((k) => values.add(k)).join(', ')} )', values.values, ); } diff --git a/lib/src/internals/insert_repository.dart b/lib/src/internals/insert_repository.dart index 0d807cf..e07d4bf 100644 --- a/lib/src/internals/insert_repository.dart +++ b/lib/src/internals/insert_repository.dart @@ -1,4 +1,3 @@ - import '../core/database.dart'; import 'base_repository.dart'; @@ -12,7 +11,8 @@ abstract class KeyedModelRepositoryInsert { Future> insertMany(List requests); } -mixin RepositoryInsertMixin on BaseRepository implements ModelRepositoryInsert { +mixin RepositoryInsertMixin on BaseRepository + implements ModelRepositoryInsert { Future insert(List requests); @override @@ -21,11 +21,13 @@ mixin RepositoryInsertMixin on BaseRepository implements ModelRep Future insertMany(List requests) => transaction(() => insert(requests)); } -mixin KeyedRepositoryInsertMixin on BaseRepository implements KeyedModelRepositoryInsert { +mixin KeyedRepositoryInsertMixin on BaseRepository + implements KeyedModelRepositoryInsert { Future> insert(List requests); @override - Future insertOne(InsertRequest request) => transaction(() => insert([request])).then((r) => r.first); + Future insertOne(InsertRequest request) => + transaction(() => insert([request])).then((r) => r.first); @override Future> insertMany(List requests) => transaction(() => insert(requests)); } diff --git a/lib/src/internals/text_encoder.dart b/lib/src/internals/text_encoder.dart index 1108083..fd5cde0 100644 --- a/lib/src/internals/text_encoder.dart +++ b/lib/src/internals/text_encoder.dart @@ -12,7 +12,8 @@ final _baseConverters = { typeOf(): _PrimitiveTypeConverter((dynamic v) => num.parse(v.toString()).round()), typeOf(): _PrimitiveTypeConverter((dynamic v) => double.parse(v.toString())), typeOf(): _PrimitiveTypeConverter((dynamic v) => num.parse(v.toString())), - typeOf(): _PrimitiveTypeConverter((dynamic v) => v is num ? v != 0 : v.toString() == 'true'), + typeOf(): + _PrimitiveTypeConverter((dynamic v) => v is num ? v != 0 : v.toString() == 'true'), typeOf(): _DateTimeConverter(), }; @@ -57,7 +58,6 @@ class _DateTimeConverter extends TypeConverter { } class TextEncoder { - TextEncoder(); static TextEncoder i = TextEncoder(); @@ -263,7 +263,8 @@ class _TextEncoder { } String _encodePoint(PgPoint value, QuoteStyle quotes) { - return _encodeString('(${_encodeNumber(value.latitude)},${_encodeNumber(value.longitude)})', quotes); + return _encodeString( + '(${_encodeNumber(value.latitude)},${_encodeNumber(value.longitude)})', quotes); } String _sharedType(List values) { diff --git a/lib/src/internals/update_repository.dart b/lib/src/internals/update_repository.dart index 6791728..fce8377 100644 --- a/lib/src/internals/update_repository.dart +++ b/lib/src/internals/update_repository.dart @@ -1,4 +1,3 @@ - import '../core/database.dart'; import 'base_repository.dart'; @@ -7,7 +6,8 @@ abstract class ModelRepositoryUpdate { Future updateMany(List requests); } -mixin RepositoryUpdateMixin on BaseRepository implements ModelRepositoryUpdate { +mixin RepositoryUpdateMixin on BaseRepository + implements ModelRepositoryUpdate { @override Future updateOne(UpdateRequest request) => transaction(() => update([request])); @override @@ -17,10 +17,9 @@ mixin RepositoryUpdateMixin on BaseRepository implements ModelRep } class UpdateColumns { - final String columnName; final String columnType; final T Function(UpdateRequest) getValue; UpdateColumns(this.columnName, this.columnType, this.getValue); -} \ No newline at end of file +} diff --git a/lib/src/internals/view_query.dart b/lib/src/internals/view_query.dart index bf6cd26..530d15f 100644 --- a/lib/src/internals/view_query.dart +++ b/lib/src/internals/view_query.dart @@ -1,4 +1,3 @@ - import 'dart:convert'; import '../core/annotations.dart'; @@ -52,4 +51,4 @@ class ViewQuery implements Query, QueryParams> { print('Queried ${results.length} rows in ${DateTime.now().difference(time)}'); return results; } -} \ No newline at end of file +} diff --git a/lib/stormberry.dart b/lib/stormberry.dart index 9b2f0a7..d63145e 100644 --- a/lib/stormberry.dart +++ b/lib/stormberry.dart @@ -12,4 +12,4 @@ export 'src/internals/insert_repository.dart'; export 'src/internals/update_repository.dart'; export 'src/internals/delete_repository.dart'; export 'src/internals/view_query.dart'; -export 'src/internals/text_encoder.dart'; \ No newline at end of file +export 'src/internals/text_encoder.dart'; diff --git a/test/analyze/analyze_simple_test.dart b/test/analyze/analyze_simple_test.dart index 1504c64..a71aca9 100644 --- a/test/analyze/analyze_simple_test.dart +++ b/test/analyze/analyze_simple_test.dart @@ -141,9 +141,9 @@ void main() { var view = table.views['']!; expect(view.isDefaultView, isTrue); - expect(view.className, equals('MyModelView')); - expect(view.entityName, equals('MyModel')); - expect(view.viewName, equals('MyModel')); + expect(view.className, equals('MyModelView')); + expect(view.entityName, equals('MyModel')); + expect(view.viewName, equals('MyModel')); expect(view.viewTableName, equals('my_models_view')); }); }); diff --git a/test/analyze/relations/analyze_many_to_many_relations_test.dart b/test/analyze/relations/analyze_many_to_many_relations_test.dart index e559ca4..450e560 100644 --- a/test/analyze/relations/analyze_many_to_many_relations_test.dart +++ b/test/analyze/relations/analyze_many_to_many_relations_test.dart @@ -99,7 +99,8 @@ void main() { expect( caller, - throwsA('Model B cannot have a many-to-many relation to model A without specifying a primary key.\n' + throwsA( + 'Model B cannot have a many-to-many relation to model A without specifying a primary key.\n' 'Either define a primary key for B or change the relation by changing field "List a" to have a non-list type.'), ); }); diff --git a/test/polyfill.dart b/test/polyfill.dart index 966ed9e..90e9dfa 100644 --- a/test/polyfill.dart +++ b/test/polyfill.dart @@ -4,16 +4,16 @@ import 'package:build_test/build_test.dart'; import 'package:build_resolvers/build_resolvers.dart'; Future testBuilder2( - Builder builder, - Map*/ Object> sourceAssets, { - Set? generateFor, - bool Function(String assetId)? isInput, - String? rootPackage, - MultiPackageAssetReader? reader, - RecordingAssetWriter? writer, - ResourceManager? resourceManager, - Map|Matcher>*/ Object>? outputs, - }) async { + Builder builder, + Map*/ Object> sourceAssets, { + Set? generateFor, + bool Function(String assetId)? isInput, + String? rootPackage, + MultiPackageAssetReader? reader, + RecordingAssetWriter? writer, + ResourceManager? resourceManager, + Map|Matcher>*/ Object>? outputs, +}) async { writer ??= InMemoryAssetWriter(); var inputIds = {for (var descriptor in sourceAssets.keys) makeAssetId(descriptor)}; @@ -56,9 +56,10 @@ Future testBuilder2( WrittenAssetReader(writer, spyForStep), ]); - await runBuilder(builder, {input}, readerForStep, spyForStep, resolvers, resourceManager: resourceManager); + await runBuilder(builder, {input}, readerForStep, spyForStep, resolvers, + resourceManager: resourceManager); } var actualOutputs = writerSpy.assetsWritten; checkOutputs(outputs, actualOutputs, writer); -} \ No newline at end of file +} diff --git a/test/utils.dart b/test/utils.dart index 74ab494..feb3708 100644 --- a/test/utils.dart +++ b/test/utils.dart @@ -70,7 +70,8 @@ void testColumn( (column as FieldColumnElement); expect(column.dartType, equals(dartType)); } else { - expect(column, isNot(isA()), reason: 'Missing [dartType] param for field column.'); + expect(column, isNot(isA()), + reason: 'Missing [dartType] param for field column.'); } if (paramName != null) { @@ -78,7 +79,8 @@ void testColumn( (column as ParameterColumnElement); expect(column.paramName, equals(paramName)); } else { - expect(column, isNot(isA()), reason: 'Missing [paramName] param for parameter column.'); + expect(column, isNot(isA()), + reason: 'Missing [paramName] param for parameter column.'); } expect(column.isList, equals(isList)); @@ -88,7 +90,8 @@ void testColumn( (column as LinkedColumnElement); expect(column.linkedTable, equals(linkedTo)); } else { - expect(column, isNot(isA()), reason: 'Missing [linkedTo] param for linked column.'); + expect(column, isNot(isA()), + reason: 'Missing [linkedTo] param for linked column.'); } if (references != null && joinedTo == null) { @@ -109,7 +112,8 @@ void testColumn( expect(references, isA()); expect(column.referencedColumn, equals(references)); } else { - expect(column, isNot(isA()), reason: 'Missing [joinedTo] param for join column.'); + expect(column, isNot(isA()), + reason: 'Missing [joinedTo] param for join column.'); } if (column.parameter != null) {