aggregate.d.cts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import { type AnyColumn } from "../../column.cjs";
  2. import { type SQL, type SQLWrapper } from "../sql.cjs";
  3. /**
  4. * Returns the number of values in `expression`.
  5. *
  6. * ## Examples
  7. *
  8. * ```ts
  9. * // Number employees with null values
  10. * db.select({ value: count() }).from(employees)
  11. * // Number of employees where `name` is not null
  12. * db.select({ value: count(employees.name) }).from(employees)
  13. * ```
  14. *
  15. * @see countDistinct to get the number of non-duplicate values in `expression`
  16. */
  17. export declare function count(expression?: SQLWrapper): SQL<number>;
  18. /**
  19. * Returns the number of non-duplicate values in `expression`.
  20. *
  21. * ## Examples
  22. *
  23. * ```ts
  24. * // Number of employees where `name` is distinct
  25. * db.select({ value: countDistinct(employees.name) }).from(employees)
  26. * ```
  27. *
  28. * @see count to get the number of values in `expression`, including duplicates
  29. */
  30. export declare function countDistinct(expression: SQLWrapper): SQL<number>;
  31. /**
  32. * Returns the average (arithmetic mean) of all non-null values in `expression`.
  33. *
  34. * ## Examples
  35. *
  36. * ```ts
  37. * // Average salary of an employee
  38. * db.select({ value: avg(employees.salary) }).from(employees)
  39. * ```
  40. *
  41. * @see avgDistinct to get the average of all non-null and non-duplicate values in `expression`
  42. */
  43. export declare function avg(expression: SQLWrapper): SQL<string | null>;
  44. /**
  45. * Returns the average (arithmetic mean) of all non-null and non-duplicate values in `expression`.
  46. *
  47. * ## Examples
  48. *
  49. * ```ts
  50. * // Average salary of an employee where `salary` is distinct
  51. * db.select({ value: avgDistinct(employees.salary) }).from(employees)
  52. * ```
  53. *
  54. * @see avg to get the average of all non-null values in `expression`, including duplicates
  55. */
  56. export declare function avgDistinct(expression: SQLWrapper): SQL<string | null>;
  57. /**
  58. * Returns the sum of all non-null values in `expression`.
  59. *
  60. * ## Examples
  61. *
  62. * ```ts
  63. * // Sum of every employee's salary
  64. * db.select({ value: sum(employees.salary) }).from(employees)
  65. * ```
  66. *
  67. * @see sumDistinct to get the sum of all non-null and non-duplicate values in `expression`
  68. */
  69. export declare function sum(expression: SQLWrapper): SQL<string | null>;
  70. /**
  71. * Returns the sum of all non-null and non-duplicate values in `expression`.
  72. *
  73. * ## Examples
  74. *
  75. * ```ts
  76. * // Sum of every employee's salary where `salary` is distinct (no duplicates)
  77. * db.select({ value: sumDistinct(employees.salary) }).from(employees)
  78. * ```
  79. *
  80. * @see sum to get the sum of all non-null values in `expression`, including duplicates
  81. */
  82. export declare function sumDistinct(expression: SQLWrapper): SQL<string | null>;
  83. /**
  84. * Returns the maximum value in `expression`.
  85. *
  86. * ## Examples
  87. *
  88. * ```ts
  89. * // The employee with the highest salary
  90. * db.select({ value: max(employees.salary) }).from(employees)
  91. * ```
  92. */
  93. export declare function max<T extends SQLWrapper>(expression: T): SQL<(T extends AnyColumn ? T['_']['data'] : string) | null>;
  94. /**
  95. * Returns the minimum value in `expression`.
  96. *
  97. * ## Examples
  98. *
  99. * ```ts
  100. * // The employee with the lowest salary
  101. * db.select({ value: min(employees.salary) }).from(employees)
  102. * ```
  103. */
  104. export declare function min<T extends SQLWrapper>(expression: T): SQL<(T extends AnyColumn ? T['_']['data'] : string) | null>;