Skip to content

Commit

Permalink
feat(PostgreSQL): database in connection parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabio286 committed Mar 17, 2021
1 parent 8a6c59f commit 9645702
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 30 deletions.
7 changes: 6 additions & 1 deletion src/common/customizations/defaults.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
module.exports = {
// Defaults
defaultPort: null,
defaultUser: null,
defaultDatabase: null,
// Core
database: false,
collations: false,
engines: false,
// Tools
processesList: false,
usersManagement: false,
variables: false,
// Structure
databases: true,
schemas: false,
tables: false,
views: false,
triggers: false,
Expand Down
5 changes: 5 additions & 0 deletions src/common/customizations/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
maria: require('./mysql'),
mysql: require('./mysql'),
pg: require('./postgresql')
};
4 changes: 4 additions & 0 deletions src/common/customizations/mysql.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ const defaults = require('./defaults');

module.exports = {
...defaults,
// Defaults
defaultPort: 3306,
defaultUser: 'root',
defaultDatabase: null,
// Core
collations: true,
engines: true,
Expand Down
15 changes: 9 additions & 6 deletions src/common/customizations/postgresql.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@ const defaults = require('./defaults');

module.exports = {
...defaults,
// Defaults
defaultPort: 5432,
defaultUser: 'postgres',
defaultDatabase: 'postgres',
// Core
collations: false,
engines: false,
database: true,
// Tools
processesList: true,
// Structure
tables: true,
views: true,
triggers: true,
routines: true,
functions: true,
views: false,
triggers: false,
routines: false,
functions: false,
schedulers: false,
// Settings
databaseEdit: false,
Expand Down
6 changes: 6 additions & 0 deletions src/main/ipc-handlers/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ export default connections => {
password: conn.password
};

if (conn.database)
params.database = conn.database;

if (conn.ssl) {
params.ssl = {
key: conn.key ? fs.readFileSync(conn.key) : null,
Expand Down Expand Up @@ -50,6 +53,9 @@ export default connections => {
password: conn.password
};

if (conn.database)
params.database = conn.database;

if (conn.ssl) {
params.ssl = {
key: conn.key ? fs.readFileSync(conn.key) : null,
Expand Down
3 changes: 2 additions & 1 deletion src/main/libs/clients/PostgreSQLClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ export class PostgreSQLClient extends AntaresCore {
async connect () {
if (!this._poolSize) {
const client = new Client(this._params);
this._connection = client.connect();
await client.connect();
this._connection = client;
}
else {
const pool = new Pool({ ...this._params, max: this._poolSize });
Expand Down
28 changes: 23 additions & 5 deletions src/renderer/components/ModalEditConnection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@
PostgreSQL
</option>
<!-- <option value="mssql">
Microsoft SQL
</option>
<option value="oracledb">
Oracle DB
</option> -->
Microsoft SQL
</option>
<option value="oracledb">
Oracle DB
</option> -->
</select>
</div>
</div>
Expand Down Expand Up @@ -97,6 +97,18 @@
>
</div>
</div>
<div v-if="customizations.database" class="form-group">
<div class="col-4 col-sm-12">
<label class="form-label">{{ $t('word.database') }}</label>
</div>
<div class="col-8 col-sm-12">
<input
v-model="localConnection.database"
class="form-input"
type="text"
>
</div>
</div>
<div class="form-group">
<div class="col-4 col-sm-12">
<label class="form-label">{{ $t('word.user') }}</label>
Expand Down Expand Up @@ -247,6 +259,7 @@

<script>
import { mapActions } from 'vuex';
import customizations from 'common/customizations';
import Connection from '@/ipc-api/Connection';
import ModalAskCredentials from '@/components/ModalAskCredentials';
import BaseToast from '@/components/BaseToast';
Expand Down Expand Up @@ -274,6 +287,11 @@ export default {
selectedTab: 'general'
};
},
computed: {
customizations () {
return customizations[this.connection.client];
}
},
created () {
this.localConnection = Object.assign({}, this.connection);
window.addEventListener('keydown', this.onKey);
Expand Down
42 changes: 25 additions & 17 deletions src/renderer/components/ModalNewConnection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,18 @@
>
</div>
</div>
<div v-if="customizations.database" class="form-group">
<div class="col-4 col-sm-12">
<label class="form-label">{{ $t('word.database') }}</label>
</div>
<div class="col-8 col-sm-12">
<input
v-model="connection.database"
class="form-input"
type="text"
>
</div>
</div>
<div class="form-group">
<div class="col-4 col-sm-12">
<label class="form-label">{{ $t('word.user') }}</label>
Expand Down Expand Up @@ -251,6 +263,7 @@

<script>
import { mapActions } from 'vuex';
import customizations from 'common/customizations';
import Connection from '@/ipc-api/Connection';
import { uidGen } from 'common/libs/uidGen';
import ModalAskCredentials from '@/components/ModalAskCredentials';
Expand All @@ -270,8 +283,9 @@ export default {
name: '',
client: 'mysql',
host: '127.0.0.1',
port: '3306',
user: 'root',
database: null,
port: null,
user: null,
password: '',
ask: false,
uid: uidGen('C'),
Expand All @@ -291,7 +305,13 @@ export default {
selectedTab: 'general'
};
},
computed: {
customizations () {
return customizations[this.connection.client];
}
},
created () {
this.setDefaults();
window.addEventListener('keydown', this.onKey);
setTimeout(() => {
Expand All @@ -307,21 +327,9 @@ export default {
addConnection: 'connections/addConnection'
}),
setDefaults () {
switch (this.connection.client) {
case 'mysql':
this.connection.port = '3306';
break;
case 'mssql':
this.connection.port = '1433';
break;
case 'pg':
this.connection.user = 'postgres';
this.connection.port = '5432';
break;
case 'oracledb':
this.connection.port = '1521';
break;
}
this.connection.user = this.customizations.defaultUser;
this.connection.port = this.customizations.defaultPort;
this.connection.database = this.customizations.defaultDatabase;
},
async startTest () {
this.isTesting = true;
Expand Down

0 comments on commit 9645702

Please sign in to comment.