fix(grid): recognize MySQL bit columns as boolean
This commit is contained in:
1 parent
3ecfb99f9a
commit
f9f21cbd88
2 files changed
+5
-2
No files matched your search
@@ -3,11 +3,14 @@ import type { DatabaseType } from "@/types/database";
|
|||||||
export const BOOLEAN_CHECKBOX_SIZE = 13;
|
export const BOOLEAN_CHECKBOX_SIZE = 13;
|
||||||
export const BOOLEAN_CELL_EDITOR_VALUES = ["true", "false"];
|
export const BOOLEAN_CELL_EDITOR_VALUES = ["true", "false"];
|
||||||
|
|
||||||
|
const MYSQL_BIT_BOOLEAN_DATABASE_TYPES = new Set<DatabaseType>(["mysql"]);
|
||||||
|
|
||||||
export function isBooleanColumnType(dataType: string | undefined, databaseType?: DatabaseType): boolean {
|
export function isBooleanColumnType(dataType: string | undefined, databaseType?: DatabaseType): boolean {
|
||||||
if (!dataType) return false;
|
if (!dataType) return false;
|
||||||
const normalized = dataType.trim().toLowerCase();
|
const normalized = dataType.trim().toLowerCase();
|
||||||
if (normalized === "boolean" || normalized === "bool") return true;
|
if (normalized === "boolean" || normalized === "bool") return true;
|
||||||
if (databaseType === "sqlserver") return normalized === "bit";
|
if (databaseType === "sqlserver") return normalized === "bit";
|
||||||
|
if (databaseType && MYSQL_BIT_BOOLEAN_DATABASE_TYPES.has(databaseType)) return normalized === "bit" || normalized === "bit(1)";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -22,6 +22,8 @@ test("detects boolean types using database semantics", () => {
|
|||||||
assert.equal(isBooleanColumnType("bit", "sqlserver"), true);
|
assert.equal(isBooleanColumnType("bit", "sqlserver"), true);
|
||||||
assert.equal(isBooleanColumnType("boolean", "mysql"), true);
|
assert.equal(isBooleanColumnType("boolean", "mysql"), true);
|
||||||
assert.equal(isBooleanColumnType(" BOOLEAN ", "postgres"), true);
|
assert.equal(isBooleanColumnType(" BOOLEAN ", "postgres"), true);
|
||||||
|
assert.equal(isBooleanColumnType("bit", "mysql"), true);
|
||||||
|
assert.equal(isBooleanColumnType("bit(1)", "mysql"), true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("does not treat database bit strings or MySQL integer aliases as boolean", () => {
|
test("does not treat database bit strings or MySQL integer aliases as boolean", () => {
|
||||||
@@ -31,8 +33,6 @@ test("does not treat database bit strings or MySQL integer aliases as boolean",
|
|||||||
assert.equal(isBooleanColumnType("varbit", "postgres"), false);
|
assert.equal(isBooleanColumnType("varbit", "postgres"), false);
|
||||||
assert.equal(isBooleanColumnType("bit", "opengauss"), false);
|
assert.equal(isBooleanColumnType("bit", "opengauss"), false);
|
||||||
assert.equal(isBooleanColumnType("bit", undefined), false);
|
assert.equal(isBooleanColumnType("bit", undefined), false);
|
||||||
assert.equal(isBooleanColumnType("bit", "mysql"), false);
|
|
||||||
assert.equal(isBooleanColumnType("bit(1)", "mysql"), false);
|
|
||||||
assert.equal(isBooleanColumnType("bit(8)", "mysql"), false);
|
assert.equal(isBooleanColumnType("bit(8)", "mysql"), false);
|
||||||
assert.equal(isBooleanColumnType("tinyint(1)", "mysql"), false);
|
assert.equal(isBooleanColumnType("tinyint(1)", "mysql"), false);
|
||||||
assert.equal(isBooleanColumnType(undefined, "mysql"), false);
|
assert.equal(isBooleanColumnType(undefined, "mysql"), false);
|
||||||
|
|||||||
Reference in new issue
Block a user