compiler.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. 'use strict';
  2. exports.__esModule = true;
  3. var _assign2 = require('lodash/assign');
  4. var _assign3 = _interopRequireDefault(_assign2);
  5. var _inherits = require('inherits');
  6. var _inherits2 = _interopRequireDefault(_inherits);
  7. var _compiler = require('../../../schema/compiler');
  8. var _compiler2 = _interopRequireDefault(_compiler);
  9. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10. // MySQL Schema Compiler
  11. // -------
  12. function SchemaCompiler_MySQL(client, builder) {
  13. _compiler2.default.call(this, client, builder);
  14. }
  15. (0, _inherits2.default)(SchemaCompiler_MySQL, _compiler2.default);
  16. (0, _assign3.default)(SchemaCompiler_MySQL.prototype, {
  17. // Rename a table on the schema.
  18. renameTable: function renameTable(tableName, to) {
  19. this.pushQuery('rename table ' + this.formatter.wrap(tableName) + ' to ' + this.formatter.wrap(to));
  20. },
  21. // Check whether a table exists on the query.
  22. hasTable: function hasTable(tableName) {
  23. this.pushQuery({
  24. sql: 'show tables like ' + this.formatter.parameter(tableName),
  25. output: function output(resp) {
  26. return resp.length > 0;
  27. }
  28. });
  29. },
  30. // Check whether a column exists on the schema.
  31. hasColumn: function hasColumn(tableName, column) {
  32. this.pushQuery({
  33. sql: 'show columns from ' + this.formatter.wrap(tableName) + ' like ' + this.formatter.parameter(column),
  34. output: function output(resp) {
  35. return resp.length > 0;
  36. }
  37. });
  38. }
  39. });
  40. exports.default = SchemaCompiler_MySQL;
  41. module.exports = exports['default'];