Skip to content

create the database if it doesn't exist #3072

@its-dibo

Description

@its-dibo

when executing connect() it fails if the database doesn't exist.
there are two solutions:

  • either to add an option to create the missing database
  • or, just establish the connection without selecting a database
connect({createDb: true, host: 'localhost', ...config})

or

connect(config)
 .catch(err=>{
   if(/* error caused by a missing database */) 
     pg.query(`CREATE DATABASE ${db}`)
     .then(()=>connect())
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions