pinchbv / floor

The typesafe, reactive, and lightweight SQLite abstraction for your Flutter applications
https://pinchbv.github.io/floor/
Apache License 2.0
965 stars 191 forks source link

How can I initialize the database once? Singleton pattern #836

Open a13020796019 opened 3 months ago

a13020796019 commented 3 months ago

@Database( version: 1, entities: [StaffInfoModel, MeetingInfoModel, MeetingFileInfoModel]) abstract class SqliteDatabase extends FloorDatabase { StaffInfoDao get staffInfoDao; MeetingInfoDao get meetingInfoDao; MeetingFileInfoDao get meetingFileInfoDao; }

final database = await $FloorSqliteDatabase .databaseBuilder('app_database.db') .build();

      final meetingInfoDao = database.meetingInfoDao;
      ///先删除
      await meetingInfoDao.deleteMeetingInfoByConferId(
          applicationController.uuid, conferController.conferId!);
      final MeetingInfoModel meetingInfo = MeetingInfoModel(
          conferId: conferController.conferId!,
          uuid: '',
          name: homeDetailEntity.meeting!.title!,
          startTime: homeDetailEntity.meeting!.startTime!,
          endTime: '',
          room: homeDetailEntity.meeting!.room!);

      meetingInfoDao.insertMeetingInfo(meetingInfo);