feat(tabs): support naming and renaming result tabs
This commit is contained in:
16 files changed
+172
-4
No files matched your search
@@ -12,6 +12,12 @@ describe("queryResultNameFromPreamble", () => {
|
||||
expect(queryResultNameFromPreamble("-- older comment\n/*\n-- Name: block\n*/\n-- 当前时间\n")).toBe("当前时间");
|
||||
expect(queryResultNameFromPreamble("/* -- block only */\n-- \n")).toBeUndefined();
|
||||
});
|
||||
|
||||
it("accepts hash comments for MySQL without treating them as portable SQL comments", () => {
|
||||
expect(queryResultNameFromPreamble("# MySQL report\nSELECT 1", { databaseType: "mysql" })).toBe("MySQL report");
|
||||
expect(queryResultNameFromPreamble("# temporary table\nSELECT 1", { databaseType: "sqlserver" })).toBeUndefined();
|
||||
expect(queryResultNameFromPreamble("# portable comment\nSELECT 1")).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("queryResultSourceLabel", () => {
|
||||
|
||||
@@ -7,12 +7,16 @@ export interface QueryResultSourceLabelOptions {
|
||||
databaseType?: DatabaseType;
|
||||
}
|
||||
|
||||
export function queryResultNameFromPreamble(preamble: string): string | undefined {
|
||||
const HASH_COMMENT_DATABASE_TYPES = new Set<DatabaseType>(["mysql"]);
|
||||
|
||||
export function queryResultNameFromPreamble(preamble: string, options: Pick<QueryResultSourceLabelOptions, "databaseType"> = {}): string | undefined {
|
||||
let name: string | undefined;
|
||||
let fallback: string | undefined;
|
||||
const withoutBlockComments = preamble.replace(/\/\*[\s\S]*?\*\//g, "");
|
||||
for (const line of withoutBlockComments.split(/\r?\n/)) {
|
||||
const comment = line.match(/^\s*--\s*(.*)$/)?.[1]?.trim();
|
||||
const commentMatch = line.match(/^\s*(--|#)\s*(.*)$/);
|
||||
if (commentMatch?.[1] === "#" && !HASH_COMMENT_DATABASE_TYPES.has(options.databaseType!)) continue;
|
||||
const comment = commentMatch?.[2]?.trim();
|
||||
if (!comment) continue;
|
||||
|
||||
const nameMatch = comment.match(/^name\s*:\s*(.*)$/i);
|
||||
|
||||
Reference in new issue
Block a user