[This article is a best-guess stub, and probably wrong; would someone who knows what’s going on please fix this?]
Creating a new database adapter for Rails (to be precise, ActiveRecord) requires the following steps.
0. Add the expected name of your adapter into this line in activerecord-x.x.x\lib\active_record.rb:
68 unless defined?(RAILS_CONNECTION_ADAPTERS)
69 RAILS_CONNECTION_ADAPTERS = &w(mysql postgresql sqlite firebird sqlserver db2 oci %{color:red}jet%) @
%{color:grey}70% @end
(as you can see, I’m trying to do a MS Jet 4.0 (thru ADO) adapter, so I added ‘jet’ to the list… perhaps in the future this list could be externalized to a YAML file? It took me awhile to figure this one out)
You can also add the following line to your boot.rb file for any app that wishes to use the new adapter:
RAILS_CONNECTION_ADAPTERS << 'jet'
If creating your adapter as a plugin, you can alternatively add the same line line to the plugin’s init.rb file.
1. Create DatabaseDrivers, usually in the vendor? branch.
These are the low-level functions which connect directly to the database, and manage:
Where there is no formal API or superclass for drivers, they typically provide the low-level routines needed to implement the interfaces in ‘activerecord/connection_adapters/abstract/database_statements’. Their purpose is primarily to wrap the native API in Ruby (while the initial version is often written purely in Ruby, high-performance versions are often bridged directly from C). Once you’re in Ruby, then we need to do a little extra work to make it play nicely in Rails (i.e., an Adaptor)
2. Define a Connection? in ActiveRecord::Base?
3. Define the Adapter
[This article is a best-guess stub, and probably wrong; would someone who knows what’s going on please fix this?]
Creating a new database adapter for Rails (to be precise, ActiveRecord) requires the following steps.
0. Add the expected name of your adapter into this line in activerecord-x.x.x\lib\active_record.rb:
68 unless defined?(RAILS_CONNECTION_ADAPTERS)
69 RAILS_CONNECTION_ADAPTERS = &w(mysql postgresql sqlite firebird sqlserver db2 oci %{color:red}jet%) @
%{color:grey}70% @end
(as you can see, I’m trying to do a MS Jet 4.0 (thru ADO) adapter, so I added ‘jet’ to the list… perhaps in the future this list could be externalized to a YAML file? It took me awhile to figure this one out)
You can also add the following line to your boot.rb file for any app that wishes to use the new adapter:
RAILS_CONNECTION_ADAPTERS << 'jet'
If creating your adapter as a plugin, you can alternatively add the same line line to the plugin’s init.rb file.
1. Create DatabaseDrivers, usually in the vendor? branch.
These are the low-level functions which connect directly to the database, and manage:
Where there is no formal API or superclass for drivers, they typically provide the low-level routines needed to implement the interfaces in ‘activerecord/connection_adapters/abstract/database_statements’. Their purpose is primarily to wrap the native API in Ruby (while the initial version is often written purely in Ruby, high-performance versions are often bridged directly from C). Once you’re in Ruby, then we need to do a little extra work to make it play nicely in Rails (i.e., an Adaptor)
2. Define a Connection? in ActiveRecord::Base?
3. Define the Adapter