Archive for January, 2008

Logging DataMapper SQL Queries in Merb

I have been experimenting with Merb for a while as an alternative to Rails.

Compared to Rails, Merb is a lightweight framework. By default Merb strips away a lot of unnecessary cruft, and in doing so does not include a default Object Relational Mapping (ORM), such as the popular ActiveRecord. Though this doesn’t prevent it from utilizing one, you are given the option of using a variety of frameworks to satisfy your application’s needs. Presently Merb supports ActiveRecord, DataMapper, and Sequel.

Out of the three I decided to experiment with DataMapper, as I was already familiar with ActiveRecord, and wanted to explore something new.

When using the default settings, DataMapper doesn’t log the queries! This makes it extremely difficult to debug an ORM especially when you are new to it.

Enabling Logging

Luckily you can add two keys :log_stream and :log_level to your config/database.yml to enable logging.

:development: &defaults
  :adapter: sqlite3
  :database: application_development
  :log_stream: STDOUT
  :log_level: 0

Disabling Logging

Now When going into production mode, you should (if you desire) turn logging off.

:production:
  <<: *defaults
  :database: application_production
  :log_stream: nil

Comments (2)

Installing do_postgres on MacPorts

Ensure that pg_config is in your $PATH.

Note: This expects you are using PostgreSQL 8.2. Alter the directories as required.

To test if pg_config is included, execute which pg_config Terminal:

Expected Result:
/opt/local/lib/postgresql82/bin/pg_config

Including pg_config into your $PATH

If you don’t get anything, then it isn’t in your path. Append the following to your ~/.profile file:
export PATH=$PATH:/opt/local/lib/postgresql82/bin

Now it will be included in all new terminal sessions.

Installing do_postgres

Now feel free to install the do_postgres gem.
sudo gem install do_postgres -- --with-pgsql-include-dir=/opt/local/include/postgresql82/ --with-pgsql-lib-dir=/opt/local/lib/postgresql82/

Note: This is a single line command.

Comments (2)