7.1. Supported Databases

If you've used the .NET Framework before, you should be familiar with the concept of a Data Provider. The .NET Framework offers several types of this sort of class, each used to access data that's stored in SQL Server, Oracle, and data sources exposed using OLE DB and ODBC. Third-party alternatives are provided as well, so that .NET developers have a few options to choose from.

ActiveRecord is an Object-Relational Mapper and works at a higher level of abstraction than ADO.NET. For a database to be supported by ActiveRecord, two components are required: a driver and an adapter. The driver is typically a Ruby extension written at least partially in C, which exposes an API for storing and retrieving data from a given RDBMS (Relational Database Management System).

The adapter is comprised of Ruby code that's required to inform ActiveRecord about the specifics of the database system at hand. For example, the adapter specifies how to map ActiveRecord data types like string or datetime with their actual SQL representation. ActiveRecord doesn't really know anything about the driver either, so it's the adapter that ultimately calls the driver to execute a certain query.

Due to their nature, drivers are installed by the developers and aren't shipped with ActiveRecord or Rails. This is true for any database system. In Chapter 1, for example, you obtained the SQLite3 driver by installing the sqlite3-ruby gem. When it comes to the adapters though, you're looking at a different story. Four adapters ship with the framework: sqlite (for SQLite versions older than 3), sqlite3, mysql, and postgresql.

You can verify this by heading over to the official repository at http://github.com/rails/rails/tree/master/activerecord/lib/active_record/connection_adapters/ or by checking the content of the C: ubylib ubygems1.8gemsactiverecord-2.2.2libactive_recordconnection_adapters folder on your system. This path will vary if you installed Ruby in a different folder or if you're using another version of Rails.

In the past other adapters were shipped with ActiveRecord, but in December 2007 with the release of version 2, the controversial decision of limiting the core to the three main open source databases was made. This has a couple of implications for you if you decide to use a different database: you will need to install the adapter separately on your own, and it won't be directly maintained by the Rails core team.

In all but one instance, the maintainer is one or more community volunteers. In the case of the ibm_db adapter — the one I initially developed — the API team at IBM takes care of maintaining, developing, and supporting the adapter (and the driver).

The following table shows currently supported data sources besides SQLite, MySQL, and PostgreSQL, and which adapters/gems need to be installed in order to use them with ActiveRecord.

Data SourceAdapter's Gem
DB2ibm_db
DBSlayeractiverecord-dbslayer-adapter
Firebirdactiverecord-firebird-adapter
FrontBaseactiverecord-frontbase-adapter
Informixibm_db or activerecord-informix-adapter
Interbaseactiverecord-interbase-adapter
ODBCactiverecord-odbc-adapter
OpenBaseactiverecord-openbase-adapter
Oracleactiverecord-oracle-adapter or activerecord-oracle_enhanced-adapter
SQL Serveractiverecord-sqlserver-adapter
Salesforceactiverecord-activesalesforce-adapter
Sybaseactiverecord-sybase-adapter

It is possible that further ActiveRecord adapters for less common databases are going to be developed in the future.

If you list the remote gems (for example, by running gem list -r), you'll also notice gems with names such as activerecord-jdbcsqlite3-adapter; you can safely ignore these unless you intend to use JRuby.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.240.196