Skip to content

Commit

Permalink
Merge branch 'postgres_con_string' into fix-and-minimize-con-string
Browse files Browse the repository at this point in the history
  • Loading branch information
raliqala committed Mar 9, 2022
2 parents 12ce6b1 + cc02e2c commit b2ce533
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 12 deletions.
Empty file.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
"@turf/helpers": "^6.5.0",
"@vscode/vscode-languagedetection": "^1.0.21",
"ace-builds": "^1.4.13",
"better-sqlite3": "^7.4.4",
"better-sqlite3": "^7.5.0",
"electron-log": "^4.4.1",
"electron-store": "^8.0.1",
"electron-updater": "^4.6.1",
Expand Down
18 changes: 9 additions & 9 deletions src/renderer/components/BaseMap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,16 @@ export default {
</script>

<style lang="scss">
.map{
height: 400px;
.map {
height: 400px;
}
.marker-icon{
display: flex;
justify-content: center;
align-items: center;
background: $primary-color;
border-radius: 50%;
box-shadow: 0 0 5px 1px darken($body-font-color-dark, 40%);
.marker-icon {
display: flex;
justify-content: center;
align-items: center;
background: $primary-color;
border-radius: 50%;
box-shadow: 0 0 5px 1px darken($body-font-color-dark, 40%);
}
</style>
16 changes: 15 additions & 1 deletion src/renderer/components/WorkspaceAddConnectionPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@
</select>
</div>
</div>
<div v-if="connection.client === 'pg'" class="form-group columns">
<div class="column col-4 col-sm-12">
<label class="form-label">{{ $t('word.connectionString') }}</label>
</div>
<div class="column col-8 col-sm-12">
<input
ref="pgString"
v-model="connection.pgConnString"
class="form-input"
type="text"
>
</div>
</div>
<div v-if="!customizations.fileConnection" class="form-group columns">
<div class="column col-4 col-sm-12">
<label class="form-label">{{ $t('word.hostName') }}/IP</label>
Expand Down Expand Up @@ -412,7 +425,8 @@ export default {
sshUser: '',
sshPass: '',
sshKey: '',
sshPort: 22
sshPort: 22,
pgConnString: ''
},
isConnecting: false,
isTesting: false,
Expand Down
13 changes: 13 additions & 0 deletions src/renderer/components/WorkspaceEditConnectionPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@
</select>
</div>
</div>
<div v-if="connection.client === 'pg'" class="form-group columns">
<div class="column col-4 col-sm-12">
<label class="form-label">{{ $t('word.connectionString') }}</label>
</div>
<div class="column col-8 col-sm-12">
<input
ref="pgString"
v-model="localConnection.pgConnString"
class="form-input"
type="text"
>
</div>
</div>
<div v-if="!customizations.fileConnection" class="form-group columns">
<div class="column col-4 col-sm-12">
<label class="form-label">{{ $t('word.hostName') }}/IP</label>
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/i18n/en-US.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ module.exports = {
enable: 'Enable',
disable: 'Disable',
commit: 'Commit',
rollback: 'Rollback'
rollback: 'Rollback',
connectionString: 'Connection string'
},
message: {
appWelcome: 'Welcome to Antares SQL Client!',
Expand Down
110 changes: 110 additions & 0 deletions src/renderer/libs/connStringDecode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@

const getUrlScheme = pgString => {
const scheme = pgString ? pgString.split('://')[0] : '';

return scheme === 'postgresql' ? 'postgres' : scheme;
};

const passAndHost = part => {
const host = part.split('@')[1] === 'localhost' ? '127.0.0.1' : part.split('@')[1];
return [part.split('@')[0], host];
};

const portAndDb = part => {
return part.split('/');
};

const pass = (part) => {
return part.split('@');
};

const hostAndDb = (part) => {
return part.split('/');
};

const localConnectionString = (stringArgs, args) => {
let scheme = '';
if (getUrlScheme(stringArgs) === 'postgres' || getUrlScheme(stringArgs) === 'postgresql')
scheme = 'pg';

const values = stringArgs.split('://')[1];
const parts = values.split(':');

const userName = parts[0];

const password = passAndHost(parts[1])[0];
const host = passAndHost(parts[1])[1];

const port = portAndDb(parts[2])[0];
const dbName = portAndDb(parts[2])[1];

const client = args.client ? args.client : scheme;

args.client = client;
args.host = host;
args.database = dbName;
args.port = port;
args.user = userName;
args.password = password;

return args;
};

const onlineConnectionString = (stringArgs, args) => {
let scheme = '';
const defaultPort = '5432';
if (getUrlScheme(stringArgs) === 'postgres' || getUrlScheme(stringArgs) === 'postgresql')
scheme = 'pg';

const values = stringArgs.split('://')[1];
const parts = values.split(':');

const userName = parts[0];

const password = pass(parts[1])[0];

const host = hostAndDb(pass(parts[1])[1])[0];
const dbName = hostAndDb(pass(parts[1])[1])[1];

const port = defaultPort;

const client = args.client ? args.client : scheme;

args.client = client;
args.host = host;
args.database = dbName;
args.port = port;
args.user = userName;
args.password = password;

return args;
};

const connectionType = part => {
return part.split('=')[1];
};

const connStringConstruct = args => {
if (!args.pgConnString)
return args;

const pgConnString = args.pgConnString;

if (!pgConnString.includes('?'))
return localConnectionString(pgConnString, args);

const pgConnStringPrepared = pgConnString.split('?')[0];

switch (connectionType(pgConnString.split('?')[1])) {
case 'local':
return localConnectionString(pgConnStringPrepared, args);

case 'server':
return onlineConnectionString(pgConnStringPrepared, args);

default:
return args;
};
};

export default connStringConstruct;

0 comments on commit b2ce533

Please sign in to comment.