Advanced Rails - Building Industrial-Strength Web Apps in Record Time

(Tuis.) #1

96


Chapter 4CHAPTER 4


Database 4


All non-trivial abstractions, to some degree, are leaky.
—Joel Spolsky


For many developers, Rails starts with the database. One of the most compelling
features of Rails is ActiveRecord, the object-relational mapping (ORM) layer.
ActiveRecord does such a good job of hiding the gory details of SQL from the pro-
grammer that it almost seems like magic.


However, as Joel Spolsky says, all abstractions are leaky. There is no perfectly trans-
parent ORM system, and there never will be, due to the fundamentally different
nature of the object-oriented and relational models. Ignore the underlying database
at your own peril.


Database Management Systems


The Rails community has been built around the MySQL database management sys-
tem (DBMS*) for years. However, there are still a lot of misconceptions surrounding
DBMSs, especially when used with Rails. While MySQL has its place, it is certainly
not the only option. In the past few years, support for other databases has vastly
grown. I encourage you to keep an open mind throughout this chapter, and weigh all
criteria before making a decision on a DBMS.


Rails supports many DBMSs; at the time of this writing, DB2, Firebird, FrontBase,
MySQL, OpenBase, Oracle, PostgreSQL, SQLite, Microsoft SQL Server, and Sybase
are supported. You will probably know if you need to use a DBMS other than the
ones mentioned here. Check the RDoc for the connection adapter for any caveats
specific to your DBMS; some features such as migrations are only supported on a
handful of connection adapters.



  • Informally, DBMSs are often referred to as “databases.” Consistent with industry practices, in this book
    “database management system” refers to the software package or installation thereof, while “database”
    refers to the actual data set being managed.

Free download pdf