compiler.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. 'use strict';
  2. exports.__esModule = true;
  3. var _some2 = require('lodash/some');
  4. var _some3 = _interopRequireDefault(_some2);
  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. // Schema Compiler
  11. // -------
  12. // SQLite3: Column Builder & Compiler
  13. // -------
  14. function SchemaCompiler_SQLite3() {
  15. _compiler2.default.apply(this, arguments);
  16. }
  17. (0, _inherits2.default)(SchemaCompiler_SQLite3, _compiler2.default);
  18. // Compile the query to determine if a table exists.
  19. SchemaCompiler_SQLite3.prototype.hasTable = function (tableName) {
  20. var sql = 'select * from sqlite_master ' + ('where type = \'table\' and name = ' + this.formatter.parameter(tableName));
  21. this.pushQuery({ sql: sql, output: function output(resp) {
  22. return resp.length > 0;
  23. } });
  24. };
  25. // Compile the query to determine if a column exists.
  26. SchemaCompiler_SQLite3.prototype.hasColumn = function (tableName, column) {
  27. this.pushQuery({
  28. sql: 'PRAGMA table_info(' + this.formatter.wrap(tableName) + ')',
  29. output: function output(resp) {
  30. return (0, _some3.default)(resp, { name: column });
  31. }
  32. });
  33. };
  34. // Compile a rename table command.
  35. SchemaCompiler_SQLite3.prototype.renameTable = function (from, to) {
  36. this.pushQuery('alter table ' + this.formatter.wrap(from) + ' rename to ' + this.formatter.wrap(to));
  37. };
  38. exports.default = SchemaCompiler_SQLite3;
  39. module.exports = exports['default'];