mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 10:16:00 +00:00
added plugins
This commit is contained in:
66
plugins/dbgate-plugin-postgres/src/frontend/Dumper.js
Normal file
66
plugins/dbgate-plugin-postgres/src/frontend/Dumper.js
Normal file
@@ -0,0 +1,66 @@
|
||||
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('^extract(^year ^from %c)', dumpExpr);
|
||||
break;
|
||||
case 'MONTH':
|
||||
this.put('^extract(^month ^from %c)', dumpExpr);
|
||||
break;
|
||||
case 'DAY':
|
||||
this.put('^extract(^day ^from %c)', dumpExpr);
|
||||
break;
|
||||
case 'GROUP:MONTH':
|
||||
this.put("^to_char(%c, '%s')", dumpExpr, 'YYYY-MM');
|
||||
break;
|
||||
case 'GROUP:DAY':
|
||||
this.put("^to_char(%c, '%s')", dumpExpr, 'YYYY-MM-DD');
|
||||
break;
|
||||
default:
|
||||
dumpExpr();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
dropRecreatedTempTable(tmptable) {
|
||||
this.putCmd('^drop ^table %i ^cascade', tmptable);
|
||||
}
|
||||
|
||||
renameTable(obj, newname) {
|
||||
this.putCmd('^alter ^table %f ^rename ^to %i', obj, newname);
|
||||
}
|
||||
|
||||
renameColumn(column, newcol) {
|
||||
this.putCmd('^alter ^table %f ^rename ^column %i ^to %i', column, column.columnName, newcol);
|
||||
}
|
||||
|
||||
dropTable(obj, options = {}) {
|
||||
this.put('^drop ^table');
|
||||
if (options.testIfExists) this.put(' ^if ^exists');
|
||||
this.put(' %f', obj.FullName);
|
||||
this.endCommand();
|
||||
}
|
||||
|
||||
//public override void CreateIndex(IndexInfo ix)
|
||||
//{
|
||||
//}
|
||||
|
||||
enableConstraints(table, enabled) {
|
||||
this.putCmd('^alter ^table %f %k ^trigger ^all', table, enabled ? 'enable' : 'disable');
|
||||
}
|
||||
|
||||
columnDefinition(col, options) {
|
||||
const { autoIncrement } = options || {};
|
||||
if (col.autoIncrement) {
|
||||
this.put('^serial');
|
||||
return;
|
||||
}
|
||||
super.columnDefinition(col, options);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Dumper;
|
||||
27
plugins/dbgate-plugin-postgres/src/frontend/driver.js
Normal file
27
plugins/dbgate-plugin-postgres/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: '\\',
|
||||
stringEscapeChar: "'",
|
||||
fallbackDataType: 'varchar',
|
||||
anonymousPrimaryKey: true,
|
||||
enableConstraintsPerTable: true,
|
||||
quoteIdentifier(s) {
|
||||
return '"' + s + '"';
|
||||
},
|
||||
};
|
||||
|
||||
/** @type {import('dbgate-types').EngineDriver} */
|
||||
const driver = {
|
||||
...driverBase,
|
||||
dumperClass: Dumper,
|
||||
dialect,
|
||||
engine: 'postgres@dbgate-plugin-postgres',
|
||||
title: 'Postgre SQL',
|
||||
defaultPort: 5432,
|
||||
};
|
||||
|
||||
module.exports = driver;
|
||||
6
plugins/dbgate-plugin-postgres/src/frontend/index.js
Normal file
6
plugins/dbgate-plugin-postgres/src/frontend/index.js
Normal file
@@ -0,0 +1,6 @@
|
||||
import driver from './driver';
|
||||
|
||||
export default {
|
||||
packageName: 'dbgate-plugin-postgres',
|
||||
driver,
|
||||
};
|
||||
Reference in New Issue
Block a user