Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter : Difference between Moor and floor ORMs [closed]

So I had been looking for some ORMs for Flutter and I found two candidates Moor and Floor.

Seems like Moor has a little bit more active repository but As I came from the Android world, Floor seems more similar to Room which I used to love.

Currently, I am in favor to use Floor but are there any hidden gotchas that I should be aware of before using it in production?

like image 883
erluxman Avatar asked Oct 14 '19 12:10

erluxman


2 Answers

I also have some doubts on which is the best for production environment. Seems like Moor is already stable and battle tested and production ready. There is a good technical explanation in moor FAQ comparing Moor with Floor and plus another alternatives:

Floor also has a lot of convenience features like auto-updating queries and schema migrations. Similar to moor, you define the structure of your database in Dart. Then, you have write queries in sql - the mapping code if generated by floor. Moor has a similar feature, but it can also verify that your queries are valid at compile time. Moor additionally has an api that let’s you write some queries in Dart instead of sql.

A difference between these two is that Floor let’s you write your own classes and generates mapping code around that. Moor generates most classes for you, which can make it easier to use, but makes the api less flexible in some instances.

I have made some tests including the sqfEntity which employee scaffolding concepts and it's do more stuffs like forms than just data persistence. For me seems like Floor is more close to Hibernate mainly in the way that Entities were created, just make a comparison between their Entities sintaxe, therefore I found it more familiar and have choose Floor despite it's very new yet.

Also there is Jaguar ORM for Dart: https://github.com/Jaguar-dart/jaguar_orm. I haven't tested JaguarORM yet, but it's the only one that have support for OneToOne, OneToMany, and ManyToMany relationships and it's also support another databases.

Moor has an experimental support for the web, take a look: https://moor.simonbinder.eu/web/. Despite it's an experimental feature, if your app will need to be portable the web, you need to consider it. There is another alternative for the web: https://github.com/sql-js/sql.js. The fact is it's very difficult allow sqlite be abstracted to local storage in browser. But at least Moor is trying to achieve it.

For those that are looking to DateTime converters both Floor and Moor already support it. Floor added it since version 0.17: https://github.com/vitusortner/floor#type-converters

In case you just need to concern about android/ios I will recommend you to try Floor, mainly because his sintaxe is really very good.

like image 70
Cassio Seffrin Avatar answered Oct 30 '22 11:10

Cassio Seffrin


As far as I know, Floor is a quite new. Even its documentation states it

This package is still in an early phase and the API will likely change.

So it means if the package is changed then you will also have to adapt your code. Whereas Moor is more popular and you can find some nice tutorials. Even Google Developers use it for demo purposes.

like image 37
Marat Avatar answered Oct 30 '22 12:10

Marat