mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
SQL Operations Studio Public Preview 1 (0.23) release source code
This commit is contained in:
18
extensions/mssql/client/src/serialize/iserialization.ts
Normal file
18
extensions/mssql/client/src/serialize/iserialization.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import { SaveResultsInfo } from '../models/contracts';
|
||||
import * as data from 'data';
|
||||
|
||||
/**
|
||||
* Serializer for saving results into a different format
|
||||
*
|
||||
* @export
|
||||
* @interface ISerialization
|
||||
*/
|
||||
export interface ISerialization {
|
||||
saveAs(saveFormat: string, savePath: string, results: string, appendToFile: boolean): Promise<data.SaveResultRequestResult>;
|
||||
}
|
||||
41
extensions/mssql/client/src/serialize/serialization.ts
Normal file
41
extensions/mssql/client/src/serialize/serialization.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import * as Contracts from '../models/contracts';
|
||||
import { ISerialization } from './iserialization';
|
||||
import { SqlToolsServiceClient } from 'extensions-modules';
|
||||
import * as data from 'data';
|
||||
import { LanguageClient } from 'dataprotocol-client';
|
||||
|
||||
/**
|
||||
* Implements serializer for query results
|
||||
*/
|
||||
export class Serialization implements ISerialization {
|
||||
|
||||
constructor(private _client?: SqlToolsServiceClient, private _languageClient?: LanguageClient) {
|
||||
if (!this._client) {
|
||||
this._client = SqlToolsServiceClient.instance;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves results as a specified path
|
||||
*
|
||||
* @param {string} credentialId the ID uniquely identifying this credential
|
||||
* @returns {Promise<ISaveResultsInfo>} Promise that resolved to the credential, or undefined if not found
|
||||
*/
|
||||
public saveAs(saveFormat: string, savePath: string, results: string, appendToFile: boolean): Promise<data.SaveResultRequestResult> {
|
||||
let self = this;
|
||||
let resultsInfo: Contracts.SaveResultsInfo = new Contracts.SaveResultsInfo(saveFormat, savePath, results, appendToFile);
|
||||
return new Promise<data.SaveResultRequestResult>( (resolve, reject) => {
|
||||
self._client
|
||||
.sendRequest(Contracts.SaveAsRequest.type, resultsInfo, this._languageClient)
|
||||
.then(result => {
|
||||
resolve(<data.SaveResultRequestResult>result);
|
||||
}, err => reject(err));
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user