“This is the 11th day of my participation in the Gwen Challenge in November. See details: The Last Gwen Challenge in 2021.”

Preface:

I used the persistent library Moor in my previous Flutter project. Recently, I wanted to summarize the usage of MOOR. Then I saw the news that MOOR had been renamed as Drift in the PUB of MOOR.

moor:

  1. n.Wilderness, wilderness
  2. vt. & vi.To moor (a ship) at anchor.

drift:

  1. Drifting; Drift; trend
  2. Drifting; drifting
  3. N. That… Drift; Make the… By the wind

No longer moored, but began to drift

Related content simple meat turned over.

Moor pub: moor | Dart Package (pub. Dev)

Important notice: MOOR has been renamed drift. The package (MOOR) will continue to be supported for some time, but we are still encouraging users to migrate to Drift. Automated tools to help with switching are already available. For more information, please check the documentation. Thank you for your understanding.

Drift pub: drift | Dart Package (pub. Dev)

Moor and Drift

Moor and Drift (simonbinder.eu)

Moor has been renamed Drift. The reason is that in some parts of the world moor is used as an irreverent term. This was not known at the beginning of the project, but we believe that the current name (moor) does not reflect the inclusiveness of the Dart&Flutter community. Despite these efforts, I believe that the project’s renaming is the right decision. Thank you for your understanding.

Until version 5.0.0, the current MOOR and Moor_Generator will continue to be available – no urgent changes are required. All features and fixes for the new pack Drift will be reflected on moor. By the time of the next incompatible release, moor will have discontinued maintenance in favor of Drift and DRIFt_dev.

This article described how to migrate from the old MOOR package to the new Drift package. This process can be automated and we hope it will be a matter of minutes for you. This article also describes how to manually migrate to the new Drift package if there are problems with the (automatic migration) tool.

Automatic migration

To make the name change as easy as possible, Drift has come with a tool to automate migration for projects. It analyzes the project’s source code files and then makes all migration-related changes.

In order to use the migration tool, first verify that the version of moor_Generator being used is 4.6.0 or later, such as the following update dependencies:

dev_dependencies:
  moor_generator: ^ 4.6.0
Copy the code

Next, verify that the project has no analysis errors, which can make the migration tool inefficient. Of course, before running the migration tool, you need to create a backup of the current project files. Because the migration process overwrites part of the code file without any further confirmation prompts. If you are using Git, make sure it is clean.

To migrate, run the dart run moor_generator migrate command in the project directory. If you are using a Flutter, run the Flutter pub Run moor_generator Migrate instead. The migration tool transforms the project’s PubSpec, build.yaml files, and Dart code files. The.moor file will also be renamed to the.drift file and the import in the code will be changed as needed.

After running the migration, confirm the changes to the migration to ensure that the migration results as expected.

You may also need to do the following:

  • Reformat code: Rundart format .flutter format .
  • Recompile :(Dart project) rundart run build_runner buildOr (Flutter project) operationflutter pub run build_runner build --delete-conflicting-outputs.
  • Manually modify the order of import changes caused by migration.

Congratulations to you! Your project is already using Drift!

If you have problems using the automatic move tool, please open an issue.

Manual migration

Migrating from MOOR to Drift may require updating the following files:

  • Engineering pubspec
  • The import of the Dart
  • Dart code, reflecting the new API name
  • Build. yaml configuration file, if available

New rely on

Drift_dev is used to replace moor and MOor_generator dependencies.

dependencies:
  drift: ^ 1.0.1
dev_dependencies:
  drift_dev: ^ 1.0.2
Copy the code

Run pub get to get the new package.

Modify the Dart import

The table below compares the old import of MOOR with the new import of Drift.

moor import drift import
package:moor/extensions/json1.dart package:drift/extensions/json1.dart
package:moor/extensions/moor_ffi.dart package:drift/extensions/native.dart
package:moor/backends.dart package:drift/backends.dart
package:moor/ffi.dart package:drift/native.dart
package:moor/isolate.dart package:drift/isolate.dart
package:moor/moor_web.dart package:drift/web.dart
package:moor/moor.dart package:drift/drift.dart
package:moor/remote.dart package:drift/remote.dart
package:moor/sqlite_keywords.dart package:drift/sqlite_keywords.dart

Modifying the Dart code

The table below compares the API names specific to MOOR with the corresponding API names for Drift.

Moor the API name Drift of the API
VmDatabase NativeDatabase
MoorIsolate DriftIsolate
MoorWebStorage DriftWebStorage
@UseMoor @DriftDatabase
@UseDao @DriftAccessor
MoorWrappedException DriftWrappedException
MoorRuntimeOptions DriftRuntimeOptions
moorRuntimeOptions driftRuntimeOptions
$mrjc and $mrjf Use Object.hash from dart:core
MoorServer DriftServer

(Optional: Rename the MOOR file)

For consistency, rename the.moor file to.drift. The Drift Generator will continue to accept.moor files, though.

If you choose to rename, you will also need to update import and include: the parameters used in the database and DAO classes.

Compile the configuration

If the Moor Builder option is currently configured, you will also need to update the build.yaml file to reflect the new Builder key.

The moor builder key Drift builder key
moor_generator|preparing_builder drift_dev|preparing_builder
moor_generator|moor_generator drift_dev|drift_dev
moor_generator drift_dev
moor_generator|moor_generator_not_shared drift_dev|not_shared
moor_generator|moor_cleanup drift_dev|cleanup

Start migrating.