mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
#182 support for MySQL binary keys
This commit is contained in:
parent
30cbcd5ce0
commit
2231bc21cd
@ -13,3 +13,4 @@ export * from './settingsExtractors';
|
||||
export * from './filterName';
|
||||
export * from './diffTools';
|
||||
export * from './schemaEditorTools';
|
||||
export * from './stringTools';
|
||||
|
3
packages/tools/src/stringTools.ts
Normal file
3
packages/tools/src/stringTools.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export function toHexString(byteArray) {
|
||||
return byteArray.reduce((output, elem) => output + ('0' + elem.toString(16)).slice(-2), '');
|
||||
}
|
@ -192,14 +192,6 @@
|
||||
return `Rows: ${allRowCount.toLocaleString()}`;
|
||||
}
|
||||
|
||||
function extractCopiedValue(row, col) {
|
||||
let value = row[col];
|
||||
if (value === undefined) value = _.get(row, col);
|
||||
if (value === null) return '(NULL)';
|
||||
if (value === undefined) return '(NoField)';
|
||||
if (_.isPlainObject(value) || _.isArray(value)) return JSON.stringify(value);
|
||||
return value;
|
||||
}
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
@ -231,7 +223,7 @@
|
||||
import keycodes from '../utility/keycodes';
|
||||
import { selectedCellsCallback } from '../stores';
|
||||
import axiosInstance from '../utility/axiosInstance';
|
||||
import { copyTextToClipboard } from '../utility/clipboard';
|
||||
import { copyTextToClipboard ,extractRowCopiedValue} from '../utility/clipboard';
|
||||
import invalidateCommands from '../commands/invalidateCommands';
|
||||
import createRef from '../utility/createRef';
|
||||
import openReferenceForm, { openPrimaryKeyForm } from '../formview/openReferenceForm';
|
||||
@ -370,7 +362,7 @@
|
||||
if (!rowData) return '';
|
||||
const line = colIndexes
|
||||
.map(col => realColumnUniqueNames[col])
|
||||
.map(col => extractCopiedValue(rowData, col))
|
||||
.map(col => extractRowCopiedValue(rowData, col))
|
||||
.join('\t');
|
||||
return line;
|
||||
});
|
||||
|
@ -152,7 +152,6 @@
|
||||
function isDataCell(cell) {
|
||||
return cell[1] % 2 == 1;
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
@ -175,7 +174,7 @@
|
||||
import FontIcon from '../icons/FontIcon.svelte';
|
||||
|
||||
import axiosInstance from '../utility/axiosInstance';
|
||||
import { copyTextToClipboard } from '../utility/clipboard';
|
||||
import { copyTextToClipboard, extractRowCopiedValue } from '../utility/clipboard';
|
||||
import contextMenu, { getContextMenu, registerMenu } from '../utility/contextMenu';
|
||||
import createActivator, { getActiveComponent } from '../utility/createActivator';
|
||||
import createReducer from '../utility/createReducer';
|
||||
@ -256,7 +255,7 @@
|
||||
export function copyToClipboard() {
|
||||
const column = getCellColumn(currentCell);
|
||||
if (!column) return;
|
||||
const text = currentCell[1] % 2 == 1 ? rowData[column.uniqueName] : column.columnName;
|
||||
const text = currentCell[1] % 2 == 1 ? extractRowCopiedValue(rowData, column.uniqueName) : column.columnName;
|
||||
copyTextToClipboard(text);
|
||||
}
|
||||
|
||||
@ -475,7 +474,6 @@
|
||||
function handleSetFormView(rowData, column) {
|
||||
openReferenceForm(rowData, column, conid, database);
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<div class="outer">
|
||||
@ -629,5 +627,4 @@
|
||||
right: 40px;
|
||||
bottom: 20px;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
@ -1,3 +1,6 @@
|
||||
import _ from 'lodash';
|
||||
import { toHexString } from 'dbgate-tools';
|
||||
|
||||
export function copyTextToClipboard(text) {
|
||||
const oldFocus = document.activeElement;
|
||||
|
||||
@ -58,3 +61,13 @@ export function copyTextToClipboard(text) {
|
||||
|
||||
if (oldFocus) oldFocus.focus();
|
||||
}
|
||||
|
||||
export function extractRowCopiedValue(row, col) {
|
||||
let value = row[col];
|
||||
if (value === undefined) value = _.get(row, col);
|
||||
if (value === null) return '(NULL)';
|
||||
if (value === undefined) return '(NoField)';
|
||||
if (value.type == 'Buffer' && _.isArray(value.data)) return toHexString(value.data);
|
||||
if (_.isPlainObject(value) || _.isArray(value)) return JSON.stringify(value);
|
||||
return value;
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
const { SqlDumper } = global.DBGATE_TOOLS;
|
||||
const { SqlDumper, toHexString } = global.DBGATE_TOOLS;
|
||||
const _isArray = require('lodash/isArray');
|
||||
|
||||
class Dumper extends SqlDumper {
|
||||
/** @param type {import('dbgate-types').TransformType} */
|
||||
@ -63,6 +64,11 @@ class Dumper extends SqlDumper {
|
||||
selectTableIntoNewTable(sourceName, targetName) {
|
||||
this.putCmd('^create ^table %f (^select * ^from %f)', targetName, sourceName);
|
||||
}
|
||||
|
||||
putValue(value) {
|
||||
if (value.type == 'Buffer' && _isArray(value.data)) this.putRaw(`unhex('${toHexString(value.data)}')`);
|
||||
else super.putValue(value);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Dumper;
|
||||
|
Loading…
Reference in New Issue
Block a user