Reputation: 401
Can anyone explain how to use a PostgreSQL database with a Pakyow app?
I have built a Pakyow app and I have a PostgreSQL database, but I don't know how to set up the app to use the database.
Upvotes: 3
Views: 89
Reputation: 437
Pakyow doesn't have database support built-in, but it's compatible with any Ruby ORM (see the docs). Sequel is my go-to library for working with databases in Pakyow. To get Sequel working in your app, you'll first need to add sequel
and pg
(since you want to use Postgres) to your Gemfile:
gem 'sequel'
gem 'pg'
Next you'll need to configure the adapter in app.rb
. The best place to do this is in the configure
block for each environment. For example, this will configure the adapter for development:
$db = Sequel.connect('postgres://user:password@host:port/database_name')
You can access the $db
global throughout your app.
Have a look at the Sequel Documentation for info about accessing your data via direct queries or models.
Upvotes: 3