Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CSV export format options #1309

Merged
merged 2 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions packages/extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,43 @@
"default": "prompt",
"description": "Default mode for results Open command."
},
"sqltools.csvExport.delimiter": {
"type": "string",
"minLength": 1,
"default": ",",
"description": "CSV field delimiter, one character only."
},
"sqltools.csvExport.header": {
"type": "boolean",
"default": true,
"description": "Display the column names on the first line."
},
"sqltools.csvExport.quote": {
"type": "string",
"default": "\"",
"description": "The quote characters, an empty value will preserve the original field."
},
"sqltools.csvExport.quoted": {
"type": "boolean",
"default": true,
"description": "Quote all the non-empty fields even if not required."
},
"sqltools.csvExport.quoted_empty": {
"type": "boolean",
"default": true,
"markdownDescription": "Quote empty fields and overrides `#sqltools.csvExport.quoted_string#` on empty strings when defined."
},
"sqltools.csvExport.quoted_string": {
"type": "boolean",
"default": false,
flowrean marked this conversation as resolved.
Show resolved Hide resolved
"description": "Quote all fields of type string even if not required."
},
"sqltools.csvExport.record_delimiter": {
"type": "string",
"minLength": 1,
"default": "unix",
"markdownDescription": "String used to delimit record rows or a special value: `unix` (`\\n`), `mac` (`\\r`), `windows` (`\\r\\n`), `ascii` (`\\u001e`), or `unicode` (`\\u2028`)."
},
"sqltools.useNodeRuntime": {
"type": [
"null",
Expand Down
4 changes: 1 addition & 3 deletions packages/plugins/connection-manager/language-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ export default class ConnectionManagerPlugin implements ILanguageServerPlugin {
? JSON.stringify(results, null, 2)
: csvStringify(results, {
columns: cols,
header: true,
quoted_string: true,
quoted_empty: true,
...ConfigRO.csvExport,
flowrean marked this conversation as resolved.
Show resolved Hide resolved
});
};

Expand Down
59 changes: 59 additions & 0 deletions packages/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,58 @@ export interface IResultsOptions {
};
}

export interface ICSVExportOptions {
/**
* Field delimiter
* @type {string}
* @default ','
* @memberof ICSVExportOptions
*/
delimiter?: string;
/**
* Include header line
* @type {boolean}
* @default true
* @memberof ICSVExportOptions
*/
header?: boolean;
/**
* Quote characters
* @type {string}
* @default '"'
* @memberof ICSVExportOptions
*/
quote?: string;
/**
* Quote all non-empty fields
* @type {boolean}
* @default true
* @memberof ICSVExportOptions
*/
quoted?: boolean;
/**
* Quote empty fields
* @type {boolean}
* @default true
* @memberof ICSVExportOptions
*/
quoted_empty?: boolean;
/**
* Quote all string fields
* @type {boolean}
* @default false
flowrean marked this conversation as resolved.
Show resolved Hide resolved
* @memberof ICSVExportOptions
*/
quoted_string?: boolean;
/**
* Record delimiter or special value
* @type {string}
* @default 'unix'
* @memberof ICSVExportOptions
*/
record_delimiter?: string;
}

export interface ISettings {
/**
* Disable new release notifications.
Expand Down Expand Up @@ -607,6 +659,13 @@ export interface ISettings {
*/
defaultOpenType?: 'prompt' | 'csv' | 'json';

/**
* CSV export format options
* @type {ICSVExportOptions}
* @memberof ISettings
*/
csvExport?: ICSVExportOptions;

/**
* Enable node runtime usage.
* @default false
Expand Down