count.cjs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. "use strict";
  2. var __defProp = Object.defineProperty;
  3. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  4. var __getOwnPropNames = Object.getOwnPropertyNames;
  5. var __hasOwnProp = Object.prototype.hasOwnProperty;
  6. var __export = (target, all) => {
  7. for (var name in all)
  8. __defProp(target, name, { get: all[name], enumerable: true });
  9. };
  10. var __copyProps = (to, from, except, desc) => {
  11. if (from && typeof from === "object" || typeof from === "function") {
  12. for (let key of __getOwnPropNames(from))
  13. if (!__hasOwnProp.call(to, key) && key !== except)
  14. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  15. }
  16. return to;
  17. };
  18. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  19. var count_exports = {};
  20. __export(count_exports, {
  21. GelCountBuilder: () => GelCountBuilder
  22. });
  23. module.exports = __toCommonJS(count_exports);
  24. var import_entity = require("../../entity.cjs");
  25. var import_sql = require("../../sql/sql.cjs");
  26. class GelCountBuilder extends import_sql.SQL {
  27. constructor(params) {
  28. super(GelCountBuilder.buildEmbeddedCount(params.source, params.filters).queryChunks);
  29. this.params = params;
  30. this.mapWith(Number);
  31. this.session = params.session;
  32. this.sql = GelCountBuilder.buildCount(
  33. params.source,
  34. params.filters
  35. );
  36. }
  37. sql;
  38. static [import_entity.entityKind] = "GelCountBuilder";
  39. [Symbol.toStringTag] = "GelCountBuilder";
  40. session;
  41. static buildEmbeddedCount(source, filters) {
  42. return import_sql.sql`(select count(*) from ${source}${import_sql.sql.raw(" where ").if(filters)}${filters})`;
  43. }
  44. static buildCount(source, filters) {
  45. return import_sql.sql`select count(*) as count from ${source}${import_sql.sql.raw(" where ").if(filters)}${filters};`;
  46. }
  47. then(onfulfilled, onrejected) {
  48. return Promise.resolve(this.session.count(this.sql)).then(
  49. onfulfilled,
  50. onrejected
  51. );
  52. }
  53. catch(onRejected) {
  54. return this.then(void 0, onRejected);
  55. }
  56. finally(onFinally) {
  57. return this.then(
  58. (value) => {
  59. onFinally?.();
  60. return value;
  61. },
  62. (reason) => {
  63. onFinally?.();
  64. throw reason;
  65. }
  66. );
  67. }
  68. }
  69. // Annotate the CommonJS export names for ESM import in node:
  70. 0 && (module.exports = {
  71. GelCountBuilder
  72. });
  73. //# sourceMappingURL=count.cjs.map