mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-30 01:03:58 +00:00
Commandline arguments #108
This commit is contained in:
@@ -1,14 +0,0 @@
|
|||||||
DEVMODE=1
|
|
||||||
|
|
||||||
CONNECTIONS=mysql
|
|
||||||
|
|
||||||
LABEL_mysql=MySql
|
|
||||||
SERVER_mysql=dbgate.org
|
|
||||||
USER_mysql=reader
|
|
||||||
PASSWORD_mysql=CovidReader2020
|
|
||||||
PORT_mysql=3326
|
|
||||||
ENGINE_mysql=mysql@dbgate-plugin-mysql
|
|
||||||
SINGLE_CONNECTION=mysql
|
|
||||||
SINGLE_DATABASE=covid
|
|
||||||
|
|
||||||
PERMISSIONS=files/charts/read
|
|
||||||
15
packages/api/.env-singledb
Normal file
15
packages/api/.env-singledb
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
DEVMODE=1
|
||||||
|
|
||||||
|
CONNECTIONS=mysql
|
||||||
|
|
||||||
|
LABEL_mysql=MySql localhost
|
||||||
|
SERVER_mysql=localhost
|
||||||
|
USER_mysql=root
|
||||||
|
PASSWORD_mysql=test
|
||||||
|
PORT_mysql=3307
|
||||||
|
ENGINE_mysql=mysql@dbgate-plugin-mysql
|
||||||
|
|
||||||
|
SINGLE_CONNECTION=mysql
|
||||||
|
SINGLE_DATABASE=Chinook
|
||||||
|
|
||||||
|
PERMISSIONS=files/charts/read
|
||||||
@@ -51,7 +51,9 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "env-cmd node src/index.js",
|
"start": "env-cmd node src/index.js",
|
||||||
"start:portal": "env-cmd -f .env-portal node src/index.js",
|
"start:portal": "env-cmd -f .env-portal node src/index.js",
|
||||||
"start:covid": "env-cmd -f .env-covid node src/index.js",
|
"start:singledb": "env-cmd -f .env-singledb node src/index.js",
|
||||||
|
"start:filedb": "env-cmd node src/index.js /home/jena/test/chinook/Chinook.db",
|
||||||
|
"start:singleconn": "env-cmd node src/index.js --server localhost --user root --port 3307 --engine mysql@dbgate-plugin-mysql --password test",
|
||||||
"ts": "tsc",
|
"ts": "tsc",
|
||||||
"build": "webpack"
|
"build": "webpack"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ const _ = require('lodash');
|
|||||||
|
|
||||||
const currentVersion = require('../currentVersion');
|
const currentVersion = require('../currentVersion');
|
||||||
const platformInfo = require('../utility/platformInfo');
|
const platformInfo = require('../utility/platformInfo');
|
||||||
|
const connections = require('../controllers/connections');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
settingsValue: {},
|
settingsValue: {},
|
||||||
@@ -21,30 +22,11 @@ module.exports = {
|
|||||||
|
|
||||||
get_meta: 'get',
|
get_meta: 'get',
|
||||||
async get() {
|
async get() {
|
||||||
// const toolbarButtons = process.env.TOOLBAR;
|
|
||||||
// const toolbar = toolbarButtons
|
|
||||||
// ? toolbarButtons.split(',').map((name) => ({
|
|
||||||
// name,
|
|
||||||
// icon: process.env[`ICON_${name}`],
|
|
||||||
// title: process.env[`TITLE_${name}`],
|
|
||||||
// page: process.env[`PAGE_${name}`],
|
|
||||||
// }))
|
|
||||||
// : null;
|
|
||||||
// const startupPages = process.env.STARTUP_PAGES ? process.env.STARTUP_PAGES.split(',') : [];
|
|
||||||
const permissions = process.env.PERMISSIONS ? process.env.PERMISSIONS.split(',') : null;
|
const permissions = process.env.PERMISSIONS ? process.env.PERMISSIONS.split(',') : null;
|
||||||
const singleDatabase =
|
|
||||||
process.env.SINGLE_CONNECTION && process.env.SINGLE_DATABASE
|
|
||||||
? {
|
|
||||||
conid: process.env.SINGLE_CONNECTION,
|
|
||||||
database: process.env.SINGLE_DATABASE,
|
|
||||||
}
|
|
||||||
: null;
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
runAsPortal: !!process.env.CONNECTIONS,
|
runAsPortal: !!connections.portalConnections,
|
||||||
// toolbar,
|
singleDatabase: connections.singleDatabase,
|
||||||
// startupPages,
|
|
||||||
singleDatabase,
|
|
||||||
permissions,
|
permissions,
|
||||||
...currentVersion,
|
...currentVersion,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -8,6 +8,32 @@ const socket = require('../utility/socket');
|
|||||||
const { encryptConnection } = require('../utility/crypting');
|
const { encryptConnection } = require('../utility/crypting');
|
||||||
const { handleProcessCommunication } = require('../utility/processComm');
|
const { handleProcessCommunication } = require('../utility/processComm');
|
||||||
|
|
||||||
|
function getNamedArgs() {
|
||||||
|
const res = {};
|
||||||
|
for (let i = 0; i < process.argv.length; i++) {
|
||||||
|
const name = process.argv[i];
|
||||||
|
if (name.startsWith('--')) {
|
||||||
|
let value = process.argv[i + 1];
|
||||||
|
if (value && value.startsWith('--')) value = null;
|
||||||
|
res[name.substring(2)] = value == null ? true : value;
|
||||||
|
i++;
|
||||||
|
} else {
|
||||||
|
if (name.endsWith('.db') || name.endsWith('.sqlite') || name.endsWith('.sqlite3')) {
|
||||||
|
res.databaseFile = name;
|
||||||
|
res.engine = 'sqlite@dbgate-plugin-sqlite';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getDatabaseFileLabel(databaseFile) {
|
||||||
|
if (!databaseFile) return databaseFile;
|
||||||
|
const m = databaseFile.match(/[\/]([^\/]+)$/);
|
||||||
|
if (m) return m[1];
|
||||||
|
return databaseFile;
|
||||||
|
}
|
||||||
|
|
||||||
function getPortalCollections() {
|
function getPortalCollections() {
|
||||||
if (process.env.CONNECTIONS) {
|
if (process.env.CONNECTIONS) {
|
||||||
return _.compact(process.env.CONNECTIONS.split(',')).map(id => ({
|
return _.compact(process.env.CONNECTIONS.split(',')).map(id => ({
|
||||||
@@ -24,13 +50,72 @@ function getPortalCollections() {
|
|||||||
displayName: process.env[`LABEL_${id}`],
|
displayName: process.env[`LABEL_${id}`],
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const args = getNamedArgs();
|
||||||
|
if (args.databaseFile) {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
_id: 'argv',
|
||||||
|
databaseFile: args.databaseFile,
|
||||||
|
singleDatabase: true,
|
||||||
|
defaultDatabase: getDatabaseFileLabel(args.databaseFile),
|
||||||
|
engine: args.engine,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
if (args.databaseUrl) {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
_id: 'argv',
|
||||||
|
useDatabaseUrl: true,
|
||||||
|
...args,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
if (args.server) {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
_id: 'argv',
|
||||||
|
...args,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const portalConnections = getPortalCollections();
|
const portalConnections = getPortalCollections();
|
||||||
|
|
||||||
|
function getSingleDatabase() {
|
||||||
|
if (process.env.SINGLE_CONNECTION && process.env.SINGLE_DATABASE) {
|
||||||
|
// @ts-ignore
|
||||||
|
const connection = portalConnections.find(x => x._id == process.env.SINGLE_CONNECTION);
|
||||||
|
return {
|
||||||
|
connection,
|
||||||
|
name: process.env.SINGLE_DATABASE,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
// @ts-ignore
|
||||||
|
const arg0 = (portalConnections || []).find(x => x._id == 'argv');
|
||||||
|
if (arg0) {
|
||||||
|
// @ts-ignore
|
||||||
|
if (arg0.singleDatabase) {
|
||||||
|
return {
|
||||||
|
connection: arg0,
|
||||||
|
// @ts-ignore
|
||||||
|
name: arg0.defaultDatabase,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const singleDatabase = getSingleDatabase();
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
datastore: null,
|
datastore: null,
|
||||||
opened: [],
|
opened: [],
|
||||||
|
singleDatabase,
|
||||||
|
portalConnections,
|
||||||
|
|
||||||
async _init() {
|
async _init() {
|
||||||
const dir = datadir();
|
const dir = datadir();
|
||||||
|
|||||||
@@ -120,6 +120,9 @@ let currentConfigValue = null;
|
|||||||
currentConfigStore.subscribe(value => {
|
currentConfigStore.subscribe(value => {
|
||||||
currentConfigValue = value;
|
currentConfigValue = value;
|
||||||
invalidateCommands();
|
invalidateCommands();
|
||||||
|
if (value.singleDatabase) {
|
||||||
|
currentDatabase.set(value.singleDatabase);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
export const getCurrentConfig = () => currentConfigValue;
|
export const getCurrentConfig = () => currentConfigValue;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { findEngineDriver } from 'dbgate-tools';
|
import { findEngineDriver } from 'dbgate-tools';
|
||||||
import { currentDatabase, extensions } from '../stores';
|
import { currentDatabase, extensions } from '../stores';
|
||||||
import { useConnectionInfo } from '../utility/metadataLoaders';
|
import { useConfig, useConnectionInfo } from '../utility/metadataLoaders';
|
||||||
|
|
||||||
import ConnectionList from './ConnectionList.svelte';
|
import ConnectionList from './ConnectionList.svelte';
|
||||||
import SqlObjectListWrapper from './SqlObjectListWrapper.svelte';
|
import SqlObjectListWrapper from './SqlObjectListWrapper.svelte';
|
||||||
@@ -12,12 +12,16 @@
|
|||||||
$: conid = $currentDatabase?.connection?._id;
|
$: conid = $currentDatabase?.connection?._id;
|
||||||
$: connection = useConnectionInfo({ conid });
|
$: connection = useConnectionInfo({ conid });
|
||||||
$: driver = findEngineDriver($connection, $extensions);
|
$: driver = findEngineDriver($connection, $extensions);
|
||||||
|
$: config = useConfig();
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<WidgetColumnBar>
|
<WidgetColumnBar>
|
||||||
|
{#if !$config?.singleDatabase}
|
||||||
<WidgetColumnBarItem title="Connections" name="connections" height="50%">
|
<WidgetColumnBarItem title="Connections" name="connections" height="50%">
|
||||||
<ConnectionList />
|
<ConnectionList />
|
||||||
</WidgetColumnBarItem>
|
</WidgetColumnBarItem>
|
||||||
|
{/if}
|
||||||
<WidgetColumnBarItem title={driver?.dialect?.nosql ? 'Collections' : 'Tables, views, functions'} name="dbObjects">
|
<WidgetColumnBarItem title={driver?.dialect?.nosql ? 'Collections' : 'Tables, views, functions'} name="dbObjects">
|
||||||
<SqlObjectListWrapper />
|
<SqlObjectListWrapper />
|
||||||
</WidgetColumnBarItem>
|
</WidgetColumnBarItem>
|
||||||
|
|||||||
Reference in New Issue
Block a user