|
| 1 | +import * as vscode from 'vscode'; |
| 2 | +import { isCanary, isNewQueryRunExperienceEnabled } from '../config'; |
| 3 | +import { logger } from '../logging'; |
| 4 | +import { DisposableObject } from '../pure/disposable-object'; |
| 5 | +import { DbConfigStore } from './db-config-store'; |
| 6 | +import { DbManager } from './db-manager'; |
| 7 | +import { DbPanel } from './ui/db-panel'; |
| 8 | + |
| 9 | +export class DbModule extends DisposableObject { |
| 10 | + public async initialize( |
| 11 | + extensionContext: vscode.ExtensionContext |
| 12 | + ): Promise<void> { |
| 13 | + if (extensionContext.extensionMode !== vscode.ExtensionMode.Development || |
| 14 | + !isCanary() || |
| 15 | + !isNewQueryRunExperienceEnabled()) { |
| 16 | + // Currently, we only want to expose the new database panel when we |
| 17 | + // are in development and canary mode and the developer has enabled the |
| 18 | + // new query run experience. |
| 19 | + return; |
| 20 | + } |
| 21 | + |
| 22 | + void logger.log('Initializing database module'); |
| 23 | + |
| 24 | + const storagePath = extensionContext.storageUri?.fsPath || extensionContext.globalStorageUri.fsPath; |
| 25 | + const dbConfigStore = new DbConfigStore(storagePath); |
| 26 | + await dbConfigStore.initialize(); |
| 27 | + |
| 28 | + const dbManager = new DbManager(dbConfigStore); |
| 29 | + dbManager.loadDatabases(); |
| 30 | + |
| 31 | + const dbPanel = new DbPanel(dbManager); |
| 32 | + |
| 33 | + this.push(dbPanel); |
| 34 | + this.push(dbConfigStore); |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +export async function initializeDbModule( |
| 39 | + extensionContext: vscode.ExtensionContext |
| 40 | +): Promise<DbModule> { |
| 41 | + const dbModule = new DbModule(); |
| 42 | + await dbModule.initialize(extensionContext); |
| 43 | + return dbModule; |
| 44 | +} |
0 commit comments