Skip to content

Commit

Permalink
discontinue type mismatch support (#219)
Browse files Browse the repository at this point in the history
  • Loading branch information
invisal authored Dec 22, 2024
1 parent 7f21faf commit 1cd1a18
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 61 deletions.
1 change: 0 additions & 1 deletion src/components/gui/table-cell/create-editable-cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ export default function createEditableCell<T = unknown>({
focus={focus}
isChanged={isChanged}
align={align}
mismatchDetection={state.mismatchDetection}
onDoubleClick={() => {
if (
typeof editValue === "string" &&
Expand Down
49 changes: 7 additions & 42 deletions src/components/gui/table-cell/generic-cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,10 @@ import {
import {
DatabaseResultSet,
DatabaseValue,
describeTableColumnType,
TableColumnDataType,
} from "@/drivers/base-driver";
import { useDatabaseDriver } from "@/context/driver-provider";
import { convertDatabaseValueToString } from "@/drivers/sqlite/sql-helper";
import {
Tooltip,
TooltipContent,
TooltipTrigger,
} from "@/components/ui/tooltip";

interface TableCellProps<T = unknown> {
align?: "left" | "right";
Expand All @@ -32,7 +26,6 @@ interface TableCellProps<T = unknown> {
onFocus?: () => void;
onDoubleClick?: () => void;
header: OptimizeTableHeaderWithIndexProps;
mismatchDetection?: boolean;
}

interface SneakpeakProps {
Expand Down Expand Up @@ -184,14 +177,12 @@ function BlobCellValue({

export default function GenericCell({
value,
valueType,
onFocus,
isChanged,
focus,
align,
onDoubleClick,
header,
mismatchDetection,
}: TableCellProps) {
const className = cn(
"libsql-cell font-mono flex",
Expand Down Expand Up @@ -292,39 +283,13 @@ export default function GenericCell({
}, [value, textBaseStyle, isChanged, header]);

return (
<div className="relative">
{mismatchDetection &&
valueType &&
header.dataType &&
valueType !== header.dataType && (
<Tooltip>
<TooltipTrigger asChild>
<div className="w-0 h-0 border-transparent border-r-8 border-b-8 border-r-red-400 dark:border-r-red-600 absolute right-0 top-0"></div>
</TooltipTrigger>
<TooltipContent>
<strong>Mismatched type:</strong>
<ul>
<li>
<strong>- Expected by column:</strong>{" "}
<code>{describeTableColumnType(header.dataType)}</code>
</li>
<li>
<strong>- But stored as:</strong>{" "}
<code>{describeTableColumnType(valueType)}</code>
</li>
</ul>
</TooltipContent>
</Tooltip>
)}

<div
className={className}
onMouseDown={onFocus}
onDoubleClick={onDoubleClick}
>
<div className="flex flex-grow overflow-hidden">{content}</div>
{fkContent}
</div>
<div
className={className}
onMouseDown={onFocus}
onDoubleClick={onDoubleClick}
>
<div className="flex flex-grow overflow-hidden">{content}</div>
{fkContent}
</div>
);
}
1 change: 0 additions & 1 deletion src/components/gui/table-optimized/OptimizeTableState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export default class OptimizeTableState {

protected editMode = false;
protected readOnlyMode = false;
public mismatchDetection = false;
protected container: HTMLDivElement | null = null;

protected changeCallback: TableChangeEventCallback[] = [];
Expand Down
1 change: 0 additions & 1 deletion src/components/gui/tabs-result/query-result-tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export default function QueryResult({
result.result
);
state.setReadOnlyMode(true);
state.mismatchDetection = databaseDriver.getFlags().mismatchDetection;

return state;
}, [result, databaseDriver]);
Expand Down
3 changes: 1 addition & 2 deletions src/components/gui/tabs/table-data-tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ export default function TableDataWindow({
dataResult,
schemaResult
);
tableState.mismatchDetection =
databaseDriver.getFlags().mismatchDetection;

setData(tableState);

setStat(dataResult.stat);
Expand Down
3 changes: 1 addition & 2 deletions src/drivers/base-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export interface DatabaseTableSchema {
type?: "table" | "view";
withoutRowId?: boolean;
strict?: boolean;
stats?: DatabaseTableSchemaStats
stats?: DatabaseTableSchemaStats;
}

export type TriggerWhen = "BEFORE" | "AFTER" | "INSTEAD_OF";
Expand Down Expand Up @@ -234,7 +234,6 @@ export interface DriverFlags {
supportBigInt: boolean;
supportCreateUpdateTable: boolean;
supportModifyColumn: boolean;
mismatchDetection: boolean;
dialect: SupportedDialect;

supportUseStatement?: boolean;
Expand Down
17 changes: 8 additions & 9 deletions src/drivers/mysql/mysql-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ export default abstract class MySQLLikeDriver extends CommonSQLImplement {
optionalSchema: false,
supportBigInt: false,
supportModifyColumn: true,
mismatchDetection: false,
supportCreateUpdateTable: true,
supportCreateUpdateDatabase: true,
dialect: "mysql",
Expand Down Expand Up @@ -194,7 +193,7 @@ export default abstract class MySQLLikeDriver extends CommonSQLImplement {
schemaName: t.TABLE_SCHEMA,
tableSchema: {
stats: {
sizeInByte: t.DATA_LENGTH + t.INDEX_LENGTH
sizeInByte: t.DATA_LENGTH + t.INDEX_LENGTH,
},
autoIncrement: false,
pk: [],
Expand Down Expand Up @@ -350,13 +349,13 @@ export default abstract class MySQLLikeDriver extends CommonSQLImplement {
foreignKey:
constraint.CONSTRAINT_TYPE === "FOREIGN KEY"
? {
columns: columnList.map((c) => c.COLUMN_NAME),
foreignColumns: columnList.map(
(c) => c.REFERENCED_COLUMN_NAME
),
foreignSchemaName: columnList[0].REFERENCED_TABLE_SCHEMA,
foreignTableName: columnList[0].REFERENCED_TABLE_NAME,
}
columns: columnList.map((c) => c.COLUMN_NAME),
foreignColumns: columnList.map(
(c) => c.REFERENCED_COLUMN_NAME
),
foreignSchemaName: columnList[0].REFERENCED_TABLE_SCHEMA,
foreignTableName: columnList[0].REFERENCED_TABLE_NAME,
}
: undefined,
};
}
Expand Down
1 change: 0 additions & 1 deletion src/drivers/postgres/postgres-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ export default abstract class PostgresLikeDriver extends CommonSQLImplement {
supportRowId: false,
supportBigInt: false,
supportModifyColumn: false,
mismatchDetection: false,
supportCreateUpdateTable: false,
supportCreateUpdateDatabase: false,
supportInsertReturning: true,
Expand Down
1 change: 0 additions & 1 deletion src/drivers/sqlite-base-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export abstract class SqliteLikeBaseDriver extends CommonSQLImplement {
supportUpdateReturning: true,
defaultSchema: "main",
optionalSchema: true,
mismatchDetection: false,
supportCreateUpdateTable: true,
supportCreateUpdateDatabase: false,
dialect: "sqlite",
Expand Down
1 change: 0 additions & 1 deletion src/drivers/turso-driver.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ export default class TursoDriver extends SqliteLikeBaseDriver {
...super.getFlags(),
supportBigInt: this.bigInt,
supportModifyColumn: true,
mismatchDetection: this.bigInt,
};
}

Expand Down

0 comments on commit 1cd1a18

Please sign in to comment.