aggregate.cjs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 aggregate_exports = {};
  20. __export(aggregate_exports, {
  21. avg: () => avg,
  22. avgDistinct: () => avgDistinct,
  23. count: () => count,
  24. countDistinct: () => countDistinct,
  25. max: () => max,
  26. min: () => min,
  27. sum: () => sum,
  28. sumDistinct: () => sumDistinct
  29. });
  30. module.exports = __toCommonJS(aggregate_exports);
  31. var import_column = require("../../column.cjs");
  32. var import_entity = require("../../entity.cjs");
  33. var import_sql = require("../sql.cjs");
  34. function count(expression) {
  35. return import_sql.sql`count(${expression || import_sql.sql.raw("*")})`.mapWith(Number);
  36. }
  37. function countDistinct(expression) {
  38. return import_sql.sql`count(distinct ${expression})`.mapWith(Number);
  39. }
  40. function avg(expression) {
  41. return import_sql.sql`avg(${expression})`.mapWith(String);
  42. }
  43. function avgDistinct(expression) {
  44. return import_sql.sql`avg(distinct ${expression})`.mapWith(String);
  45. }
  46. function sum(expression) {
  47. return import_sql.sql`sum(${expression})`.mapWith(String);
  48. }
  49. function sumDistinct(expression) {
  50. return import_sql.sql`sum(distinct ${expression})`.mapWith(String);
  51. }
  52. function max(expression) {
  53. return import_sql.sql`max(${expression})`.mapWith((0, import_entity.is)(expression, import_column.Column) ? expression : String);
  54. }
  55. function min(expression) {
  56. return import_sql.sql`min(${expression})`.mapWith((0, import_entity.is)(expression, import_column.Column) ? expression : String);
  57. }
  58. // Annotate the CommonJS export names for ESM import in node:
  59. 0 && (module.exports = {
  60. avg,
  61. avgDistinct,
  62. count,
  63. countDistinct,
  64. max,
  65. min,
  66. sum,
  67. sumDistinct
  68. });
  69. //# sourceMappingURL=aggregate.cjs.map