count.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { entityKind } from "../../entity.js";
  2. import { SQL, sql } from "../../sql/sql.js";
  3. class SQLiteCountBuilder extends SQL {
  4. constructor(params) {
  5. super(SQLiteCountBuilder.buildEmbeddedCount(params.source, params.filters).queryChunks);
  6. this.params = params;
  7. this.session = params.session;
  8. this.sql = SQLiteCountBuilder.buildCount(
  9. params.source,
  10. params.filters
  11. );
  12. }
  13. sql;
  14. static [entityKind] = "SQLiteCountBuilderAsync";
  15. [Symbol.toStringTag] = "SQLiteCountBuilderAsync";
  16. session;
  17. static buildEmbeddedCount(source, filters) {
  18. return sql`(select count(*) from ${source}${sql.raw(" where ").if(filters)}${filters})`;
  19. }
  20. static buildCount(source, filters) {
  21. return sql`select count(*) from ${source}${sql.raw(" where ").if(filters)}${filters}`;
  22. }
  23. then(onfulfilled, onrejected) {
  24. return Promise.resolve(this.session.count(this.sql)).then(
  25. onfulfilled,
  26. onrejected
  27. );
  28. }
  29. catch(onRejected) {
  30. return this.then(void 0, onRejected);
  31. }
  32. finally(onFinally) {
  33. return this.then(
  34. (value) => {
  35. onFinally?.();
  36. return value;
  37. },
  38. (reason) => {
  39. onFinally?.();
  40. throw reason;
  41. }
  42. );
  43. }
  44. }
  45. export {
  46. SQLiteCountBuilder
  47. };
  48. //# sourceMappingURL=count.js.map