How to get datamapper to work with a postgresql database?
Asked Answered
S

2

5

I have found several examples using datamapper and was able to get them to work. All these examples are for a sqlite database though. I'm trying to use datamapper with postgresql.

I changed the call in datamapper from sqlite3 to postgres, and I've got dm-postgres-adapter installed already. But it still doesn't work.

What else do I have to do?

Splay answered 29/3, 2012 at 11:31 Comment(2)
Can you show us your config section for postgres db?Tecu
I just changed sqlite3 so it looks like this DataMapper.setup(:default, "postgres://#{Dir.pwd}/database.pg")Splay
B
8

Unlike SQLite, PostgreSQL does not store databases in single files.

After you have created your database, try something like this:

DataMapper.setup :default, {
  :adapter  => 'postgres',
  :host     => 'localhost',
  :database => 'your-database-name',
  :user     => 'postgres',
}

Depending on your PostgreSQL configuration, you may need to connect as a different user, and/or supply a :passwordas well.

You can also use the short form:

DataMapper.setup(:default, 'postgres://user:password@hostname/database')
Blockbuster answered 29/3, 2012 at 19:46 Comment(0)
T
2

Another nice connection string, that will work with Heroku:

DataMapper.setup(:default, ENV['DATABASE_URL'] || "postgres://user:password@localhost/[YOUR_DATABASE_NAME]")

source: http://postgresapp.com/documentation

However I haven't seen anything, yet, where DataMapper will create the Postgresql database like Sqlite

Tabathatabb answered 1/3, 2013 at 13:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.