simolus3 / drift

Drift is an easy to use, reactive, typesafe persistence library for Dart & Flutter.
https://drift.simonbinder.eu/
MIT License
2.55k stars 365 forks source link

Type 'BaseReferences' not found after upgrading from drift 2.13.1 to 2.20.0 #3163

Closed MadsVETiSearch closed 3 weeks ago

MadsVETiSearch commented 3 weeks ago

I just upgraded to drift version 2.20.0 from 2.13.1 ran code gen, but when i try launch the app in iOS simulator i get the following error:

Error (Xcode): packages/database/lib/src/database.g.dart:26272:13: Error: Type 'BaseReferences' not found.

the line referred to is:

final class $$PharmaciesTableReferences
    extends BaseReferences<_$Database, $PharmaciesTable, PharmacyData> {
  $$PharmaciesTableReferences(super.$_db, super.$_table, super.$_typedResult);

  static MultiTypedResultKey<$ClinicsTable, List<ClinicData>> _clinicsRefsTable(
          _$Database db) =>
      MultiTypedResultKey.fromTable(db.clinics,
          aliasName:
              $_aliasNameGenerator(db.pharmacies.id, db.clinics.pharmacy_id));

  $$ClinicsTableProcessedTableManager get clinicsRefs {
    final manager = $$ClinicsTableTableManager($_db, $_db.clinics)
        .filter((f) => f.pharmacy_id.id($_item.id));

    final cache = $_typedResult.readTableOrNull(_clinicsRefsTable($_db));
    return ProcessedTableManager(
        manager.$state.copyWith(prefetchedData: cache));
  }

  static MultiTypedResultKey<$ClinicOrdersTable, List<ClinicOrderData>>
      _clinicOrdersRefsTable(_$Database db) =>
          MultiTypedResultKey.fromTable(db.clinicOrders,
              aliasName: $_aliasNameGenerator(
                  db.pharmacies.id, db.clinicOrders.pharmacy_id));

  $$ClinicOrdersTableProcessedTableManager get clinicOrdersRefs {
    final manager = $$ClinicOrdersTableTableManager($_db, $_db.clinicOrders)
        .filter((f) => f.pharmacy_id.id($_item.id));

    final cache = $_typedResult.readTableOrNull(_clinicOrdersRefsTable($_db));
    return ProcessedTableManager(
        manager.$state.copyWith(prefetchedData: cache));
  }

  static MultiTypedResultKey<$PrescriptionsTable, List<PrescriptionData>>
      _prescriptionsRefsTable(_$Database db) =>
          MultiTypedResultKey.fromTable(db.prescriptions,
              aliasName: $_aliasNameGenerator(
                  db.pharmacies.id, db.prescriptions.pharmacy_id));

  $$PrescriptionsTableProcessedTableManager get prescriptionsRefs {
    final manager = $$PrescriptionsTableTableManager($_db, $_db.prescriptions)
        .filter((f) => f.pharmacy_id.id($_item.id));

    final cache = $_typedResult.readTableOrNull(_prescriptionsRefsTable($_db));
    return ProcessedTableManager(
        manager.$state.copyWith(prefetchedData: cache));
  }
}

Im kinda lost, i havent been able to figure out whats happening, if you need me to provide anything else, please say so

MadsVETiSearch commented 3 weeks ago

changing the constructor in my db class fixed the issue.

I was using: Database() : super(connect(dbName: 'vdatabase'));

with this connect method:

DatabaseConnection connect({
  required String dbName,
  bool logStatements = false,
  bool inMemory = false,
}) {
  if (inMemory) {
    driftRuntimeOptions.dontWarnAboutMultipleDatabases = true;
  }
  return DatabaseConnection.delayed(
    Future.sync(() async {
      if (inMemory) {
        return DatabaseConnection(
          NativeDatabase.memory(logStatements: logStatements),
        );
      }
      final dbFolder = await getApplicationDocumentsDirectory();
      final file = File(p.join(dbFolder.path, dbName));

      return DatabaseConnection(
        NativeDatabase.createInBackground(
          file,
          logStatements: logStatements,
        ),
      );
    }),
  );
}

now i use: Database.defaults() : super(driftDatabase(name: 'vdatabase')); and it works.

if you know why this was an issue, please enlighten me

simolus3 commented 3 weeks ago

Perhaps the packages were in a weird state originally where the compiler wasn't aware of the drift upgrade - that also shouldn't happen now. So it will probably keep working without using driftDatabase, but that can't hurt :D