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?

node ninja
  • 31,796
  • 59
  • 166
  • 254

2 Answers2

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')
Lars Haugseth
  • 14,721
  • 2
  • 45
  • 49
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

hoitomt
  • 670
  • 1
  • 6
  • 16