mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-28 19:56:00 +00:00
refactor:dialect.nosql=>driver.databaseEngineTypes
This commit is contained in:
@@ -240,6 +240,7 @@ module.exports = {
|
|||||||
|
|
||||||
get_meta: true,
|
get_meta: true,
|
||||||
async get({ conid }) {
|
async get({ conid }) {
|
||||||
|
if (!conid) return null;
|
||||||
if (portalConnections) return portalConnections.find(x => x._id == conid) || null;
|
if (portalConnections) return portalConnections.find(x => x._id == conid) || null;
|
||||||
const res = await this.datastore.get(conid);
|
const res = await this.datastore.get(conid);
|
||||||
return res || null;
|
return res || null;
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ async function tableReader({ connection, pureName, schemaName }) {
|
|||||||
|
|
||||||
const fullName = { pureName, schemaName };
|
const fullName = { pureName, schemaName };
|
||||||
|
|
||||||
if (driver.dialect.nosql) {
|
if (driver.databaseEngineTypes.includes('document')) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
console.log(`Reading collection ${fullNameToString(fullName)}`);
|
console.log(`Reading collection ${fullNameToString(fullName)}`);
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ export function createBulkInsertStreamBase(driver, stream, pool, name, options):
|
|||||||
writable.buffer = [];
|
writable.buffer = [];
|
||||||
writable.structure = null;
|
writable.structure = null;
|
||||||
writable.columnNames = null;
|
writable.columnNames = null;
|
||||||
writable.requireFixedStructure = !driver.dialect.nosql;
|
writable.requireFixedStructure = driver.databaseEngineTypes.includes('sql');
|
||||||
|
|
||||||
writable.addRow = async row => {
|
writable.addRow = async row => {
|
||||||
if (writable.structure) {
|
if (writable.structure) {
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ export const driverBase = {
|
|||||||
analyserClass: null,
|
analyserClass: null,
|
||||||
dumperClass: SqlDumper,
|
dumperClass: SqlDumper,
|
||||||
dialect,
|
dialect,
|
||||||
|
databaseEngineTypes: ['sql'],
|
||||||
|
|
||||||
async analyseFull(pool, version) {
|
async analyseFull(pool, version) {
|
||||||
const analyser = new this.analyserClass(pool, this, version);
|
const analyser = new this.analyserClass(pool, this, version);
|
||||||
@@ -45,7 +46,7 @@ export const driverBase = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
getNewObjectTemplates() {
|
getNewObjectTemplates() {
|
||||||
if (!this.dialect?.nosql) {
|
if (this.databaseEngineTypes.includes('sql')) {
|
||||||
return [{ label: 'New view', sql: 'CREATE VIEW myview\nAS\nSELECT * FROM table1' }];
|
return [{ label: 'New view', sql: 'CREATE VIEW myview\nAS\nSELECT * FROM table1' }];
|
||||||
}
|
}
|
||||||
return [];
|
return [];
|
||||||
|
|||||||
1
packages/types/dialect.d.ts
vendored
1
packages/types/dialect.d.ts
vendored
@@ -10,7 +10,6 @@ export interface SqlDialect {
|
|||||||
explicitDropConstraint?: boolean;
|
explicitDropConstraint?: boolean;
|
||||||
anonymousPrimaryKey?: boolean;
|
anonymousPrimaryKey?: boolean;
|
||||||
enableConstraintsPerTable?: boolean;
|
enableConstraintsPerTable?: boolean;
|
||||||
nosql?: boolean; // mongo
|
|
||||||
|
|
||||||
dropColumnDependencies?: string[];
|
dropColumnDependencies?: string[];
|
||||||
changeColumnDependencies?: string[];
|
changeColumnDependencies?: string[];
|
||||||
|
|||||||
1
packages/types/engines.d.ts
vendored
1
packages/types/engines.d.ts
vendored
@@ -46,6 +46,7 @@ export interface EngineDriver {
|
|||||||
engine: string;
|
engine: string;
|
||||||
title: string;
|
title: string;
|
||||||
defaultPort?: number;
|
defaultPort?: number;
|
||||||
|
databaseEngineTypes: string[];
|
||||||
supportsDatabaseUrl?: boolean;
|
supportsDatabaseUrl?: boolean;
|
||||||
isElectronOnly?: boolean;
|
isElectronOnly?: boolean;
|
||||||
showConnectionField?: (field: string, values: any) => boolean;
|
showConnectionField?: (field: string, values: any) => boolean;
|
||||||
|
|||||||
@@ -174,8 +174,8 @@
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
{ onClick: handleNewQuery, text: 'New query', isNewQuery: true },
|
{ onClick: handleNewQuery, text: 'New query', isNewQuery: true },
|
||||||
!driver?.dialect?.nosql && { onClick: handleNewTable, text: 'New table' },
|
driver?.databaseEngineTypes?.includes('sql') && { onClick: handleNewTable, text: 'New table' },
|
||||||
driver?.dialect?.nosql && { onClick: handleNewCollection, text: 'New collection' },
|
driver?.databaseEngineTypes?.includes('document') && { onClick: handleNewCollection, text: 'New collection' },
|
||||||
{ divider: true },
|
{ divider: true },
|
||||||
{ onClick: handleImport, text: 'Import' },
|
{ onClick: handleImport, text: 'Import' },
|
||||||
{ onClick: handleExport, text: 'Export' },
|
{ onClick: handleExport, text: 'Export' },
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ registerCommand({
|
|||||||
toolbarName: 'New table',
|
toolbarName: 'New table',
|
||||||
testEnabled: () => {
|
testEnabled: () => {
|
||||||
const driver = findEngineDriver(get(currentDatabase)?.connection, getExtensions());
|
const driver = findEngineDriver(get(currentDatabase)?.connection, getExtensions());
|
||||||
return !!get(currentDatabase) && !driver?.dialect?.nosql;
|
return !!get(currentDatabase) && driver?.databaseEngineTypes?.includes('sql');
|
||||||
},
|
},
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
const $currentDatabase = get(currentDatabase);
|
const $currentDatabase = get(currentDatabase);
|
||||||
@@ -196,7 +196,7 @@ registerCommand({
|
|||||||
toolbarName: 'New collection',
|
toolbarName: 'New collection',
|
||||||
testEnabled: () => {
|
testEnabled: () => {
|
||||||
const driver = findEngineDriver(get(currentDatabase)?.connection, getExtensions());
|
const driver = findEngineDriver(get(currentDatabase)?.connection, getExtensions());
|
||||||
return !!get(currentDatabase) && driver?.dialect?.nosql;
|
return !!get(currentDatabase) && driver?.databaseEngineTypes?.includes('document');
|
||||||
},
|
},
|
||||||
onClick: async () => {
|
onClick: async () => {
|
||||||
const $currentDatabase = get(currentDatabase);
|
const $currentDatabase = get(currentDatabase);
|
||||||
|
|||||||
@@ -266,7 +266,7 @@
|
|||||||
class:isOk
|
class:isOk
|
||||||
placeholder="Filter"
|
placeholder="Filter"
|
||||||
/>
|
/>
|
||||||
{#if conid && database && driver && !driver?.dialect?.nosql}
|
{#if conid && database && driver && driver?.databaseEngineTypes?.includes('sql')}
|
||||||
{#if foreignKey}
|
{#if foreignKey}
|
||||||
<InlineButton on:click={handleShowDictionary} narrow square>
|
<InlineButton on:click={handleShowDictionary} narrow square>
|
||||||
<FontIcon icon="icon dots-horizontal" />
|
<FontIcon icon="icon dots-horizontal" />
|
||||||
|
|||||||
@@ -124,7 +124,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function isSqlEditor() {
|
export function isSqlEditor() {
|
||||||
return !driver?.dialect?.nosql;
|
return driver?.databaseEngineTypes?.includes('sql');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function canKill() {
|
export function canKill() {
|
||||||
@@ -281,7 +281,7 @@
|
|||||||
<ToolStripContainer>
|
<ToolStripContainer>
|
||||||
<VerticalSplitter isSplitter={visibleResultTabs}>
|
<VerticalSplitter isSplitter={visibleResultTabs}>
|
||||||
<svelte:fragment slot="1">
|
<svelte:fragment slot="1">
|
||||||
{#if driver?.dialect?.nosql}
|
{#if driver?.databaseEngineTypes?.includes('document')}
|
||||||
<AceEditor
|
<AceEditor
|
||||||
mode="javascript"
|
mode="javascript"
|
||||||
value={$editorState.value || ''}
|
value={$editorState.value || ''}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@
|
|||||||
];
|
];
|
||||||
|
|
||||||
function autodetect(selection) {
|
function autodetect(selection) {
|
||||||
if (selection[0]?.engine?.dialect?.nosql) {
|
if (selection[0]?.engine?.databaseEngineTypes?.includes('document')) {
|
||||||
return 'jsonRow';
|
return 'jsonRow';
|
||||||
}
|
}
|
||||||
const value = selection.length == 1 ? selection[0].value : null;
|
const value = selection.length == 1 ? selection[0].value : null;
|
||||||
|
|||||||
@@ -5,10 +5,12 @@
|
|||||||
|
|
||||||
import ConnectionList from './ConnectionList.svelte';
|
import ConnectionList from './ConnectionList.svelte';
|
||||||
import PinnedObjectsList from './PinnedObjectsList.svelte';
|
import PinnedObjectsList from './PinnedObjectsList.svelte';
|
||||||
import SqlObjectListWrapper from './SqlObjectListWrapper.svelte';
|
import ErrorInfo from '../elements/ErrorInfo.svelte';
|
||||||
|
import WidgetsInnerContainer from './WidgetsInnerContainer.svelte';
|
||||||
|
|
||||||
import WidgetColumnBar from './WidgetColumnBar.svelte';
|
import WidgetColumnBar from './WidgetColumnBar.svelte';
|
||||||
import WidgetColumnBarItem from './WidgetColumnBarItem.svelte';
|
import WidgetColumnBarItem from './WidgetColumnBarItem.svelte';
|
||||||
|
import SqlObjectList from './SqlObjectList.svelte';
|
||||||
|
|
||||||
export let hidden = false;
|
export let hidden = false;
|
||||||
|
|
||||||
@@ -16,6 +18,12 @@
|
|||||||
$: connection = useConnectionInfo({ conid });
|
$: connection = useConnectionInfo({ conid });
|
||||||
$: driver = findEngineDriver($connection, $extensions);
|
$: driver = findEngineDriver($connection, $extensions);
|
||||||
$: config = useConfig();
|
$: config = useConfig();
|
||||||
|
$: singleDatabase = $currentDatabase?.connection?.singleDatabase;
|
||||||
|
$: database = $currentDatabase?.name;
|
||||||
|
|
||||||
|
$: console.log('CONID', conid);
|
||||||
|
$: console.log('CONN', $connection);
|
||||||
|
$: console.log('DRIVER', driver);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<WidgetColumnBar {hidden}>
|
<WidgetColumnBar {hidden}>
|
||||||
@@ -34,11 +42,24 @@
|
|||||||
>
|
>
|
||||||
<PinnedObjectsList />
|
<PinnedObjectsList />
|
||||||
</WidgetColumnBarItem>
|
</WidgetColumnBarItem>
|
||||||
|
|
||||||
|
{#if conid && (database || singleDatabase)}
|
||||||
|
{#if driver?.databaseEngineTypes?.includes('sql') || driver?.databaseEngineTypes?.includes('document')}
|
||||||
<WidgetColumnBarItem
|
<WidgetColumnBarItem
|
||||||
title={driver?.dialect?.nosql ? 'Collections' : 'Tables, views, functions'}
|
title={driver?.databaseEngineTypes?.includes('document') ? 'Collections' : 'Tables, views, functions'}
|
||||||
name="dbObjects"
|
name="dbObjects"
|
||||||
storageName="dbObjectsWidget"
|
storageName="dbObjectsWidget"
|
||||||
>
|
>
|
||||||
<SqlObjectListWrapper />
|
<SqlObjectList {conid} {database} />
|
||||||
</WidgetColumnBarItem>
|
</WidgetColumnBarItem>
|
||||||
|
{:else if driver?.databaseEngineTypes?.includes('keyvalue')}
|
||||||
|
<WidgetColumnBarItem title={'Keys'} name="dbObjects" storageName="dbObjectsWidget" />
|
||||||
|
{/if}
|
||||||
|
{:else}
|
||||||
|
<WidgetColumnBarItem title="Database content" name="dbObjects" storageName="dbObjectsWidget">
|
||||||
|
<WidgetsInnerContainer>
|
||||||
|
<ErrorInfo message="Database not selected" icon="img alert" />
|
||||||
|
</WidgetsInnerContainer>
|
||||||
|
</WidgetColumnBarItem>
|
||||||
|
{/if}
|
||||||
</WidgetColumnBar>
|
</WidgetColumnBar>
|
||||||
|
|||||||
@@ -67,9 +67,10 @@
|
|||||||
|
|
||||||
function createAddMenu() {
|
function createAddMenu() {
|
||||||
const res = [];
|
const res = [];
|
||||||
if (driver?.dialect?.nosql) {
|
if (driver?.databaseEngineTypes?.includes('document')) {
|
||||||
res.push({ command: 'new.collection' });
|
res.push({ command: 'new.collection' });
|
||||||
} else {
|
}
|
||||||
|
if (driver?.databaseEngineTypes?.includes('sql')) {
|
||||||
res.push({ command: 'new.table' });
|
res.push({ command: 'new.table' });
|
||||||
}
|
}
|
||||||
if (driver)
|
if (driver)
|
||||||
@@ -100,11 +101,11 @@
|
|||||||
/>
|
/>
|
||||||
<div class="m-1" />
|
<div class="m-1" />
|
||||||
<InlineButton on:click={handleRefreshDatabase}>Refresh</InlineButton>
|
<InlineButton on:click={handleRefreshDatabase}>Refresh</InlineButton>
|
||||||
{#if !driver?.dialect?.nosql}
|
{#if driver?.databaseEngineTypes?.includes('sql')}
|
||||||
<div class="m-1" />
|
<div class="m-1" />
|
||||||
<InlineButton on:click={() => runCommand('new.table')}>New table</InlineButton>
|
<InlineButton on:click={() => runCommand('new.table')}>New table</InlineButton>
|
||||||
{/if}
|
{/if}
|
||||||
{#if driver?.dialect?.nosql}
|
{#if driver?.databaseEngineTypes?.includes('document')}
|
||||||
<div class="m-1" />
|
<div class="m-1" />
|
||||||
<InlineButton on:click={() => runCommand('new.collection')}>New collection</InlineButton>
|
<InlineButton on:click={() => runCommand('new.collection')}>New collection</InlineButton>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ const dialect = {
|
|||||||
offsetFetchRangeSyntax: true,
|
offsetFetchRangeSyntax: true,
|
||||||
stringEscapeChar: "'",
|
stringEscapeChar: "'",
|
||||||
fallbackDataType: 'nvarchar(max)',
|
fallbackDataType: 'nvarchar(max)',
|
||||||
nosql: true,
|
|
||||||
quoteIdentifier(s) {
|
quoteIdentifier(s) {
|
||||||
return `[${s}]`;
|
return `[${s}]`;
|
||||||
},
|
},
|
||||||
@@ -26,6 +25,7 @@ const dialect = {
|
|||||||
const driver = {
|
const driver = {
|
||||||
...driverBase,
|
...driverBase,
|
||||||
dumperClass: Dumper,
|
dumperClass: Dumper,
|
||||||
|
databaseEngineTypes: ['document'],
|
||||||
dialect,
|
dialect,
|
||||||
engine: 'mongo@dbgate-plugin-mongo',
|
engine: 'mongo@dbgate-plugin-mongo',
|
||||||
title: 'MongoDB',
|
title: 'MongoDB',
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ const driver = {
|
|||||||
engine: 'redis@dbgate-plugin-redis',
|
engine: 'redis@dbgate-plugin-redis',
|
||||||
title: 'Redis',
|
title: 'Redis',
|
||||||
defaultPort: 6379,
|
defaultPort: 6379,
|
||||||
|
databaseEngineTypes: ['keyvalue'],
|
||||||
|
|
||||||
showConnectionField: (field, values) => {
|
showConnectionField: (field, values) => {
|
||||||
return ['server', 'port', 'password'].includes(field);
|
return ['server', 'port', 'password'].includes(field);
|
||||||
|
|||||||
Reference in New Issue
Block a user