diff --git a/connection.schema.json b/connection.schema.json index 4565f31..86cb0f4 100644 --- a/connection.schema.json +++ b/connection.schema.json @@ -8,13 +8,13 @@ "minLength": 1 }, "instance": { - "title": "Cloud Spanner Instance ID", + "title": "Spanner Instance ID", "type": "string", "minLength": 2, "maxLength": 64 }, "database": { - "title": "Cloud Spanner Database ID", + "title": "Spanner Database ID", "type": "string", "minLength": 2, "maxLength": 30 @@ -23,6 +23,18 @@ "title": "Credentials Key File (optional)", "$comment": "Specifying a credentials file is optional. If no file is specified, the default Google credentials on this environment will be used", "type": "string" + }, + "connectToEmulator": { + "title": "Connect to emulator", + "type": "boolean" + }, + "emulatorHost": { + "title": "Emulator host", + "type": "string" + }, + "emulatorPort": { + "title": "Emulator port", + "type": "string" } }, "required": [ diff --git a/package.json b/package.json index c97b40a..0c1efe6 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "google-cloud-spanner-driver", "displayName": "Google Cloud Spanner Driver", "description": "Google Cloud Spanner Driver for SQLTools", - "version": "0.1.0", + "version": "0.3.0", "engines": { "vscode": "^1.42.0" }, diff --git a/src/ls/driver.ts b/src/ls/driver.ts index b9371d4..d682355 100644 --- a/src/ls/driver.ts +++ b/src/ls/driver.ts @@ -18,6 +18,7 @@ import queries from './queries'; import { IConnectionDriver, MConnectionExplorer, NSDatabase, ContextValue, Arg0 } from '@sqltools/types'; import { v4 as generateId } from 'uuid'; import {Database, Spanner, SpannerOptions} from '@google-cloud/spanner'; +import {grpc} from 'google-gax'; import { RunUpdateResponse } from '@google-cloud/spanner/build/src/transaction'; import { SpannerQueryParser, StatementType } from './parser'; @@ -38,12 +39,41 @@ export default class CloudSpannerDriver extends AbstractDriver { const db = await this.open(); @@ -75,6 +105,8 @@ export default class CloudSpannerDriver extends AbstractDriver { + const [operation] = await db.updateSchema({statements: [sql]}); + await new Promise(function(resolve, reject) { + operation.on("complete", resolve); + operation.on("error", reject); + }); + return { + cols: ['Result'], + connId: this.getId(), + messages: [{ date: new Date(), message: `DDL statement executed successfully`}], + results: [{Result: 'Success'}], + query: sql, + requestId: opt.requestId, + resultId: generateId(), + }; + } + private mapRows(rows: any[], columns: string[]): any[] { return rows.map((r) => { columns.forEach((col) => { diff --git a/ui.schema.json b/ui.schema.json index 586ca84..d66bbfb 100644 --- a/ui.schema.json +++ b/ui.schema.json @@ -1,4 +1,7 @@ { - "ui:order": ["project", "instance", "database", "credentials"], - "credentials": { "ui:widget": "file" } + "ui:order": ["project", "instance", "database", "credentialsKeyFile", "useLocalEmulator"], + "credentialsKeyFile": { "ui:widget": "file", "ui:help": "Credentials file to use to connect to Cloud Spanner. This is only required if the connection should use other credentials than the default credentials of the environment. Ignored for emulator connections." }, + "connectToEmulator": { "ui:help": "Connects to a Spanner emulator instance instead of to Google Cloud. The instance and database specified in the settings above will automatically be created on the emulator if these do not already exist. The emulator must have been started before you can connect to it." }, + "emulatorHost": { "ui:help": "The host name where the emulator is running. Defaults to 'localhost', and is only required if 'Connect to emulator' is enabled and the emulator is not running on localhost." }, + "emulatorPort": { "ui:help": "The port number where the emulator is running. Defaults to '9010', and is only required if 'Connect to emulator' is enabled and the emulator is not running on port 9010 (gRPC)." } } \ No newline at end of file