count.cjs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. PgCountBuilder: () => PgCountBuilder
  22. });
  23. module.exports = __toCommonJS(count_exports);
  24. var import_entity = require("../../entity.cjs");
  25. var import_sql = require("../../sql/sql.cjs");
  26. class PgCountBuilder extends import_sql.SQL {
  27. constructor(params) {
  28. super(PgCountBuilder.buildEmbeddedCount(params.source, params.filters).queryChunks);
  29. this.params = params;
  30. this.mapWith(Number);
  31. this.session = params.session;
  32. this.sql = PgCountBuilder.buildCount(
  33. params.source,
  34. params.filters
  35. );
  36. }
  37. sql;
  38. token;
  39. static [import_entity.entityKind] = "PgCountBuilder";
  40. [Symbol.toStringTag] = "PgCountBuilder";
  41. session;
  42. static buildEmbeddedCount(source, filters) {
  43. return import_sql.sql`(select count(*) from ${source}${import_sql.sql.raw(" where ").if(filters)}${filters})`;
  44. }
  45. static buildCount(source, filters) {
  46. return import_sql.sql`select count(*) as count from ${source}${import_sql.sql.raw(" where ").if(filters)}${filters};`;
  47. }
  48. /** @intrnal */
  49. setToken(token) {
  50. this.token = token;
  51. return this;
  52. }
  53. then(onfulfilled, onrejected) {
  54. return Promise.resolve(this.session.count(this.sql, this.token)).then(
  55. onfulfilled,
  56. onrejected
  57. );
  58. }
  59. catch(onRejected) {
  60. return this.then(void 0, onRejected);
  61. }
  62. finally(onFinally) {
  63. return this.then(
  64. (value) => {
  65. onFinally?.();
  66. return value;
  67. },
  68. (reason) => {
  69. onFinally?.();
  70. throw reason;
  71. }
  72. );
  73. }
  74. }
  75. // Annotate the CommonJS export names for ESM import in node:
  76. 0 && (module.exports = {
  77. PgCountBuilder
  78. });
  79. //# sourceMappingURL=count.cjs.map