http urls monitor.

result.go 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. // Copyright (c) 2012-present The upper.io/db authors. All rights reserved.
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining
  4. // a copy of this software and associated documentation files (the
  5. // "Software"), to deal in the Software without restriction, including
  6. // without limitation the rights to use, copy, modify, merge, publish,
  7. // distribute, sublicense, and/or sell copies of the Software, and to
  8. // permit persons to whom the Software is furnished to do so, subject to
  9. // the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be
  12. // included in all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  16. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  17. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  18. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  19. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  20. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. package db
  22. // Result is an interface that defines methods useful for working with result
  23. // sets.
  24. type Result interface {
  25. // String satisfies fmt.Stringer and returns a SELECT statement for
  26. // the result.
  27. String() string
  28. // Limit defines the maximum number of results in this set. It only has
  29. // effect on `One()`, `All()` and `Next()`. A negative limit cancels any
  30. // previous limit settings.
  31. Limit(int) Result
  32. // Offset ignores the first *n* results. It only has effect on `One()`,
  33. // `All()` and `Next()`. A negative offset cancels any previous offset
  34. // settings.
  35. Offset(int) Result
  36. // OrderBy receives field names that define the order in which elements will be
  37. // returned in a query, field names may be prefixed with a minus sign (-)
  38. // indicating descending order, ascending order will be used otherwise.
  39. OrderBy(...interface{}) Result
  40. // Select defines specific columns to be returned from the elements of the
  41. // set.
  42. Select(...interface{}) Result
  43. // Where discards all the previously set filtering constraints (if any) and
  44. // sets new ones. Commonly used when the conditions of the result depend on
  45. // external parameters that are yet to be evaluated:
  46. //
  47. // res := col.Find()
  48. //
  49. // if ... {
  50. // res.Where(...)
  51. // } else {
  52. // res.Where(...)
  53. // }
  54. Where(...interface{}) Result
  55. // And adds more filtering conditions on top of the existing constraints.
  56. //
  57. // res := col.Find(...).And(...)
  58. And(...interface{}) Result
  59. // Group is used to group results that have the same value in the same column
  60. // or columns.
  61. Group(...interface{}) Result
  62. // Delete deletes all items within the result set. `Offset()` and `Limit()` are
  63. // not honoured by `Delete()`.
  64. Delete() error
  65. // Update modifies all items within the result set. `Offset()` and `Limit()`
  66. // are not honoured by `Update()`.
  67. Update(interface{}) error
  68. // Count returns the number of items that match the set conditions. `Offset()`
  69. // and `Limit()` are not honoured by `Count()`
  70. Count() (uint64, error)
  71. // Exists returns true if at least one item on the collection exists. False
  72. // otherwise.
  73. Exists() (bool, error)
  74. // Next fetches the next result within the result set and dumps it into the
  75. // given pointer to struct or pointer to map. You must call
  76. // `Close()` after finishing using `Next()`.
  77. Next(ptrToStruct interface{}) bool
  78. // Err returns the last error that has happened with the result set, nil
  79. // otherwise.
  80. Err() error
  81. // One fetches the first result within the result set and dumps it into the
  82. // given pointer to struct or pointer to map. The result set is automatically
  83. // closed after picking the element, so there is no need to call Close()
  84. // after using One().
  85. One(ptrToStruct interface{}) error
  86. // All fetches all results within the result set and dumps them into the
  87. // given pointer to slice of maps or structs. The result set is
  88. // automatically closed, so there is no need to call Close() after
  89. // using All().
  90. All(sliceOfStructs interface{}) error
  91. // Paginate splits the results of the query into pages containing pageSize
  92. // items. When using pagination previous settings for Limit and Offset are
  93. // ignored. Page numbering starts at 1.
  94. //
  95. // Use Page() to define the specific page to get results from.
  96. //
  97. // Example:
  98. //
  99. // r = q.Paginate(12)
  100. //
  101. // You can provide constraints an order settings when using pagination:
  102. //
  103. // Example:
  104. //
  105. // res := q.Where(conds).OrderBy("-id").Paginate(12)
  106. // err := res.Page(4).All(&items)
  107. Paginate(pageSize uint) Result
  108. // Page makes the result set return results only from the page identified by
  109. // pageNumber. Page numbering starts from 0.
  110. //
  111. // Example:
  112. //
  113. // r = q.Paginate(12).Page(4)
  114. Page(pageNumber uint) Result
  115. // Cursor defines the column that is going to be taken as basis for
  116. // cursor-based pagination.
  117. //
  118. // Example:
  119. //
  120. // a = q.Paginate(10).Cursor("id")
  121. // b = q.Paginate(12).Cursor("-id")
  122. //
  123. // You can set "" as cursorColumn to disable cursors.
  124. Cursor(cursorColumn string) Result
  125. // NextPage returns the next results page according to the cursor. It expects
  126. // a cursorValue, which is the value the cursor column had on the last item
  127. // of the current result set (lower bound).
  128. //
  129. // Example:
  130. //
  131. // cursor = q.Paginate(12).Cursor("id")
  132. // res = cursor.NextPage(items[len(items)-1].ID)
  133. //
  134. // Note that NextPage requires a cursor, any column with an absolute order
  135. // (given two values one always precedes the other) can be a cursor.
  136. //
  137. // You can define the pagination order and add constraints to your result:
  138. //
  139. // cursor = q.Where(...).OrderBy("id").Paginate(10).Cursor("id")
  140. // res = cursor.NextPage(lowerBound)
  141. NextPage(cursorValue interface{}) Result
  142. // PrevPage returns the previous results page according to the cursor. It
  143. // expects a cursorValue, which is the value the cursor column had on the
  144. // fist item of the current result set (upper bound).
  145. //
  146. // Example:
  147. //
  148. // current = current.PrevPage(items[0].ID)
  149. //
  150. // Note that PrevPage requires a cursor, any column with an absolute order
  151. // (given two values one always precedes the other) can be a cursor.
  152. //
  153. // You can define the pagination order and add constraints to your result:
  154. //
  155. // cursor = q.Where(...).OrderBy("id").Paginate(10).Cursor("id")
  156. // res = cursor.PrevPage(upperBound)
  157. PrevPage(cursorValue interface{}) Result
  158. // TotalPages returns the total number of pages the result could produce. If
  159. // no pagination has been set this value equals 1.
  160. TotalPages() (uint, error)
  161. // TotalEntries returns the total number of entries in the query.
  162. TotalEntries() (uint64, error)
  163. // Close closes the result set and frees all locked resources.
  164. Close() error
  165. }