Skip to content

Document running a basic hello world on heroku #1342

Open

Description

@brianc
No description provided.

Activity

  1. added this to the docs milestone on Jun 22, 2017
  2. caub commented on Jun 24, 2017

    @caub
    Contributor

    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?

  3. mariusa commented on Jul 12, 2017

    @mariusa

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

  4. caub commented on Jul 12, 2017

    @caub
    Contributor

    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)
  5. charmander commented on Jul 12, 2017

    @charmander
    Collaborator
  6. caub commented on Jul 12, 2017

    @caub
    Contributor

    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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions