mysql column comments #218 #81

This commit is contained in:
Jan Prochazka
2022-02-10 12:46:00 +01:00
parent c3c63da752
commit 691bb0af4f
8 changed files with 37 additions and 6 deletions

View File

@@ -10,6 +10,10 @@ const dialect = {
quoteIdentifier(s) { quoteIdentifier(s) {
return s; return s;
}, },
columnProperties: {
isSparse: false,
isPersisted: false,
},
}; };
export const driverBase = { export const driverBase = {

View File

@@ -54,6 +54,7 @@ export interface ColumnInfo extends NamedObjectInfo {
isSparse?: boolean; isSparse?: boolean;
defaultValue?: string; defaultValue?: string;
defaultConstraint?: string; defaultConstraint?: string;
columnComment?: string;
} }
export interface DatabaseObjectInfo extends NamedObjectInfo { export interface DatabaseObjectInfo extends NamedObjectInfo {
@@ -63,6 +64,7 @@ export interface DatabaseObjectInfo extends NamedObjectInfo {
modifyDate?: string; modifyDate?: string;
hashCode?: string; hashCode?: string;
objectTypeField?: string; objectTypeField?: string;
obejctComment?: string;
} }
export interface SqlObjectInfo extends DatabaseObjectInfo { export interface SqlObjectInfo extends DatabaseObjectInfo {

View File

@@ -87,6 +87,7 @@
export let tableInfo; export let tableInfo;
export let setTableInfo; export let setTableInfo;
export let dbInfo; export let dbInfo;
export let driver;
export function writable() { export function writable() {
return !!setTableInfo; return !!setTableInfo;
@@ -176,7 +177,7 @@
header: 'Default value', header: 'Default value',
sortable: true, sortable: true,
}, },
{ driver?.dialect?.columnProperties?.isSparse && {
fieldName: 'isSparse', fieldName: 'isSparse',
header: 'Is Sparse', header: 'Is Sparse',
sortable: true, sortable: true,
@@ -187,12 +188,17 @@
header: 'Computed Expression', header: 'Computed Expression',
sortable: true, sortable: true,
}, },
{ driver?.dialect?.columnProperties?.isPersisted && {
fieldName: 'isPersisted', fieldName: 'isPersisted',
header: 'Is Persisted', header: 'Is Persisted',
sortable: true, sortable: true,
slot: 2, slot: 2,
}, },
driver?.dialect?.columnProperties?.columnComment && {
fieldName: 'columnComment',
header: 'Comment',
sortable: true,
},
writable() writable()
? { ? {
fieldName: 'actions', fieldName: 'actions',

View File

@@ -75,6 +75,7 @@
$: dbInfo = useDatabaseInfo({ conid, database }); $: dbInfo = useDatabaseInfo({ conid, database });
$: tableInfoWithPairingId = $tableInfo ? generateTablePairingId($tableInfo) : null; $: tableInfoWithPairingId = $tableInfo ? generateTablePairingId($tableInfo) : null;
$: connection = useConnectionInfo({ conid }); $: connection = useConnectionInfo({ conid });
$: driver = findEngineDriver($connection, $extensions);
const { editorState, editorValue, setEditorData, clearEditorData } = useEditorData({ tabid }); const { editorState, editorValue, setEditorData, clearEditorData } = useEditorData({ tabid });
@@ -108,8 +109,6 @@
} }
function doSave(createTableName) { function doSave(createTableName) {
const driver = findEngineDriver($connection, $extensions);
const { sql, recreates } = getAlterTableScript( const { sql, recreates } = getAlterTableScript(
$editorValue.base, $editorValue.base,
extendTableInfo(fillConstraintNames($editorValue.current, driver.dialect)), extendTableInfo(fillConstraintNames($editorValue.current, driver.dialect)),
@@ -167,6 +166,7 @@
bind:this={domEditor} bind:this={domEditor}
tableInfo={showTable} tableInfo={showTable}
dbInfo={$dbInfo} dbInfo={$dbInfo}
{driver}
setTableInfo={objectTypeField == 'tables' setTableInfo={objectTypeField == 'tables'
? tableInfoUpdater => ? tableInfoUpdater =>
setEditorData(tbl => setEditorData(tbl =>

View File

@@ -35,6 +35,11 @@ const dialect = {
dropCheck: true, dropCheck: true,
dropReferencesWhenDropTable: true, dropReferencesWhenDropTable: true,
columnProperties: {
isSparse: true,
isPersisted: true,
},
}; };
/** @type {import('dbgate-types').EngineDriver} */ /** @type {import('dbgate-types').EngineDriver} */
@@ -66,7 +71,10 @@ const driver = {
{ label: 'New view', sql: 'CREATE VIEW myview\nAS\nSELECT * FROM table1' }, { label: 'New view', sql: 'CREATE VIEW myview\nAS\nSELECT * FROM table1' },
{ label: 'New procedure', sql: 'CREATE PROCEDURE myproc (@arg1 INT)\nAS\nBEGIN\n SELECT * FROM table1\nEND' }, { label: 'New procedure', sql: 'CREATE PROCEDURE myproc (@arg1 INT)\nAS\nBEGIN\n SELECT * FROM table1\nEND' },
{ label: 'New function', sql: 'CREATE FUNCTION myfunc (@arg1 INT) RETURNS INT\nAS\nBEGIN\n RETURN 1;\nEND' }, { label: 'New function', sql: 'CREATE FUNCTION myfunc (@arg1 INT) RETURNS INT\nAS\nBEGIN\n RETURN 1;\nEND' },
{ label: 'New table valued function', sql: 'CREATE FUNCTION myfunc (@arg1 INT) RETURNS TABLE \nAS\nRETURN SELECT * FROM table1' }, {
label: 'New table valued function',
sql: 'CREATE FUNCTION myfunc (@arg1 INT) RETURNS TABLE \nAS\nRETURN SELECT * FROM table1',
},
]; ];
}, },
}; };

View File

@@ -14,6 +14,7 @@ function getColumnInfo({
numericPrecision, numericPrecision,
numericScale, numericScale,
defaultValue, defaultValue,
columnComment,
}) { }) {
let fullDataType = dataType; let fullDataType = dataType;
if (charMaxLength && isTypeString(dataType)) fullDataType = `${dataType}(${charMaxLength})`; if (charMaxLength && isTypeString(dataType)) fullDataType = `${dataType}(${charMaxLength})`;
@@ -23,6 +24,7 @@ function getColumnInfo({
notNull: !isNullable || isNullable == 'NO' || isNullable == 'no', notNull: !isNullable || isNullable == 'NO' || isNullable == 'no',
autoIncrement: !!(extra && extra.toLowerCase().includes('auto_increment')), autoIncrement: !!(extra && extra.toLowerCase().includes('auto_increment')),
columnName, columnName,
columnComment,
dataType: fullDataType, dataType: fullDataType,
defaultValue, defaultValue,
}; };

View File

@@ -8,6 +8,7 @@ select
NUMERIC_PRECISION as numericPrecision, NUMERIC_PRECISION as numericPrecision,
NUMERIC_SCALE as numericScale, NUMERIC_SCALE as numericScale,
COLUMN_DEFAULT as defaultValue, COLUMN_DEFAULT as defaultValue,
COLUMN_COMMENT as columnComment,
EXTRA as extra EXTRA as extra
from INFORMATION_SCHEMA.COLUMNS from INFORMATION_SCHEMA.COLUMNS
where TABLE_SCHEMA = '#DATABASE#' and TABLE_NAME =OBJECT_ID_CONDITION where TABLE_SCHEMA = '#DATABASE#' and TABLE_NAME =OBJECT_ID_CONDITION

View File

@@ -30,6 +30,10 @@ const dialect = {
dropCheck: true, dropCheck: true,
dropReferencesWhenDropTable: false, dropReferencesWhenDropTable: false,
columnProperties: {
columnComment: true,
},
}; };
const mysqlDriverBase = { const mysqlDriverBase = {
@@ -44,7 +48,11 @@ const mysqlDriverBase = {
getNewObjectTemplates() { getNewObjectTemplates() {
return [ return [
{ label: 'New view', sql: 'CREATE VIEW myview\nAS\nSELECT * FROM table1' }, { label: 'New view', sql: 'CREATE VIEW myview\nAS\nSELECT * FROM table1' },
{ label: 'New procedure', sql: 'DELIMITER //\n\nCREATE PROCEDURE myproc (IN arg1 INT)\nBEGIN\n SELECT * FROM table1;\nEND\n\nDELIMITER ;' }, {
label: 'New procedure',
sql:
'DELIMITER //\n\nCREATE PROCEDURE myproc (IN arg1 INT)\nBEGIN\n SELECT * FROM table1;\nEND\n\nDELIMITER ;',
},
{ label: 'New function', sql: 'CREATE FUNCTION myfunc (arg1 INT)\nRETURNS INT DETERMINISTIC\nRETURN 1' }, { label: 'New function', sql: 'CREATE FUNCTION myfunc (arg1 INT)\nRETURNS INT DETERMINISTIC\nRETURN 1' },
]; ];
}, },