Skip to content

Document running a basic hello world on heroku #1342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
brianc opened this issue Jun 22, 2017 · 5 comments
Open

Document running a basic hello world on heroku #1342

brianc opened this issue Jun 22, 2017 · 5 comments
Assignees
Milestone

Comments

@brianc
Copy link
Owner

brianc commented Jun 22, 2017

No description provided.

@brianc brianc added this to the docs milestone Jun 22, 2017
@caub
Copy link
Contributor

caub commented Jun 24, 2017

schema.sql

CREATE TABLE IF NOT EXISTS hello {
  id   BIGSERIAL PRIMARY KEY;
  text TEXT DEFAULT '...';
}

Run heroku run "psql -U postgres -f schema.sql" --app your-app

hello-world.js

const {Pool} = require('pg');
const {parse} = require('pg-connection-string');
const dbConfig = Object.assign(parse(process.env.DATABASE_URL || 'pg://postgres@localhost/postgres'), {max: 9});
const pool = new Pool(dbConfig);
pool.query(`INSERT INTO hello(text) VALUES('world') RETURNING *`)
  .then(({rows}) => console.log(rows))
  .catch(console.error)

Run heroku run "node hello-world" --app your-app
like this?

@mariusa
Copy link

mariusa commented Jul 12, 2017

Hopefully connection-string support won't require another module.

@caub
Copy link
Contributor

caub commented Jul 12, 2017

I made a PR to make it simpler:

const {Pool} = require('pg');
const parse = require('pg-connection-string');

const pool = new Pool(parse(process.env.DATABASE_URL || 'pg://postgres@localhost/postgres', {ssl:true, max: 2}));
pool.query(`INSERT INTO hello(text) VALUES('world') RETURNING *`)
  .then(({rows}) => console.log(rows))
  .catch(console.error)

I hope the one integrated in pg will look like it

I'd love to do:

const {Pool} = require('pg');
// new Pool(opts) or new Pool(connectionString, opts)
const pool = new Pool(process.env.DATABASE_URL || 'pg://postgres@localhost/postgres', {ssl:true, max: 2});
pool.query(`INSERT INTO hello(text) VALUES('world') RETURNING *`)
  .then(({rows}) => console.log(rows))
  .catch(console.error)

@charmander
Copy link
Collaborator

@caub
Copy link
Contributor

caub commented Jul 12, 2017

ahh! nice, I'll test that, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants