compiler.js
2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
'use strict';
exports.__esModule = true;
var _inherits = require('inherits');
var _inherits2 = _interopRequireDefault(_inherits);
var _compiler = require('../../../schema/compiler');
var _compiler2 = _interopRequireDefault(_compiler);
var _utils = require('../utils');
var utils = _interopRequireWildcard(_utils);
var _trigger = require('./trigger');
var _trigger2 = _interopRequireDefault(_trigger);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// Oracle Schema Compiler
// -------
function SchemaCompiler_Oracle() {
_compiler2.default.apply(this, arguments);
}
(0, _inherits2.default)(SchemaCompiler_Oracle, _compiler2.default);
// Rename a table on the schema.
SchemaCompiler_Oracle.prototype.renameTable = function (tableName, to) {
var renameTable = _trigger2.default.renameTableAndAutoIncrementTrigger(tableName, to);
this.pushQuery(renameTable);
};
// Check whether a table exists on the query.
SchemaCompiler_Oracle.prototype.hasTable = function (tableName) {
this.pushQuery({
sql: 'select TABLE_NAME from USER_TABLES where TABLE_NAME = ' + this.formatter.parameter(tableName),
output: function output(resp) {
return resp.length > 0;
}
});
};
// Check whether a column exists on the schema.
SchemaCompiler_Oracle.prototype.hasColumn = function (tableName, column) {
var sql = 'select COLUMN_NAME from USER_TAB_COLUMNS ' + ('where TABLE_NAME = ' + this.formatter.parameter(tableName) + ' ') + ('and COLUMN_NAME = ' + this.formatter.parameter(column));
this.pushQuery({ sql: sql, output: function output(resp) {
return resp.length > 0;
} });
};
SchemaCompiler_Oracle.prototype.dropSequenceIfExists = function (sequenceName) {
this.pushQuery(utils.wrapSqlWithCatch('drop sequence ' + this.formatter.wrap(sequenceName), -2289));
};
SchemaCompiler_Oracle.prototype._dropRelatedSequenceIfExists = function (tableName) {
// removing the sequence that was possibly generated by increments() column
var sequenceName = utils.generateCombinedName('seq', tableName);
this.dropSequenceIfExists(sequenceName);
};
SchemaCompiler_Oracle.prototype.dropTable = function (tableName) {
this.pushQuery('drop table ' + this.formatter.wrap(tableName));
// removing the sequence that was possibly generated by increments() column
this._dropRelatedSequenceIfExists(tableName);
};
SchemaCompiler_Oracle.prototype.dropTableIfExists = function (tableName) {
this.pushQuery(utils.wrapSqlWithCatch('drop table ' + this.formatter.wrap(tableName), -942));
// removing the sequence that was possibly generated by increments() column
this._dropRelatedSequenceIfExists(tableName);
};
exports.default = SchemaCompiler_Oracle;
module.exports = exports['default'];