mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-21 00:06:01 +00:00
extracted getConnectionLabel functionality
This commit is contained in:
20
packages/web/src/utility/getConnectionLabel.ts
Normal file
20
packages/web/src/utility/getConnectionLabel.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
export default function getConnectionLabel(connection, { allowExplicitDatabase = true } = {}) {
|
||||
if (!connection) {
|
||||
return null;
|
||||
}
|
||||
if (connection.displayName) {
|
||||
return connection.displayName;
|
||||
}
|
||||
if (connection.singleDatabase && connection.server && allowExplicitDatabase && connection.defaultDatabase) {
|
||||
return `${connection.defaultDatabase} on ${connection.server}`;
|
||||
}
|
||||
if (connection.databaseFile) {
|
||||
const m = connection.databaseFile.match(/[\/]([^\/]+)$/);
|
||||
if (m) return m[1];
|
||||
return connection.databaseFile;
|
||||
}
|
||||
if (connection.server) {
|
||||
return connection.server;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
Reference in New Issue
Block a user