helpers.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. 'use strict';
  2. exports.__esModule = true;
  3. var _tail2 = require('lodash/tail');
  4. var _tail3 = _interopRequireDefault(_tail2);
  5. var _isString2 = require('lodash/isString');
  6. var _isString3 = _interopRequireDefault(_isString2);
  7. exports.pushQuery = pushQuery;
  8. exports.pushAdditional = pushAdditional;
  9. var _columncompiler = require('./columncompiler');
  10. var _columncompiler2 = _interopRequireDefault(_columncompiler);
  11. var _tablecompiler = require('./tablecompiler');
  12. var _tablecompiler2 = _interopRequireDefault(_tablecompiler);
  13. var _compiler = require('./compiler');
  14. var _compiler2 = _interopRequireDefault(_compiler);
  15. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  16. // Push a new query onto the compiled "sequence" stack,
  17. // creating a new formatter, returning the compiler.
  18. function pushQuery(query) {
  19. if (!query) return;
  20. if ((0, _isString3.default)(query)) {
  21. query = { sql: query };
  22. }
  23. if (!query.bindings) {
  24. query.bindings = this.formatter.bindings;
  25. }
  26. this.sequence.push(query);
  27. var builder = void 0;
  28. if (this instanceof _columncompiler2.default) {
  29. builder = this.columnBuilder;
  30. } else if (this instanceof _tablecompiler2.default) {
  31. builder = this.tableBuilder;
  32. } else if (this instanceof _compiler2.default) {
  33. builder = this.builder;
  34. }
  35. this.formatter = this.client.formatter(builder);
  36. }
  37. // Used in cases where we need to push some additional column specific statements.
  38. function pushAdditional(fn) {
  39. var child = new this.constructor(this.client, this.tableCompiler, this.columnBuilder);
  40. fn.call(child, (0, _tail3.default)(arguments));
  41. this.sequence.additional = (this.sequence.additional || []).concat(child.sequence);
  42. }