5 comments
This is a great post on how SQL can be used in a Ruby app and how it compares to Rails ActiveRecord. I am also reading your book ‘Ruby Deep Dive’ and really like how you keep the topics clean and concise. Thanks for what you provide to the community! You are a true asset!
Hi Rick,
thanks a lot for you comment! 🙂
It was the first time I heard about Sequel and I found it very interesting. Thanks for sharing.
Nice! I’m glad you learned something new 🙂
Nice article, I know about Sequel and I think it is superior to ActiveRecord in many aspects. First, performance, sequel is faster than ActiveRecord. Second, is connections management, while ActiveRecord creates and assigns a connection to each thread and it doesn’t release it until the thread is dead, Sequel just reserves the connection when a query is about to be sent to the db server, once the query is over the connection is returned to the pool. This seems simple, but it’s a killer feature especially in multithreaded environments like Sidekiq.
Third, its Api, Active record creates a model instance for every record in the query result, those records are huge and in some cases you may not need them. For example in an Api that returns Json, with sequel you don’t even need a model class, you just serialize the hashes, no waste here, but with AR it creates a new object for every hash of the results, then you convert them back to Json, a lot of waste in time and memory. There are other things, but these are just a subset of the cool things that makes Sequel great and make me love it.
Here a great video of the creator of Sequel about its internals, it’s definitely worth watching.
https://youtu.be/RuGZCcEL2F8