Skip to content

Commit

Permalink
move deprecated code to Deprecated.swift file
Browse files Browse the repository at this point in the history
  • Loading branch information
grdsdev committed Jan 30, 2025
1 parent e93d10a commit e5a7a74
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 68 deletions.
25 changes: 23 additions & 2 deletions .swiftpm/xcode/xcshareddata/xcschemes/PostgREST.xcscheme
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1510"
version = "1.7">
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
Expand All @@ -26,8 +26,29 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES"
onlyGenerateCoverageForSpecifiedTargets = "YES">
<CodeCoverageTargets>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "PostgREST"
BuildableName = "PostgREST"
BlueprintName = "PostgREST"
ReferencedContainer = "container:">
</BuildableReference>
</CodeCoverageTargets>
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "PostgRESTTests"
BuildableName = "PostgRESTTests"
BlueprintName = "PostgRESTTests"
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
Expand Down
60 changes: 58 additions & 2 deletions Sources/PostgREST/Deprecated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ extension PostgrestClient.Configuration {
@available(
*,
deprecated,
message: "Replace usages of this initializer with new init(url:schema:headers:logger:fetch:encoder:decoder:)"
message:
"Replace usages of this initializer with new init(url:schema:headers:logger:fetch:encoder:decoder:)"
)
public init(
url: URL,
Expand Down Expand Up @@ -57,7 +58,8 @@ extension PostgrestClient {
@available(
*,
deprecated,
message: "Replace usages of this initializer with new init(url:schema:headers:logger:fetch:encoder:decoder:)"
message:
"Replace usages of this initializer with new init(url:schema:headers:logger:fetch:encoder:decoder:)"
)
public convenience init(
url: URL,
Expand All @@ -78,3 +80,57 @@ extension PostgrestClient {
)
}
}

extension PostgrestFilterBuilder {

@available(*, deprecated, renamed: "like(_:pattern:)")
public func like(
_ column: String,
value: any URLQueryRepresentable
) -> PostgrestFilterBuilder {
like(column, pattern: value)
}

@available(*, deprecated, renamed: "in(_:values:)")
public func `in`(
_ column: String,
value: [any URLQueryRepresentable]
) -> PostgrestFilterBuilder {
`in`(column, values: value)
}

@available(*, deprecated, message: "Use textSearch(_:query:config:type) with .plain type.")
public func plfts(
_ column: String,
query: any URLQueryRepresentable,
config: String? = nil
) -> PostgrestFilterBuilder {
textSearch(column, query: query, config: config, type: .plain)
}

@available(*, deprecated, message: "Use textSearch(_:query:config:type) with .phrase type.")
public func phfts(
_ column: String,
query: any URLQueryRepresentable,
config: String? = nil
) -> PostgrestFilterBuilder {
textSearch(column, query: query, config: config, type: .phrase)
}

@available(*, deprecated, message: "Use textSearch(_:query:config:type) with .websearch type.")
public func wfts(
_ column: String,
query: any URLQueryRepresentable,
config: String? = nil
) -> PostgrestFilterBuilder {
textSearch(column, query: query, config: config, type: .websearch)
}

@available(*, deprecated, renamed: "ilike(_:pattern:)")
public func ilike(
_ column: String,
value: any URLQueryRepresentable
) -> PostgrestFilterBuilder {
ilike(column, pattern: value)
}
}
80 changes: 16 additions & 64 deletions Sources/PostgREST/PostgrestFilterBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Helpers
public class PostgrestFilterBuilder: PostgrestTransformBuilder, @unchecked Sendable {
public enum Operator: String, CaseIterable, Sendable {
case eq, neq, gt, gte, lt, lte, like, ilike, `is`, `in`, cs, cd, sl, sr, nxl, nxr, adj, ov, fts,
plfts, phfts, wfts
plfts, phfts, wfts
}

// MARK: - Filters
Expand All @@ -17,10 +17,11 @@ public class PostgrestFilterBuilder: PostgrestTransformBuilder, @unchecked Senda
let queryValue = value.queryValue

mutableState.withValue {
$0.request.query.append(URLQueryItem(
name: column,
value: "not.\(op.rawValue).\(queryValue)"
))
$0.request.query.append(
URLQueryItem(
name: column,
value: "not.\(op.rawValue).\(queryValue)"
))
}

return self
Expand Down Expand Up @@ -152,14 +153,6 @@ public class PostgrestFilterBuilder: PostgrestTransformBuilder, @unchecked Senda
return self
}

@available(*, deprecated, renamed: "like(_:pattern:)")
public func like(
_ column: String,
value: any URLQueryRepresentable
) -> PostgrestFilterBuilder {
like(column, pattern: value)
}

/// Match only rows where `column` matches all of `patterns` case-sensitively.
/// - Parameters:
/// - column: The column to filter on
Expand Down Expand Up @@ -206,14 +199,6 @@ public class PostgrestFilterBuilder: PostgrestTransformBuilder, @unchecked Senda
return self
}

@available(*, deprecated, renamed: "ilike(_:pattern:)")
public func ilike(
_ column: String,
value: any URLQueryRepresentable
) -> PostgrestFilterBuilder {
ilike(column, pattern: value)
}

/// Match only rows where `column` matches all of `patterns` case-insensitively.
/// - Parameters:
/// - column: The column to filter on
Expand Down Expand Up @@ -284,14 +269,6 @@ public class PostgrestFilterBuilder: PostgrestTransformBuilder, @unchecked Senda
return self
}

@available(*, deprecated, renamed: "in(_:values:)")
public func `in`(
_ column: String,
value: [any URLQueryRepresentable]
) -> PostgrestFilterBuilder {
`in`(column, values: value)
}

/// Match only rows where `column` contains every element appearing in `value`.
///
/// Only relevant for jsonb, array, and range columns.
Expand Down Expand Up @@ -472,33 +449,6 @@ public class PostgrestFilterBuilder: PostgrestTransformBuilder, @unchecked Senda
textSearch(column, query: query, config: config, type: nil)
}

@available(*, deprecated, message: "Use textSearch(_:query:config:type) with .plain type.")
public func plfts(
_ column: String,
query: any URLQueryRepresentable,
config: String? = nil
) -> PostgrestFilterBuilder {
textSearch(column, query: query, config: config, type: .plain)
}

@available(*, deprecated, message: "Use textSearch(_:query:config:type) with .phrase type.")
public func phfts(
_ column: String,
query: any URLQueryRepresentable,
config: String? = nil
) -> PostgrestFilterBuilder {
textSearch(column, query: query, config: config, type: .phrase)
}

@available(*, deprecated, message: "Use textSearch(_:query:config:type) with .websearch type.")
public func wfts(
_ column: String,
query: any URLQueryRepresentable,
config: String? = nil
) -> PostgrestFilterBuilder {
textSearch(column, query: query, config: config, type: .websearch)
}

/// Match only rows which satisfy the filter. This is an escape hatch - you should use the specific filter methods wherever possible.
///
/// Unlike most filters, `opearator` and `value` are used as-is and need to follow [PostgREST syntax](https://postgrest.org/en/stable/api.html#operators). You also need to make sure they are properly sanitized.
Expand All @@ -513,10 +463,11 @@ public class PostgrestFilterBuilder: PostgrestTransformBuilder, @unchecked Senda
value: String
) -> PostgrestFilterBuilder {
mutableState.withValue {
$0.request.query.append(URLQueryItem(
name: column,
value: "\(`operator`).\(value)"
))
$0.request.query.append(
URLQueryItem(
name: column,
value: "\(`operator`).\(value)"
))
}
return self
}
Expand All @@ -530,10 +481,11 @@ public class PostgrestFilterBuilder: PostgrestTransformBuilder, @unchecked Senda
let query = query.mapValues(\.queryValue)
mutableState.withValue { mutableState in
for (key, value) in query {
mutableState.request.query.append(URLQueryItem(
name: key,
value: "eq.\(value.queryValue)"
))
mutableState.request.query.append(
URLQueryItem(
name: key,
value: "eq.\(value.queryValue)"
))
}
}
return self
Expand Down

0 comments on commit e5a7a74

Please sign in to comment.