An ActiveRecord ODBC adapter. Master branch is working off of Rails 5.0.1. Previous work has been done to make it compatible with Rails 3.2 and 4.2; for those versions use the 3.2.x or 4.2.x gem releases.
This adapter will work for basic queries for most DBMSs out of the box, without support for migrations. Full support is built-in for MySQL 5 and PostgreSQL 9 databases. You can register your own adapter to get more support for your DBMS using the ODBCAdapter.register function.
A lot of this work is based on OpenLink's ActiveRecord adapter which works for earlier versions of Rails.
Ensure you have the ODBC driver installed on your machine. You will also need the driver for whichever database to which you want ODBC to connect.
Add this line to your application's Gemfile:
gem 'odbc_adapter'And then execute:
$ bundle
Or install it yourself as:
$ gem install odbc_adapter
Configure your database.yml by either using the dsn option to point to a DSN that corresponds to a valid entry in your ~/.odbc.ini file:
development:
adapter: odbc
dsn: MyDatabaseDSN
or by using the conn_str option and specifying the entire connection string:
development:
adapter: odbc
conn_str: "DRIVER={PostgreSQL ANSI};SERVER=localhost;PORT=5432;DATABASE=my_database;UID=postgres;"
ActiveRecord models that use this connection will now be connecting to the configured database using the ODBC driver.
To run the tests, you'll need the ODBC driver as well as the connection adapter for each database against which you're trying to test. Then run DSN=MyDatabaseDSN bundle exec rake test and the test suite will be run by connecting to your database.
Tested on Sierra.
Run from project root:
bundle package
docker build -f Dockerfile.dev -t odbc-dev .
# Local mount mysql directory to avoid some permissions problems
mkdir -p /tmp/mysql
docker run -it --rm -v $(pwd):/workspace -v /tmp/mysql:/var/lib/mysql odbc-dev:latest
# In container
docker/test.sh
To release a new version of the gem, follow these steps:
-
Create a release branch:
git checkout -b release/vX.Y.Z
-
Update the version number:
- Edit
lib/odbc_adapter/version.rband update theVERSIONconstant
- Edit
-
Update the CHANGELOG:
- Edit
CHANGELOG.mdto document all changes in this release - Update the release date for the version (use format
YYYY-MM-DD) - Move any items from
[Unreleased]to the new version section - Follow Keep a Changelog format
- Edit
-
Commit your changes:
git add lib/odbc_adapter/version.rb CHANGELOG.md git commit -m "Bump version to X.Y.Z" -
Push the branch and create a pull request:
git push origin release/vX.Y.Z
- Create a PR to merge into
master - Get it reviewed and approved
- Create a PR to merge into
-
After the PR is merged, tag the release:
git checkout master git pull git tag -a vX.Y.Z -m "Release version X.Y.Z" git push origin vX.Y.Z -
Build and publish the gem:
gem build odbc_adapter.gemspec gem push odbc_adapter-X.Y.Z.gem
-
Create a GitHub release:
- Go to the Releases page
- Click "Draft a new release"
- Select the tag you just created
- Use the version number as the release title (e.g.,
v7.0.0) - Copy the relevant section from CHANGELOG.md into the release notes
- Publish the release
Bug reports and pull requests are welcome on GitHub at https://github.com/localytics/odbc_adapter.
The gem is available as open source under the terms of the MIT License.