@@ -47,17 +47,19 @@ public final class PostgrestQueryBuilder: PostgrestBuilder, @unchecked Sendable
47
47
/// - values: The values to insert. Pass an object to insert a single row or an array to insert multiple rows.
48
48
/// - count: Count algorithm to use to count inserted rows.
49
49
public func insert(
50
- _ values: some Encodable & Sendable ,
50
+ _ values: some Encodable ,
51
51
returning: PostgrestReturningOptions ? = nil ,
52
52
count: CountOption ? = nil
53
53
) throws -> PostgrestFilterBuilder {
54
+ let body = try configuration. encoder. encode ( values)
55
+
54
56
try mutableState. withValue {
55
57
$0. request. method = . post
56
58
var prefersHeaders : [ String ] = [ ]
57
59
if let returning {
58
60
prefersHeaders. append ( " return= \( returning. rawValue) " )
59
61
}
60
- $0. request. body = try configuration . encoder . encode ( values )
62
+ $0. request. body = body
61
63
if let count {
62
64
prefersHeaders. append ( " count= \( count. rawValue) " )
63
65
}
@@ -68,14 +70,16 @@ public final class PostgrestQueryBuilder: PostgrestBuilder, @unchecked Sendable
68
70
$0. request. headers [ . prefer] = prefersHeaders. joined ( separator: " , " )
69
71
}
70
72
if let body = $0. request. body,
71
- let jsonObject = try JSONSerialization . jsonObject ( with: body) as? [ [ String : Any ] ]
73
+ let jsonObject = try JSONSerialization . jsonObject ( with: body) as? [ [ String : Any ] ]
72
74
{
73
75
let allKeys = jsonObject. flatMap ( \. keys)
74
76
let uniqueKeys = Set ( allKeys) . sorted ( )
75
- $0. request. query. appendOrUpdate ( URLQueryItem (
76
- name: " columns " ,
77
- value: uniqueKeys. joined ( separator: " , " )
78
- ) )
77
+ $0. request. query. appendOrUpdate (
78
+ URLQueryItem (
79
+ name: " columns " ,
80
+ value: uniqueKeys. joined ( separator: " , " )
81
+ )
82
+ )
79
83
}
80
84
}
81
85
@@ -94,12 +98,14 @@ public final class PostgrestQueryBuilder: PostgrestBuilder, @unchecked Sendable
94
98
/// - count: Count algorithm to use to count upserted rows.
95
99
/// - ignoreDuplicates: If `true`, duplicate rows are ignored. If `false`, duplicate rows are merged with existing rows.
96
100
public func upsert(
97
- _ values: some Encodable & Sendable ,
101
+ _ values: some Encodable ,
98
102
onConflict: String ? = nil ,
99
103
returning: PostgrestReturningOptions = . representation,
100
104
count: CountOption ? = nil ,
101
105
ignoreDuplicates: Bool = false
102
106
) throws -> PostgrestFilterBuilder {
107
+ let body = try configuration. encoder. encode ( values)
108
+
103
109
try mutableState. withValue {
104
110
$0. request. method = . post
105
111
var prefersHeaders = [
@@ -109,7 +115,7 @@ public final class PostgrestQueryBuilder: PostgrestBuilder, @unchecked Sendable
109
115
if let onConflict {
110
116
$0. request. query. appendOrUpdate ( URLQueryItem ( name: " on_conflict " , value: onConflict) )
111
117
}
112
- $0. request. body = try configuration . encoder . encode ( values )
118
+ $0. request. body = body
113
119
if let count {
114
120
prefersHeaders. append ( " count= \( count. rawValue) " )
115
121
}
@@ -121,14 +127,16 @@ public final class PostgrestQueryBuilder: PostgrestBuilder, @unchecked Sendable
121
127
}
122
128
123
129
if let body = $0. request. body,
124
- let jsonObject = try JSONSerialization . jsonObject ( with: body) as? [ [ String : Any ] ]
130
+ let jsonObject = try JSONSerialization . jsonObject ( with: body) as? [ [ String : Any ] ]
125
131
{
126
132
let allKeys = jsonObject. flatMap ( \. keys)
127
133
let uniqueKeys = Set ( allKeys) . sorted ( )
128
- $0. request. query. appendOrUpdate ( URLQueryItem (
129
- name: " columns " ,
130
- value: uniqueKeys. joined ( separator: " , " )
131
- ) )
134
+ $0. request. query. appendOrUpdate (
135
+ URLQueryItem (
136
+ name: " columns " ,
137
+ value: uniqueKeys. joined ( separator: " , " )
138
+ )
139
+ )
132
140
}
133
141
}
134
142
return PostgrestFilterBuilder ( self )
@@ -142,14 +150,15 @@ public final class PostgrestQueryBuilder: PostgrestBuilder, @unchecked Sendable
142
150
/// - values: The values to update with.
143
151
/// - count: Count algorithm to use to count rows in a table.
144
152
public func update(
145
- _ values: some Encodable & Sendable ,
153
+ _ values: some Encodable ,
146
154
returning: PostgrestReturningOptions = . representation,
147
155
count: CountOption ? = nil
148
156
) throws -> PostgrestFilterBuilder {
149
- try mutableState. withValue {
157
+ let body = try configuration. encoder. encode ( values)
158
+ mutableState. withValue {
150
159
$0. request. method = . patch
151
160
var preferHeaders = [ " return= \( returning. rawValue) " ]
152
- $0. request. body = try configuration . encoder . encode ( values )
161
+ $0. request. body = body
153
162
if let count {
154
163
preferHeaders. append ( " count= \( count. rawValue) " )
155
164
}
0 commit comments