deferrable.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. "use strict";
  2. const { classToInvokable } = require("./utils");
  3. class ABSTRACT {
  4. static toString(...args) {
  5. return new this().toString(...args);
  6. }
  7. toString(...args) {
  8. return this.toSql(...args);
  9. }
  10. toSql() {
  11. throw new Error("toSql implementation missing");
  12. }
  13. }
  14. class INITIALLY_DEFERRED extends ABSTRACT {
  15. toSql() {
  16. return "DEFERRABLE INITIALLY DEFERRED";
  17. }
  18. }
  19. class INITIALLY_IMMEDIATE extends ABSTRACT {
  20. toSql() {
  21. return "DEFERRABLE INITIALLY IMMEDIATE";
  22. }
  23. }
  24. class NOT extends ABSTRACT {
  25. toSql() {
  26. return "NOT DEFERRABLE";
  27. }
  28. }
  29. class SET_DEFERRED extends ABSTRACT {
  30. constructor(constraints) {
  31. super();
  32. this.constraints = constraints;
  33. }
  34. toSql(queryGenerator) {
  35. return queryGenerator.setDeferredQuery(this.constraints);
  36. }
  37. }
  38. class SET_IMMEDIATE extends ABSTRACT {
  39. constructor(constraints) {
  40. super();
  41. this.constraints = constraints;
  42. }
  43. toSql(queryGenerator) {
  44. return queryGenerator.setImmediateQuery(this.constraints);
  45. }
  46. }
  47. const Deferrable = {
  48. INITIALLY_DEFERRED: classToInvokable(INITIALLY_DEFERRED),
  49. INITIALLY_IMMEDIATE: classToInvokable(INITIALLY_IMMEDIATE),
  50. NOT: classToInvokable(NOT),
  51. SET_DEFERRED: classToInvokable(SET_DEFERRED),
  52. SET_IMMEDIATE: classToInvokable(SET_IMMEDIATE)
  53. };
  54. module.exports = Deferrable;
  55. //# sourceMappingURL=deferrable.js.map