compiler.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. 'use strict';
  2. exports.__esModule = true;
  3. var _inherits = require('inherits');
  4. var _inherits2 = _interopRequireDefault(_inherits);
  5. var _compiler = require('../../../schema/compiler');
  6. var _compiler2 = _interopRequireDefault(_compiler);
  7. var _utils = require('../utils');
  8. var utils = _interopRequireWildcard(_utils);
  9. var _trigger = require('./trigger');
  10. var _trigger2 = _interopRequireDefault(_trigger);
  11. 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; } }
  12. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  13. // Oracle Schema Compiler
  14. // -------
  15. function SchemaCompiler_Oracle() {
  16. _compiler2.default.apply(this, arguments);
  17. }
  18. (0, _inherits2.default)(SchemaCompiler_Oracle, _compiler2.default);
  19. // Rename a table on the schema.
  20. SchemaCompiler_Oracle.prototype.renameTable = function (tableName, to) {
  21. var renameTable = _trigger2.default.renameTableAndAutoIncrementTrigger(tableName, to);
  22. this.pushQuery(renameTable);
  23. };
  24. // Check whether a table exists on the query.
  25. SchemaCompiler_Oracle.prototype.hasTable = function (tableName) {
  26. this.pushQuery({
  27. sql: 'select TABLE_NAME from USER_TABLES where TABLE_NAME = ' + this.formatter.parameter(tableName),
  28. output: function output(resp) {
  29. return resp.length > 0;
  30. }
  31. });
  32. };
  33. // Check whether a column exists on the schema.
  34. SchemaCompiler_Oracle.prototype.hasColumn = function (tableName, column) {
  35. var sql = 'select COLUMN_NAME from USER_TAB_COLUMNS ' + ('where TABLE_NAME = ' + this.formatter.parameter(tableName) + ' ') + ('and COLUMN_NAME = ' + this.formatter.parameter(column));
  36. this.pushQuery({ sql: sql, output: function output(resp) {
  37. return resp.length > 0;
  38. } });
  39. };
  40. SchemaCompiler_Oracle.prototype.dropSequenceIfExists = function (sequenceName) {
  41. this.pushQuery(utils.wrapSqlWithCatch('drop sequence ' + this.formatter.wrap(sequenceName), -2289));
  42. };
  43. SchemaCompiler_Oracle.prototype._dropRelatedSequenceIfExists = function (tableName) {
  44. // removing the sequence that was possibly generated by increments() column
  45. var sequenceName = utils.generateCombinedName('seq', tableName);
  46. this.dropSequenceIfExists(sequenceName);
  47. };
  48. SchemaCompiler_Oracle.prototype.dropTable = function (tableName) {
  49. this.pushQuery('drop table ' + this.formatter.wrap(tableName));
  50. // removing the sequence that was possibly generated by increments() column
  51. this._dropRelatedSequenceIfExists(tableName);
  52. };
  53. SchemaCompiler_Oracle.prototype.dropTableIfExists = function (tableName) {
  54. this.pushQuery(utils.wrapSqlWithCatch('drop table ' + this.formatter.wrap(tableName), -942));
  55. // removing the sequence that was possibly generated by increments() column
  56. this._dropRelatedSequenceIfExists(tableName);
  57. };
  58. exports.default = SchemaCompiler_Oracle;
  59. module.exports = exports['default'];