Skip to content

Commit

Permalink
Add CSV export format options (#1309)
Browse files Browse the repository at this point in the history
  • Loading branch information
flowrean authored Apr 11, 2024
1 parent 0491cdb commit 2a42731
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 3 deletions.
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": false,
"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": true,
"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 @@ -62,10 +62,8 @@ export default class ConnectionManagerPlugin implements ILanguageServerPlugin {
return formatType === 'json'
? JSON.stringify(results, null, 2)
: csvStringify(results, {
...ConfigRO.csvExport,
columns: cols,
header: true,
quoted_string: true,
quoted_empty: true,
});
};

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 false
* @memberof ICSVExportOptions
*/
quoted?: boolean;
/**
* Quote empty fields
* @type {boolean}
* @default true
* @memberof ICSVExportOptions
*/
quoted_empty?: boolean;
/**
* Quote all string fields
* @type {boolean}
* @default true
* @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

0 comments on commit 2a42731

Please sign in to comment.