Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get datamapper to work with a postgresql database?

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?

like image 992
node ninja Avatar asked Mar 29 '12 11:03

node ninja


2 Answers

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')
like image 103
Lars Haugseth Avatar answered Oct 04 '22 00:10

Lars Haugseth


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

like image 22
hoitomt Avatar answered Oct 04 '22 00:10

hoitomt