dbgate/packages/web/src/appobj/ColumnAppObject.svelte

49 lines
1.4 KiB
Svelte
Raw Normal View History

2021-03-01 19:27:09 +00:00
<script lang="ts" context="module">
export const extractKey = ({ columnName }) => columnName;
</script>
<script lang="ts">
import _ from 'lodash';
2021-03-18 10:51:19 +00:00
import { getColumnIcon } from '../elements/ColumnLabel.svelte';
import { renameDatabaseObjectDialog, alterDatabaseDialog } from '../utility/alterDatabaseTools';
2021-03-01 19:27:09 +00:00
import AppObjectCore from './AppObjectCore.svelte';
export let data;
2021-09-11 06:33:35 +00:00
function handleRenameColumn() {
renameDatabaseObjectDialog(data.conid, data.database, data.columnName, (db, newName) => {
const tbl = db.tables.find(x => x.schemaName == data.schemaName && x.pureName == data.pureName);
const col = tbl.columns.find(x => x.columnName == data.columnName);
col.columnName = newName;
});
2021-09-11 06:33:35 +00:00
}
function handleDropColumn() {
alterDatabaseDialog(data.conid, data.database, db => {
const tbl = db.tables.find(x => x.schemaName == data.schemaName && x.pureName == data.pureName);
_.remove(tbl.columns as any[], x => x.columnName == data.columnName);
});
}
2021-09-11 06:33:35 +00:00
function createMenu() {
return [
{ text: 'Rename column', onClick: handleRenameColumn },
{ text: 'Drop column', onClick: handleDropColumn },
];
}
2021-03-01 19:27:09 +00:00
$: extInfo = data.foreignKey ? `${data.dataType} -> ${data.foreignKey.refTableName}` : data.dataType;
</script>
<AppObjectCore
{...$$restProps}
{data}
title={data.columnName}
{extInfo}
icon={getColumnIcon(data, true)}
2021-09-11 06:33:35 +00:00
menu={createMenu}
2021-03-01 19:27:09 +00:00
disableHover
/>