IFunctionBuilder.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OCP\DB\QueryBuilder;
  7. /**
  8. * This class provides a builder for sql some functions
  9. *
  10. * @since 12.0.0
  11. */
  12. interface IFunctionBuilder {
  13. /**
  14. * Calculates the MD5 hash of a given input
  15. *
  16. * @param string|ILiteral|IParameter|IQueryFunction $input The input to be hashed
  17. *
  18. * @return IQueryFunction
  19. * @since 12.0.0
  20. */
  21. public function md5($input): IQueryFunction;
  22. /**
  23. * Combines two input strings
  24. *
  25. * @param string|ILiteral|IParameter|IQueryFunction $x Expressions or literal strings
  26. * @param string|ILiteral|IParameter|IQueryFunction ...$exprs Expressions or literal strings
  27. *
  28. * @return IQueryFunction
  29. * @since 12.0.0
  30. */
  31. public function concat($x, ...$expr): IQueryFunction;
  32. /**
  33. * Returns a string which is the concatenation of all non-NULL values of X
  34. *
  35. * Usage examples:
  36. *
  37. * groupConcat('column') -- with comma as separator (default separator)
  38. *
  39. * groupConcat('column', ';') -- with different separator
  40. *
  41. * @param string|IQueryFunction $expr The expression to group
  42. * @param string|null $separator The separator
  43. * @return IQueryFunction
  44. * @since 24.0.0
  45. */
  46. public function groupConcat($expr, ?string $separator = ','): IQueryFunction;
  47. /**
  48. * Takes a substring from the input string
  49. *
  50. * @param string|ILiteral|IParameter|IQueryFunction $input The input string
  51. * @param string|ILiteral|IParameter|IQueryFunction $start The start of the substring, note that counting starts at 1
  52. * @param null|ILiteral|IParameter|IQueryFunction $length The length of the substring
  53. *
  54. * @return IQueryFunction
  55. * @since 12.0.0
  56. */
  57. public function substring($input, $start, $length = null): IQueryFunction;
  58. /**
  59. * Takes the sum of all rows in a column
  60. *
  61. * @param string|ILiteral|IParameter|IQueryFunction $field the column to sum
  62. *
  63. * @return IQueryFunction
  64. * @since 12.0.0
  65. */
  66. public function sum($field): IQueryFunction;
  67. /**
  68. * Transforms a string field or value to lower case
  69. *
  70. * @param string|ILiteral|IParameter|IQueryFunction $field
  71. * @return IQueryFunction
  72. * @since 14.0.0
  73. */
  74. public function lower($field): IQueryFunction;
  75. /**
  76. * @param string|ILiteral|IParameter|IQueryFunction $x The first input field or number
  77. * @param string|ILiteral|IParameter|IQueryFunction $y The second input field or number
  78. * @return IQueryFunction
  79. * @since 14.0.0
  80. */
  81. public function add($x, $y): IQueryFunction;
  82. /**
  83. * @param string|ILiteral|IParameter|IQueryFunction $x The first input field or number
  84. * @param string|ILiteral|IParameter|IQueryFunction $y The second input field or number
  85. * @return IQueryFunction
  86. * @since 14.0.0
  87. */
  88. public function subtract($x, $y): IQueryFunction;
  89. /**
  90. * @param string|ILiteral|IParameter|IQueryFunction $count The input to be counted
  91. * @param string $alias Alias for the counter
  92. *
  93. * @return IQueryFunction
  94. * @since 14.0.0
  95. */
  96. public function count($count = '', $alias = ''): IQueryFunction;
  97. /**
  98. * @param string|ILiteral|IParameter|IQueryFunction $field The input to be measured
  99. * @param string $alias Alias for the length
  100. *
  101. * @return IQueryFunction
  102. * @since 24.0.0
  103. */
  104. public function octetLength($field, $alias = ''): IQueryFunction;
  105. /**
  106. * @param string|ILiteral|IParameter|IQueryFunction $field The input to be measured
  107. * @param string $alias Alias for the length
  108. *
  109. * @return IQueryFunction
  110. * @since 24.0.0
  111. */
  112. public function charLength($field, $alias = ''): IQueryFunction;
  113. /**
  114. * Takes the maximum of all rows in a column
  115. *
  116. * If you want to get the maximum value of multiple columns in the same row, use `greatest` instead
  117. *
  118. * @param string|ILiteral|IParameter|IQueryFunction $field the column to maximum
  119. *
  120. * @return IQueryFunction
  121. * @since 18.0.0
  122. */
  123. public function max($field): IQueryFunction;
  124. /**
  125. * Takes the minimum of all rows in a column
  126. *
  127. * If you want to get the minimum value of multiple columns in the same row, use `least` instead
  128. *
  129. * @param string|ILiteral|IParameter|IQueryFunction $field the column to minimum
  130. *
  131. * @return IQueryFunction
  132. * @since 18.0.0
  133. */
  134. public function min($field): IQueryFunction;
  135. /**
  136. * Takes the maximum of multiple values
  137. *
  138. * If you want to get the maximum value of all rows in a column, use `max` instead
  139. *
  140. * @param string|ILiteral|IParameter|IQueryFunction $x
  141. * @param string|ILiteral|IParameter|IQueryFunction $y
  142. * @return IQueryFunction
  143. * @since 18.0.0
  144. */
  145. public function greatest($x, $y): IQueryFunction;
  146. /**
  147. * Takes the minimum of multiple values
  148. *
  149. * If you want to get the minimum value of all rows in a column, use `min` instead
  150. *
  151. * @param string|ILiteral|IParameter|IQueryFunction $x
  152. * @param string|ILiteral|IParameter|IQueryFunction $y
  153. * @return IQueryFunction
  154. * @since 18.0.0
  155. */
  156. public function least($x, $y): IQueryFunction;
  157. }