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