mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 14:56:01 +00:00
added plugins
This commit is contained in:
68
plugins/dbgate-plugin-mysql/src/frontend/Dumper.js
Normal file
68
plugins/dbgate-plugin-mysql/src/frontend/Dumper.js
Normal file
@@ -0,0 +1,68 @@
|
||||
const { SqlDumper } = require('dbgate-tools');
|
||||
|
||||
class Dumper extends SqlDumper {
|
||||
/** @param type {import('dbgate-types').TransformType} */
|
||||
transform(type, dumpExpr) {
|
||||
switch (type) {
|
||||
case 'GROUP:YEAR':
|
||||
case 'YEAR':
|
||||
this.put('^year(%c)', dumpExpr);
|
||||
break;
|
||||
case 'MONTH':
|
||||
this.put('^month(%c)', dumpExpr);
|
||||
break;
|
||||
case 'DAY':
|
||||
this.put('^day(%c)', dumpExpr);
|
||||
break;
|
||||
case 'GROUP:MONTH':
|
||||
this.put("^date_format(%c, '%s')", dumpExpr, '%Y-%m');
|
||||
break;
|
||||
case 'GROUP:DAY':
|
||||
this.put("^date_format(%c, '%s')", dumpExpr, '%Y-%m-%d');
|
||||
break;
|
||||
default:
|
||||
dumpExpr();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
renameTable(obj, newName) {
|
||||
this.putCmd('^rename ^table %f ^to %i', obj, newName);
|
||||
}
|
||||
|
||||
changeColumn(oldcol, newcol, constraints) {
|
||||
this.put('^alter ^table %f ^change ^column %i %i ', oldcol, oldcol.columnName, newcol.columnName);
|
||||
this.columnDefinition(newcol, true, true, true);
|
||||
this.inlineConstraints(constraints);
|
||||
this.endCommand();
|
||||
}
|
||||
|
||||
renameColumn(column, newcol) {
|
||||
this.changeColumn(
|
||||
column,
|
||||
{
|
||||
...column,
|
||||
columnName: newcol,
|
||||
},
|
||||
[]
|
||||
);
|
||||
}
|
||||
|
||||
enableConstraints(table, enabled) {
|
||||
this.putCmd('^set FOREIGN_KEY_CHECKS = %s', enabled ? '1' : '0');
|
||||
}
|
||||
|
||||
comment(value) {
|
||||
this.put('/* %s */', value);
|
||||
}
|
||||
|
||||
beginTransaction() {
|
||||
this.putCmd('^start ^transaction');
|
||||
}
|
||||
|
||||
selectTableIntoNewTable(sourceName, targetName) {
|
||||
this.putCmd('^create ^table %f (^select * ^from %f)', targetName, sourceName);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Dumper;
|
||||
27
plugins/dbgate-plugin-mysql/src/frontend/driver.js
Normal file
27
plugins/dbgate-plugin-mysql/src/frontend/driver.js
Normal file
@@ -0,0 +1,27 @@
|
||||
const { driverBase } = require('dbgate-tools');
|
||||
const Dumper = require('./Dumper');
|
||||
|
||||
/** @type {import('dbgate-types').SqlDialect} */
|
||||
const dialect = {
|
||||
rangeSelect: true,
|
||||
stringEscapeChar: '\\',
|
||||
fallbackDataType: 'longtext',
|
||||
enableConstraintsPerTable: false,
|
||||
anonymousPrimaryKey: true,
|
||||
explicitDropConstraint: true,
|
||||
quoteIdentifier(s) {
|
||||
return '`' + s + '`';
|
||||
},
|
||||
};
|
||||
|
||||
/** @type {import('dbgate-types').EngineDriver} */
|
||||
const driver = {
|
||||
...driverBase,
|
||||
dumperClass: Dumper,
|
||||
dialect,
|
||||
engine: 'mysql@dbgate-plugin-mysql',
|
||||
title: 'MySQL / MariaDB',
|
||||
defaultPort: 3306,
|
||||
};
|
||||
|
||||
module.exports = driver;
|
||||
6
plugins/dbgate-plugin-mysql/src/frontend/index.js
Normal file
6
plugins/dbgate-plugin-mysql/src/frontend/index.js
Normal file
@@ -0,0 +1,6 @@
|
||||
import driver from './driver';
|
||||
|
||||
export default {
|
||||
packageName: 'dbgate-plugin-mysql',
|
||||
driver,
|
||||
};
|
||||
Reference in New Issue
Block a user