Javascript

Comparing Laravel and AdonisJs – Part 2

Yesterday I published Part 1 of a comparison between Laravel and AdonisJs. Today is a continuation of that article.

ORM

Models

Laravel uses the Eloquent ORM which, when I first started using it, felt like magic. I was used to propel which required you to carefully specify each database table, field, field type and relationship. Eloquent didn’t require any of that as it’s based on the concept of convention over configuration. That means if you follow the convention then you get a load of functionality without doing any work. For example if I have an ‘Airline model, then Eloquent expects to find them in a table called ‘airlines’. I don’t need to define anything or configure anything. I can just grab a record and access all the fields using the column name.

$airline = AppAirline::find(1); // Find the Airline with ID 1
echo $airline->name; // Prints out the column 'name'

Once I’d used Eloquent I didn’t fancy going back to the ‘old’ way of configuring schemas etc.

Thankfully I discovered AdonisJs had something very similar called Lucid. It also favoured convention over configuration and followed the same conventions as Eloquent. Retrieving records and access properties was almost identical.

const this_airline = await Ailine.find(1);
console.log(this_airline.name);

Relationships

Relationships function in a very similar way on both ORMs. For example to define a One to Many relationship between Airlines and Planes in both you just specify it in the model.

class Airline extends Model {
    public function planes() {
        return $this->hasMany('AppPlane');
    }
}
class Airline extends Model {
    planes() {
        return this.hasMany('App/Models/Plane')
    }
}

Testing

I haven’t had chance to dive into testing in AdonisJs but based on what I can see in the documentation it seems to have things covered. There are Unit Tests, Functional Tests and Browser Tests which is similar to Laravel. Both frameworks use the ChromeDriver for the browser testing.

Queueing

Laravel’s queuing system is great and provides a ‘unified’ API across multiple different queue backends. That means the code you write to run with your database queue will work just as well when you switch out the database for a an Amazon SQS implementation. This is a great boost for productivity as you can run different backends for development and production.

This is the first big difference I’ve spotted! As far as I can see Queuing is not part of AdonisJs. It is mentioned in the documentation but only by installing a separate package called bee-queue. Seems like bee-queue is redis backed so I presume you’d have to install a different package to integrate with SQS and then you aren’t getting the ‘unified’ API advantage of Laravel.

Caching

Caching seems to follow a similar path as Queuing for both framworks. Laravel provides this unified API concept and you can swap backends in and out as you want. It supports using the filesystem, database, memcached and redis out of the box. Again, the code you write will work with any of these backends.

AdonisJs on the other hand seems to promote Redis. It has first class support for Redis through it’s own package built on top of ioredis. Although this can be used for caching it’s also possible to use it for Pub/Sub.

Conclusion

Drawing a conclusion from my time with both frameworks is difficult. I’ve been using Laravel for a long time and am very new to AdonisJs. I can only go off gut feel which is:

  • Overall: AdonisJs is great. Javascript isn’t my first language but I was able to be productive in the framework very quickly. I’ve made my feelings about Laravel clear already!
  • Documentation: It’s great for both. Very clear and easy to find what you are looking for.
  • Completeness: Laravel seems more complete and mature. I’m sure AdonisJs will add more features over time and can see that version 5.0 is imminent.
  • Community: The Laravel community seems more established. When I was searching for answers to problems in AdonisJs I felt like it wasn’t as easy to find an answer as it would be for the equivalent in Laravel. I’m sure this gap will narrow over time.
  • The Future: I’m tempted to keep trying with AdonisJs and see where it takes me.