(input: MultiStepInput, state: Partial<ConnectionState>)
| 141 | } |
| 142 | |
| 143 | async setDatabase(input: MultiStepInput, state: Partial<ConnectionState>) { |
| 144 | // first need the databases |
| 145 | let connection: PgClient = null; |
| 146 | |
| 147 | let databases: DatabaseQuickPickItem[] = []; |
| 148 | let connectionError: any = null; |
| 149 | try { |
| 150 | connection = await Database.createConnection({ |
| 151 | label: '', |
| 152 | host: state.host, |
| 153 | user: state.user, |
| 154 | password: state.password, |
| 155 | port: state.port, |
| 156 | ssl: state.secure |
| 157 | }, 'postgres'); |
| 158 | const res = await connection.query('SELECT datname FROM pg_database WHERE datistemplate = false;'); |
| 159 | databases = res.rows.map<DatabaseQuickPickItem>(database => ({label: database.datname, dbname: database.datname})); |
| 160 | } catch(err) { |
| 161 | if (err.message === `permission denied for database "postgres"`) { |
| 162 | // Heroku message anyway... probably varies |
| 163 | // is there another common parameter could be checked? |
| 164 | } else { |
| 165 | // vscode.window.showErrorMessage(err.message); |
| 166 | } |
| 167 | } finally { |
| 168 | if (connection) { |
| 169 | await connection.end(); |
| 170 | connection = null; |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | if (databases.length < 1) { |
| 175 | // specify database via text input - may not have permission to list databases |
| 176 | let connectionOK = false; |
| 177 | do { |
| 178 | state.database = await input.showInputBox({ |
| 179 | title: this.TITLE, |
| 180 | step: input.CurrentStepNumber, |
| 181 | totalSteps: this.TotalSteps, |
| 182 | prompt: '[Optional] The database to connect to. Leave empty to enumerate databases on the server', |
| 183 | placeholder: '', |
| 184 | ignoreFocusOut: true, |
| 185 | value: (typeof state.database === 'string') ? state.database : '', |
| 186 | validate: async (value) => '' |
| 187 | }); |
| 188 | |
| 189 | try { |
| 190 | let databaseToTry = state.database && state.database.trim() ? state.database : 'postgres'; |
| 191 | connection = await Database.createConnection({ |
| 192 | label: '', |
| 193 | host: state.host, |
| 194 | user: state.user, |
| 195 | password: state.password, |
| 196 | port: state.port, |
| 197 | ssl: state.secure |
| 198 | }, databaseToTry); |
| 199 | connectionOK = true; |
| 200 | } catch(err) { |
no test coverage detected