As someone who primarily works with Rails, I feel like I use about 1% of PostgreSQL's power.
As someone who primarily works with Rails, I feel like I use about 1% of PostgreSQL's power.
Check out this blog post: http://blog.remarkablelabs.com/2012/12/a-love-affair-with-po...
When I first got to Rails it seemed that databases were considered as a bothersome but unavoidable necessity; flat files with a funny accent, instead of an essential and powerful ally in the fight against entropy and error.
Some poking around in the current documentation seems to suggest that FKs have been absorbed into ActiveRecord.
Interesting link, either way.
As much as I like Rails, I sometimes wish it were designed with the database playing more of a role than just dumb storage. Defining things like validations in Ruby is certainly nice and easy, but the database is much better suited to actually enforcing such constraints.
In your webapp using POSTGRESQL, are you actually using SQL statements in your code to retrieve the data? Or is there some other way to get at it?
Rather than me explaining it here, the rails guides[1] give you a good overview.
[1] http://guides.rubyonrails.org/active_record_querying.html
- CHECK constraints. I have a gem for setting up foreign keys and CHECK constraints in Rails:
https://github.com/pjungwir/db_leftovers
- named scopes. You can include SQL snippets like this: class Publisher
scope :with_no_books, -> {
where <<-EOQ
NOT EXISTS (SELECT 1
FROM books b
WHERE publishers.id = b.publisher_id)
EOQ
}
end
Of course you can do this with MySQL too, but it's one way to nicely incorporate arbitrary SQL with your ORM, so that you can take advantage of any Postgres feature you want.- PostGIS: http://blog.daniel-azuma.com/archives/60
- hstore/json columns.