Feb 24, 2009

Want more control over your database tables in DataMapper?

I had originally submitted a request to the DataMapper team to include an option to allow MySQL database users the ability to specify table options in their DataMapper models. My needs were around data warehousing and I wanted to use a different storage engine like Infobright. Unfortunately this request was denied because dm-core could have ended up looking like spaghetti if my request were approved. Mind you I'm oversimplifying the argument, but I understood where they were coming from. As a result, I bring you dm-mysql!

Overview

  • Plugin Name: dm-mysql

  • Summary: Plugin that allows MySQL DataMapper user the ability to specify MySQL table options when DataMapper creates database tables.

  • Requirements: Your DataMapper version must be > 0.9.10

  • Options: For available MySQL table options see the MySQL documentation. Note that this plugin was created against MySQL 5.1.

  • To Install: Make sure you have github listed as one of your sources.

  • sudo gem install neovintage-dm-mysql

Example

require 'dm-core'
require 'dm-mysql'

# Shows available options
class HasAllOption
  include DataMapper::Resource

  property :id, Serial
  property :name, String

  table_opts :engine => 'MyISAM',
    :avg_row_length => 7,
    :checksum => 1,
    :comment => "Best Comment EVER!!",
    :connection => 'another_connection',
    :data_directory => '/dude/wheres/my/dictionary',
    :delay_key_write => 0,
    :index_directory => '/index/this',
    :insert_method => 'FIRST',
    :key_block_size => 256,
    :max_rows => 5,
    :min_rows => 0,
    :pack_keys => 0,
    :password => 'secret',
    :row_format => 'COMPRESSED',
    :tablespace => 'DUDE',
    :union => 'has_its, not_includeds'

end

As always, I appreciate any feedback on the code or any features that you'd like to see implemented as part of this.