count.cjs 2.3 KB

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