fix(export): preserve MySQL bit literals in SQL export
This commit is contained in:
1 parent
f2924a3725
commit
b226b445d6
9 files changed
+158
-10
No files matched your search
@@ -1493,6 +1493,23 @@ const visibleSourceColumns = computed(() => {
|
||||
if (!props.sourceColumns || props.sourceColumns.length !== props.result.columns.length) return undefined;
|
||||
return visibleColumnIndexes.value.map((index) => props.sourceColumns?.[index]);
|
||||
});
|
||||
const tableColumnTypesByName = computed(() => {
|
||||
const map = new Map<string, string>();
|
||||
for (const column of props.tableMeta?.columns ?? []) {
|
||||
map.set(column.name.toLocaleLowerCase(), column.data_type);
|
||||
}
|
||||
return map;
|
||||
});
|
||||
const visibleColumnTypes = computed(() =>
|
||||
visibleColumnIndexes.value.map((index) => {
|
||||
const resultColumn = props.result.columns[index]?.toLocaleLowerCase();
|
||||
const sourceColumn = props.sourceColumns?.[index]?.toLocaleLowerCase();
|
||||
return (
|
||||
(sourceColumn ? tableColumnTypesByName.value.get(sourceColumn) : undefined) ||
|
||||
(resultColumn ? tableColumnTypesByName.value.get(resultColumn) : undefined)
|
||||
);
|
||||
}),
|
||||
);
|
||||
const visibleColumnCount = computed(() => visibleColumnIndexes.value.length);
|
||||
const displayableColumnCount = computed(() => displayableColumnIndexes.value.length);
|
||||
const hiddenColumnCount = computed(() => displayableColumnCount.value - visibleColumnCount.value);
|
||||
@@ -3736,6 +3753,7 @@ const {
|
||||
database: computed(() => props.database),
|
||||
context: computed(() => props.context),
|
||||
sourceColumns: visibleSourceColumns,
|
||||
columnTypes: visibleColumnTypes,
|
||||
whereInput: computed(() => currentWhereInput()),
|
||||
orderBy: computed(() => currentOrderBy()),
|
||||
exportBatchSize: computed(() => settingsStore.editorSettings.exportBatchSize),
|
||||
|
||||
@@ -789,11 +789,16 @@ async function exportStructure(row: ObjectBrowserRow) {
|
||||
async function exportDataLegacy(row: ObjectBrowserRow, format: "json" | "sql") {
|
||||
try {
|
||||
const schema = row.schema || selectedSchema.value;
|
||||
const tableColumns =
|
||||
format === "sql"
|
||||
? await api.getColumns(props.connection.id, props.database, schema || props.database, row.name)
|
||||
: undefined;
|
||||
const queryColumns =
|
||||
props.connection.db_type === "neo4j"
|
||||
? (await api.getColumns(props.connection.id, props.database, schema || props.database, row.name)).map(
|
||||
(column) => column.name,
|
||||
)
|
||||
? (
|
||||
tableColumns ??
|
||||
(await api.getColumns(props.connection.id, props.database, schema || props.database, row.name))
|
||||
).map((column) => column.name)
|
||||
: undefined;
|
||||
const result = await fetchTableDataForExport({
|
||||
databaseType: effectiveDatabaseType.value,
|
||||
@@ -824,6 +829,7 @@ async function exportDataLegacy(row: ObjectBrowserRow, format: "json" | "sql") {
|
||||
schema,
|
||||
tableName: row.name,
|
||||
columns: result.columns,
|
||||
columnTypes: tableColumns ? columnTypesForResultColumns(result.columns, tableColumns) : undefined,
|
||||
rows: result.rows,
|
||||
});
|
||||
await saveFileContent(content, `${row.name}.sql`, "SQL", "sql");
|
||||
@@ -833,6 +839,14 @@ async function exportDataLegacy(row: ObjectBrowserRow, format: "json" | "sql") {
|
||||
}
|
||||
}
|
||||
|
||||
function columnTypesForResultColumns(
|
||||
columns: string[],
|
||||
tableColumns: Array<{ name: string; data_type: string }>,
|
||||
): Array<string | undefined> {
|
||||
const typesByName = new Map(tableColumns.map((column) => [column.name.toLocaleLowerCase(), column.data_type]));
|
||||
return columns.map((column) => typesByName.get(column.toLocaleLowerCase()));
|
||||
}
|
||||
|
||||
async function exportData(row: ObjectBrowserRow, format: "csv" | "json" | "sql") {
|
||||
if (format === "csv") {
|
||||
await exportTableData(row, "csv");
|
||||
|
||||
@@ -2102,9 +2102,11 @@ async function exportDataLegacy(format: "csv" | "json" | "sql") {
|
||||
|
||||
try {
|
||||
await connectionStore.ensureConnected(connectionId);
|
||||
const tableColumns =
|
||||
format === "sql" ? await api.getColumns(connectionId, database, node.schema || database, node.label) : undefined;
|
||||
const queryColumns =
|
||||
config.db_type === "neo4j"
|
||||
? (await api.getColumns(connectionId, database, node.schema || database, node.label)).map(
|
||||
? (tableColumns ?? (await api.getColumns(connectionId, database, node.schema || database, node.label))).map(
|
||||
(column) => column.name,
|
||||
)
|
||||
: undefined;
|
||||
@@ -2154,6 +2156,7 @@ async function exportDataLegacy(format: "csv" | "json" | "sql") {
|
||||
schema: node.schema,
|
||||
tableName: node.label,
|
||||
columns: result.columns,
|
||||
columnTypes: tableColumns ? columnTypesForResultColumns(result.columns, tableColumns) : undefined,
|
||||
rows: result.rows,
|
||||
});
|
||||
await saveFileContent(content, `${node.label}.sql`, "SQL", "sql");
|
||||
@@ -2163,6 +2166,11 @@ async function exportDataLegacy(format: "csv" | "json" | "sql") {
|
||||
}
|
||||
}
|
||||
|
||||
function columnTypesForResultColumns(columns: string[], tableColumns: ColumnInfo[]): Array<string | undefined> {
|
||||
const typesByName = new Map(tableColumns.map((column) => [column.name.toLocaleLowerCase(), column.data_type]));
|
||||
return columns.map((column) => typesByName.get(column.toLocaleLowerCase()));
|
||||
}
|
||||
|
||||
async function exportData(format: "csv" | "json" | "sql") {
|
||||
if (format !== "csv") {
|
||||
await exportDataLegacy(format);
|
||||
|
||||
Reference in new issue
Block a user