8

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?

runeks
  • 1,745
  • 2
  • 17
  • 26
erluxman
  • 18,155
  • 20
  • 92
  • 126

6 Answers6

8

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.

Cassio Seffrin
  • 7,293
  • 1
  • 54
  • 54
6

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.

Marat
  • 1,288
  • 2
  • 11
  • 22
3

I am using Floor at the moment for its simplicity. Other options are much more complex in my opinion. Although it is new, I never faced issues so far. It is all bases on simple annotation, required much less code than Moor from what I could read from the Documentation.

nono.31
  • 31
  • 1
1

Moor supports DateTime, Floor does not... Floor has been vacillating around how to do this - providing type converters - for over a year, and we couldn't wait, so rewrote our repository code form Floor to Moor.

idarwin
  • 607
  • 4
  • 19
0

I have started implementation of Floor and ran into a major snag -- it doesn't support DateTime. Granted sqlflite doesn't natively support DateTime, but it seems like a pretty necessary datatype to be able to handle. Moor handles this completely behind the scenes (although I don't love giving up control of models).

Jared Green
  • 196
  • 1
  • 7
  • There is active work done for implementation of Type Converters, which would include Datetime. Issue: https://github.com/vitusortner/floor/issues/165 Pull request WIP: https://github.com/vitusortner/floor/pull/318 – Andrei Erdoss May 03 '20 at 13:28
  • 2
    They already released Type Converters: https://github.com/vitusortner/floor#type-converters – Cassio Seffrin Oct 23 '20 at 14:58
0

Floor is an alternative of Android Room for flutter

hsul4n
  • 491
  • 7
  • 15