Drift(Formerly known as moor): Flutter and dart library which support all platform
Moor/Drift is a reactive persistence library for Flutter and Dart, built on top of SQLite.
Updated: Moor is now renamed as drift due to the term moor may be used as a derogatory term.
I have updated this post and created a new video tutorial with the real-world todo app. you can check out the tutorial from here.
- So the other day I was working on a flutter DB-related application and I was happy working on sqflite which flutter official documentation recommends and It is working fine on android and iOS devices.
- But then the company where I was working require to make it work for web clients as well as other devices including Windows, mac and Linux as well.
That's where the moor/drift came into the picture.
So I sit quietly and did some research and didn't find one that fulfilled this requirement. Somehow I found this moor/drift library which is funny its a reverse word of room if you are coming from native android.
I give it a shot and spend a couple of days even though moor/drift DB on the web is still experimental and after some time I was able to get the application up and running on all devices. Well, at least the device which I am having (Android, Web, Windows).
All the information below are fetch from official moor/drift documentation and dart https://pub.dev/ library. Feel free to check out their documentation and sample example as well.
Ok, Now let's start answering your question one by one
So what is moor/drift exactly?
- Remember I said moor/drift, neither moor_flutter nor moor_ffi. Just plain moor/drift. You might get confused with moor_flutter and moor.
- Moor/drift is a dart package which can be used as a database persistence library in any dart application not necessarily flutter only.
- Moor/drift is a reactive persistence library for Dart and Flutter applications. It’s built on top of database libraries like sqflite or sql.js.
2. How it is different from room or sqflite?
- Room is a native android persistence library whereas moor/drift is a dart persistence library that supports all devices.
- sqflite is a plugin for Flutter that supports iOS, Android and macOS whereas moor/drift is a persistence library for Flutter and Dart, built on top of SQLite that support almost all devices.
- It is also a flexible, safe, fast and production-ready library.
3. Why we should go for the moor?
Moor/drift Provides additional features, like:
- Type safety: moor/drift provides type-safe
- Stream queries: Moor/drift lets you “live update” your queries with zero additional effort.
- Fluent queries: eg select(users).watch() (get all user live)
- Migration utils: Moor/drift migration let you create tables easily you don't need to write a query to create a table
4. Implementation Example
Application is already deployed to GitHub Check out here
Source code to GitHub can be found below:
Want to how to deploy a flutter web project to GitHub? Click here
That's all, Thanks guys, I hope you like this shitty blog. please make sure to give a clap 👏 and leave some engagement. let me know in the comment section if you face any issues.
Check out more blogs from CodingWithTashi. Follow me on Twitter or Instagram or YouTube.