getTableFormOptions moved to dialect

This commit is contained in:
Jan Prochazka 2024-09-11 14:01:11 +02:00
parent b0165c14e9
commit 7ad1950777
6 changed files with 83 additions and 79 deletions

View File

@ -177,8 +177,4 @@ export const driverBase = {
createSaveChangeSetScript(changeSet, dbinfo, defaultCreator) {
return defaultCreator(changeSet, dbinfo);
},
getTableFormOptions() {
return null;
},
};

View File

@ -44,4 +44,9 @@ export interface SqlDialect {
// create sql-tree expression
createColumnViewExpression(columnName: string, dataType: string, source: { alias: string }, alias?: string): any;
getTableFormOptions(intent: 'newTableForm' | 'editTableForm' | 'sqlCreateTable' | 'sqlAlterTable'): {
name: string;
sqlFormatString: string;
}[];
}

View File

@ -155,11 +155,6 @@ export interface EngineDriver extends FilterBehaviourProvider {
collectionNameLabel?: string;
newCollectionFormParams?: any[];
getTableFormOptions(intent: 'newTableForm' | 'editTableForm' | 'sqlCreateTable' | 'sqlAlterTable'): {
name: string;
sqlFormatString: string;
}[];
supportedCreateDatabase?: boolean;
showConnectionField?: (
field: string,

View File

@ -156,7 +156,7 @@
invalidateCommands();
}
$: tableFormOptions = driver?.getTableFormOptions(tableInfo?.objectId ? 'editTableForm' : 'newTableForm');
$: tableFormOptions = driver?.dialect?.getTableFormOptions?.(tableInfo?.objectId ? 'editTableForm' : 'newTableForm');
</script>
<div class="wrapper">

View File

@ -72,6 +72,26 @@ const dialect = {
quoteIdentifier(s) {
return `"${s}"`;
},
getTableFormOptions(intent) {
const isNewTable = intent == 'newTableForm';
return [
{
type: isNewTable ? 'dropdowntext' : 'text',
options: clickhouseEngines,
label: 'Engine',
name: 'tableEngine',
sqlFormatString: '^engine = %s',
disabled: !isNewTable,
},
{
type: 'text',
label: 'Comment',
name: 'objectComment',
sqlFormatString: '^comment %v',
},
];
},
};
/** @type {import('dbgate-types').EngineDriver} */
@ -117,26 +137,6 @@ const driver = {
}
return res;
},
getTableFormOptions(intent) {
const isNewTable = intent == 'newTableForm';
return [
{
type: isNewTable ? 'dropdowntext' : 'text',
options: clickhouseEngines,
label: 'Engine',
name: 'tableEngine',
sqlFormatString: '^engine = %s',
disabled: !isNewTable,
},
{
type: 'text',
label: 'Comment',
name: 'objectComment',
sqlFormatString: '^comment %v',
},
];
},
};
module.exports = driver;

View File

@ -99,39 +99,6 @@ const dialect = {
};
}
},
};
const mysqlDriverBase = {
...driverBase,
showConnectionField: (field, values) =>
['authType', 'user', 'password', 'defaultDatabase', 'singleDatabase', 'isReadOnly'].includes(field) ||
(values.authType == 'socket' && ['socketPath'].includes(field)) ||
(values.authType != 'socket' && ['server', 'port'].includes(field)),
dumperClass: Dumper,
dialect,
defaultPort: 3306,
getQuerySplitterOptions: usage =>
usage == 'editor'
? { ...mysqlSplitterOptions, ignoreComments: true, preventSingleLineSplit: true }
: mysqlSplitterOptions,
readOnlySessions: true,
supportsDatabaseDump: true,
authTypeLabel: 'Connection mode',
defaultAuthTypeName: 'hostPort',
defaultSocketPath: '/var/run/mysqld/mysqld.sock',
supportsTransactions: true,
getNewObjectTemplates() {
return [
{ 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 function', sql: 'CREATE FUNCTION myfunc (arg1 INT)\nRETURNS INT DETERMINISTIC\nRETURN 1' },
];
},
getSupportedEngines() {
return [];
@ -158,15 +125,8 @@ const mysqlDriverBase = {
},
};
/** @type {import('dbgate-types').EngineDriver} */
const mysqlDriver = {
...mysqlDriverBase,
engine: 'mysql@dbgate-plugin-mysql',
title: 'MySQL',
__analyserInternals: {
quoteDefaultValues: true,
},
const mysqlDialect = {
...dialect,
getSupportedEngines() {
const mysqlEngines = [
'InnoDB', // Default and most commonly used engine with ACID transaction support and referential integrity.
@ -189,14 +149,51 @@ const mysqlDriver = {
},
};
/** @type {import('dbgate-types').EngineDriver} */
const mariaDriver = {
...mysqlDriverBase,
engine: 'mariadb@dbgate-plugin-mysql',
title: 'MariaDB',
__analyserInternals: {
quoteDefaultValues: false,
const mysqlDriverBase = {
...driverBase,
showConnectionField: (field, values) =>
['authType', 'user', 'password', 'defaultDatabase', 'singleDatabase', 'isReadOnly'].includes(field) ||
(values.authType == 'socket' && ['socketPath'].includes(field)) ||
(values.authType != 'socket' && ['server', 'port'].includes(field)),
dumperClass: Dumper,
defaultPort: 3306,
getQuerySplitterOptions: usage =>
usage == 'editor'
? { ...mysqlSplitterOptions, ignoreComments: true, preventSingleLineSplit: true }
: mysqlSplitterOptions,
readOnlySessions: true,
supportsDatabaseDump: true,
authTypeLabel: 'Connection mode',
defaultAuthTypeName: 'hostPort',
defaultSocketPath: '/var/run/mysqld/mysqld.sock',
supportsTransactions: true,
getNewObjectTemplates() {
return [
{ 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 function', sql: 'CREATE FUNCTION myfunc (arg1 INT)\nRETURNS INT DETERMINISTIC\nRETURN 1' },
];
},
};
/** @type {import('dbgate-types').EngineDriver} */
const mysqlDriver = {
...mysqlDriverBase,
dialect: mysqlDialect,
engine: 'mysql@dbgate-plugin-mysql',
title: 'MySQL',
__analyserInternals: {
quoteDefaultValues: true,
},
};
const mariaDbDialect = {
...dialect,
getSupportedEngines() {
const mariaDBEngines = [
'InnoDB', // Main transactional engine, similar to MySQL, supports ACID transactions and referential integrity.
@ -224,4 +221,15 @@ const mariaDriver = {
},
};
/** @type {import('dbgate-types').EngineDriver} */
const mariaDriver = {
...mysqlDriverBase,
dialect: mariaDbDialect,
engine: 'mariadb@dbgate-plugin-mysql',
title: 'MariaDB',
__analyserInternals: {
quoteDefaultValues: false,
},
};
module.exports = [mysqlDriver, mariaDriver];