|
1 | 1 | import Foundation |
2 | 2 |
|
| 3 | +// NB: Deprecated after 0.33.3: |
| 4 | + |
| 5 | +extension Table { |
| 6 | + @available(*, deprecated, message: "Use 'limit(_:)' and 'offset(_:)', instead.") |
| 7 | + public static func limit( |
| 8 | + _ maxLength: (TableColumns) -> some QueryExpression<Int>, |
| 9 | + offset: ((TableColumns) -> some QueryExpression<Int>)? |
| 10 | + ) -> SelectOf<Self> { |
| 11 | + Where().limit(maxLength, offset: offset) |
| 12 | + } |
| 13 | + |
| 14 | + @available(*, deprecated, message: "Use 'limit(_:)' and 'offset(_:)', instead.") |
| 15 | + public static func limit(_ maxLength: Int, offset: Int?) -> SelectOf<Self> { |
| 16 | + Where().limit(maxLength, offset: offset) |
| 17 | + } |
| 18 | +} |
| 19 | + |
| 20 | +extension Where { |
| 21 | + @available(*, deprecated, message: "Use 'limit(_:)' and 'offset(_:)', instead.") |
| 22 | + public func limit( |
| 23 | + _ maxLength: (From.TableColumns) -> some QueryExpression<Int>, |
| 24 | + offset: ((From.TableColumns) -> some QueryExpression<Int>)? |
| 25 | + ) -> SelectOf<From> { |
| 26 | + asSelect().limit(maxLength, offset: offset) |
| 27 | + } |
| 28 | + |
| 29 | + @available(*, deprecated, message: "Use 'limit(_:)' and 'offset(_:)', instead.") |
| 30 | + public func limit(_ maxLength: Int, offset: Int?) -> SelectOf<From> { |
| 31 | + asSelect().limit(maxLength, offset: offset) |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +extension Select { |
| 36 | + @_disfavoredOverload |
| 37 | + @available(*, deprecated, message: "Use 'limit(_:)' and 'offset(_:)', instead.") |
| 38 | + public func limit<each J: Table>( |
| 39 | + _ maxLength: (From.TableColumns, repeat (each J).TableColumns) -> some QueryExpression<Int>, |
| 40 | + offset: ((From.TableColumns, repeat (each J).TableColumns) -> any QueryExpression<Int>)? |
| 41 | + ) -> Self |
| 42 | + where Joins == (repeat each J) { |
| 43 | + limit(maxLength(From.columns, repeat (each J).columns)) |
| 44 | + .offset(offset?(From.columns, repeat (each J).columns)) |
| 45 | + } |
| 46 | + |
| 47 | + @_disfavoredOverload |
| 48 | + @available(*, deprecated, message: "Use 'limit(_:)' and 'offset(_:)', instead.") |
| 49 | + public func limit( |
| 50 | + _ maxLength: (From.TableColumns, Joins.TableColumns) -> some QueryExpression<Int>, |
| 51 | + offset: ((From.TableColumns, Joins.TableColumns) -> any QueryExpression<Int>)? |
| 52 | + ) -> Self |
| 53 | + where Joins: Table { |
| 54 | + limit(maxLength(From.columns, Joins.columns)) |
| 55 | + .offset(offset?(From.columns, Joins.columns)) |
| 56 | + } |
| 57 | + |
| 58 | + @available(*, deprecated, message: "Use 'limit(_:)' and 'offset(_:)', instead.") |
| 59 | + public func limit<each J: Table>(_ maxLength: Int, offset: Int?) -> Self |
| 60 | + where Joins == (repeat each J) { |
| 61 | + limit(maxLength).offset(offset) |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | +// NB: Deprecated after 0.33.1: |
| 66 | + |
| 67 | +extension QueryExpression where QueryValue == String { |
| 68 | + @available(*, deprecated, message: "Prefer 'like(\"\\(other)%\")' instead") |
| 69 | + public func hasPrefix(_ other: some StringProtocol) -> some QueryExpression<Bool> { |
| 70 | + like("\(other)%") |
| 71 | + } |
| 72 | + |
| 73 | + @available(*, deprecated, message: "Prefer 'like(\"%\\(other)\")' instead") |
| 74 | + public func hasSuffix(_ other: some StringProtocol) -> some QueryExpression<Bool> { |
| 75 | + like("%\(other)") |
| 76 | + } |
| 77 | + |
| 78 | + @_disfavoredOverload |
| 79 | + @available(*, deprecated, message: "Prefer 'like(\"%\\(other)%\")' instead") |
| 80 | + public func contains(_ other: some StringProtocol) -> some QueryExpression<Bool> { |
| 81 | + return like("%\(other)%") |
| 82 | + } |
| 83 | +} |
| 84 | + |
| 85 | +extension Sequence where Element: QueryBindable { |
| 86 | + @available(*, deprecated, message: "Prefer 'element.in(self)' instead") |
| 87 | + public func contains( |
| 88 | + _ element: some QueryExpression<Element.QueryValue> |
| 89 | + ) -> some QueryExpression<Bool> { |
| 90 | + element.in(self) |
| 91 | + } |
| 92 | +} |
| 93 | + |
| 94 | +extension ClosedRange where Bound: QueryBindable { |
| 95 | + @available( |
| 96 | + *, |
| 97 | + deprecated, |
| 98 | + message: "Prefer 'element.between(lowerBound, and: upperBound)' instead" |
| 99 | + ) |
| 100 | + public func contains( |
| 101 | + _ element: some QueryExpression<Bound.QueryValue> |
| 102 | + ) -> some QueryExpression<Bool> { |
| 103 | + element.between(lowerBound, and: upperBound) |
| 104 | + } |
| 105 | +} |
| 106 | + |
3 | 107 | // NB: Deprecated after 0.32.0: |
4 | 108 |
|
5 | 109 | extension TableDraft { |
|
0 commit comments