@@ -47,17 +47,19 @@ public final class PostgrestQueryBuilder: PostgrestBuilder, @unchecked Sendable
4747  ///   - values: The values to insert. Pass an object to insert a single row or an array to insert multiple rows.
4848  ///   - count: Count algorithm to use to count inserted rows.
4949  public  func  insert( 
50-     _ values:  some  Encodable   &   Sendable , 
50+     _ values:  some  Encodable , 
5151    returning:  PostgrestReturningOptions ? =  nil , 
5252    count:  CountOption ? =  nil 
5353  )  throws  ->  PostgrestFilterBuilder  { 
54+     let  body  =  try . encoder. encode ( values) 
55+ 
5456    try . withValue  { 
5557      $0. request. method =  . post
5658      var  prefersHeaders :  [ String ]  =  [ ] 
5759      if  let  returning { 
5860        prefersHeaders. append ( " return= \( returning. rawValue) " ) 
5961      } 
60-       $0. request. body =  try  configuration . encoder . encode ( values ) 
62+       $0. request. body =  body 
6163      if  let  count { 
6264        prefersHeaders. append ( " count= \( count. rawValue) " ) 
6365      } 
@@ -68,14 +70,16 @@ public final class PostgrestQueryBuilder: PostgrestBuilder, @unchecked Sendable
6870        $0. request. headers [ . prefer]  =  prefersHeaders. joined ( separator:  " , " ) 
6971      } 
7072      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 ] ] 
7274      { 
7375        let  allKeys  =  jsonObject. flatMap ( \. keys) 
7476        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+         ) 
7983      } 
8084    } 
8185
@@ -94,12 +98,14 @@ public final class PostgrestQueryBuilder: PostgrestBuilder, @unchecked Sendable
9498  ///   - count: Count algorithm to use to count upserted rows.
9599  ///   - ignoreDuplicates: If `true`, duplicate rows are ignored. If `false`, duplicate rows are merged with existing rows.
96100  public  func  upsert( 
97-     _ values:  some  Encodable   &   Sendable , 
101+     _ values:  some  Encodable , 
98102    onConflict:  String ? =  nil , 
99103    returning:  PostgrestReturningOptions  =  . representation, 
100104    count:  CountOption ? =  nil , 
101105    ignoreDuplicates:  Bool  =  false 
102106  )  throws  ->  PostgrestFilterBuilder  { 
107+     let  body  =  try . encoder. encode ( values) 
108+ 
103109    try . withValue  { 
104110      $0. request. method =  . post
105111      var  prefersHeaders  =  [ 
@@ -109,7 +115,7 @@ public final class PostgrestQueryBuilder: PostgrestBuilder, @unchecked Sendable
109115      if  let  onConflict { 
110116        $0. request. query. appendOrUpdate ( URLQueryItem ( name:  " on_conflict " ,  value:  onConflict) ) 
111117      } 
112-       $0. request. body =  try  configuration . encoder . encode ( values ) 
118+       $0. request. body =  body 
113119      if  let  count { 
114120        prefersHeaders. append ( " count= \( count. rawValue) " ) 
115121      } 
@@ -121,14 +127,16 @@ public final class PostgrestQueryBuilder: PostgrestBuilder, @unchecked Sendable
121127      } 
122128
123129      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 ] ] 
125131      { 
126132        let  allKeys  =  jsonObject. flatMap ( \. keys) 
127133        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+         ) 
132140      } 
133141    } 
134142    return  PostgrestFilterBuilder ( self ) 
@@ -142,14 +150,15 @@ public final class PostgrestQueryBuilder: PostgrestBuilder, @unchecked Sendable
142150  ///   - values: The values to update with.
143151  ///   - count: Count algorithm to use to count rows in a table.
144152  public  func  update( 
145-     _ values:  some  Encodable   &   Sendable , 
153+     _ values:  some  Encodable , 
146154    returning:  PostgrestReturningOptions  =  . representation, 
147155    count:  CountOption ? =  nil 
148156  )  throws  ->  PostgrestFilterBuilder  { 
149-     try . withValue  { 
157+     let  body  =  try . encoder. encode ( values) 
158+     mutableState. withValue  { 
150159      $0. request. method =  . patch
151160      var  preferHeaders  =  [ " return= \( returning. rawValue) " ] 
152-       $0. request. body =  try  configuration . encoder . encode ( values ) 
161+       $0. request. body =  body 
153162      if  let  count { 
154163        preferHeaders. append ( " count= \( count. rawValue) " ) 
155164      } 
0 commit comments