added plugins

This commit is contained in:
Jan Prochazka
2021-04-13 16:17:53 +02:00
parent 446e7c139f
commit 4d5cc119f2
115 changed files with 5519 additions and 24 deletions

View 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;