mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 13:46:00 +00:00
WIP
This commit is contained in:
27
plugins/dbgate-plugin-cassandra/src/frontend/Dumper.js
Normal file
27
plugins/dbgate-plugin-cassandra/src/frontend/Dumper.js
Normal file
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* @type {{ SqlDumper: import('dbgate-types').SqlDumper}}
|
||||
*/
|
||||
const { SqlDumper } = global.DBGATE_PACKAGES['dbgate-tools'];
|
||||
|
||||
class Dumper extends SqlDumper {
|
||||
/**
|
||||
* @param {import('dbgate-types').ColumnInfo} column
|
||||
* @param {string} newName
|
||||
*
|
||||
* @returns {void}
|
||||
*/
|
||||
renameColumn(column, newName) {
|
||||
this.putCmd('^alter ^table %f ^rename %i ^to %i', column, column.columnName, newName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import('dbgate-types').ColumnInfo} column
|
||||
*
|
||||
* @returns {void}
|
||||
*/
|
||||
dropColumn(column) {
|
||||
this.putCmd('^alter ^table %f ^drop %i', column, column.columnName);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Dumper;
|
||||
117
plugins/dbgate-plugin-cassandra/src/frontend/driver.js
Normal file
117
plugins/dbgate-plugin-cassandra/src/frontend/driver.js
Normal file
@@ -0,0 +1,117 @@
|
||||
const { driverBase } = global.DBGATE_PACKAGES['dbgate-tools'];
|
||||
const Dumper = require('./Dumper');
|
||||
const { mysqlSplitterOptions } = require('dbgate-query-splitter/lib/options');
|
||||
const _cloneDeepWith = require('lodash/cloneDeepWith');
|
||||
|
||||
/** @type {import('dbgate-types').SqlDialect} */
|
||||
const dialect = {
|
||||
limitSelect: true,
|
||||
rangeSelect: true,
|
||||
rawUuids: true,
|
||||
stringEscapeChar: "'",
|
||||
fallbackDataType: 'varchar',
|
||||
offsetNotSupported: true,
|
||||
allowMultipleValuesInsert: false,
|
||||
createColumn: true,
|
||||
dropColumn: true,
|
||||
changeColumn: true,
|
||||
changeAutoIncrement: true,
|
||||
createIndex: true,
|
||||
dropIndex: true,
|
||||
anonymousPrimaryKey: true,
|
||||
createColumnWithColumnKeyword: true,
|
||||
specificNullabilityImplementation: true,
|
||||
omitForeignKeys: true,
|
||||
omitUniqueConstraints: true,
|
||||
omitIndexes: true,
|
||||
omitTableAliases: true,
|
||||
omitTableBeforeColumn: true,
|
||||
sortingKeys: true,
|
||||
predefinedDataTypes: [
|
||||
'custom',
|
||||
'ascii',
|
||||
'bigint',
|
||||
'blob',
|
||||
'boolean',
|
||||
'counter',
|
||||
'decimal',
|
||||
'double',
|
||||
'float',
|
||||
'int',
|
||||
'text',
|
||||
'timestamp',
|
||||
'uuid',
|
||||
'varchar',
|
||||
'varint',
|
||||
'timeuuid',
|
||||
'inet',
|
||||
'date',
|
||||
'time',
|
||||
'smallint',
|
||||
'tinyint',
|
||||
'duration',
|
||||
'list',
|
||||
'map',
|
||||
'set',
|
||||
'udt',
|
||||
'tuple',
|
||||
],
|
||||
disableAutoIncrement: true,
|
||||
disableNonPrimaryKeyRename: true,
|
||||
defaultNewTableColumns: [
|
||||
{
|
||||
columnName: 'id',
|
||||
dataType: 'uuid',
|
||||
notNull: true,
|
||||
},
|
||||
],
|
||||
columnProperties: {
|
||||
columnComment: true,
|
||||
},
|
||||
|
||||
quoteIdentifier(s) {
|
||||
return `"${s}"`;
|
||||
},
|
||||
};
|
||||
|
||||
/** @type {import('dbgate-types').EngineDriver} */
|
||||
const driver = {
|
||||
...driverBase,
|
||||
supportsTransactions: false,
|
||||
defaultPort: 9042,
|
||||
defaultLocalDataCenter: 'datacenter1',
|
||||
dumperClass: Dumper,
|
||||
dialect,
|
||||
engine: 'cassandra@dbgate-plugin-cassandra',
|
||||
title: 'Cassandra',
|
||||
showConnectionField: (field, values) =>
|
||||
['server', 'port', 'singleDatabase', 'localDataCenter', 'isReadOnly', 'user', 'password'].includes(field),
|
||||
getQuerySplitterOptions: (usage) =>
|
||||
usage == 'editor'
|
||||
? { ...mysqlSplitterOptions, ignoreComments: true, preventSingleLineSplit: true }
|
||||
: mysqlSplitterOptions,
|
||||
adaptTableInfo(table) {
|
||||
if (!table.primaryKey && !table.sortingKey) {
|
||||
return {
|
||||
...table,
|
||||
primaryKey: {
|
||||
columns: [
|
||||
{
|
||||
columnName: 'id',
|
||||
},
|
||||
],
|
||||
},
|
||||
columns: [
|
||||
{
|
||||
columnName: 'id',
|
||||
dataType: 'uuid',
|
||||
},
|
||||
...table.columns,
|
||||
],
|
||||
};
|
||||
}
|
||||
return table;
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = driver;
|
||||
6
plugins/dbgate-plugin-cassandra/src/frontend/index.js
Normal file
6
plugins/dbgate-plugin-cassandra/src/frontend/index.js
Normal file
@@ -0,0 +1,6 @@
|
||||
import driver from './driver';
|
||||
|
||||
export default {
|
||||
packageName: 'dbgate-plugin-cassandra',
|
||||
drivers: [driver],
|
||||
};
|
||||
Reference in New Issue
Block a user