@@ -18,6 +18,7 @@ import io.github.jan.supabase.postgrest.request.UpdateRequest
18
18
import io.github.jan.supabase.postgrest.result.PostgrestResult
19
19
import io.ktor.client.plugins.HttpRequestTimeoutException
20
20
import kotlinx.serialization.json.JsonArray
21
+ import kotlinx.serialization.json.JsonElement
21
22
import kotlinx.serialization.json.jsonArray
22
23
import kotlinx.serialization.json.jsonObject
23
24
@@ -230,28 +231,47 @@ class PostgrestQueryBuilder(
230
231
*
231
232
* By default, updated rows are not returned. To return it, call `[PostgrestRequestBuilder.select]`.
232
233
*
233
- * @param value The value to update, will automatically get serialized into json .
234
+ * @param body The request body representing the value to update .
234
235
* @param request Additional filtering to apply to the query
235
236
* @throws PostgrestRestException if receiving an error response
236
237
* @throws HttpRequestTimeoutException if the request timed out
237
238
* @throws HttpRequestException on network related issues
238
239
*/
239
- suspend inline fun < reified T : Any > update (
240
- value : T ,
240
+ suspend inline fun update (
241
+ body : JsonElement ,
241
242
request : PostgrestRequestBuilder .() -> Unit = {}
242
243
): PostgrestResult {
243
244
val requestBuilder = PostgrestRequestBuilder (postgrest.config.propertyConversionMethod).apply (request)
244
245
val updateRequest = UpdateRequest (
246
+ body = body,
245
247
returning = requestBuilder.returning,
246
248
count = requestBuilder.count,
247
249
urlParams = requestBuilder.params.mapToFirstValue(),
248
- body = postgrest.serializer.encodeToJsonElement(value),
249
250
schema = schema,
250
251
headers = requestBuilder.headers.build()
251
252
)
252
253
return RestRequestExecutor .execute(postgrest = postgrest, path = table, request = updateRequest)
253
254
}
254
255
256
+ /* *
257
+ * Executes an update operation on the [table].
258
+ *
259
+ * By default, updated rows are not returned. To return it, call `[PostgrestRequestBuilder.select]`.
260
+ *
261
+ * @param value The value to update, will automatically get serialized into json.
262
+ * @param request Additional filtering to apply to the query
263
+ * @throws PostgrestRestException if receiving an error response
264
+ * @throws HttpRequestTimeoutException if the request timed out
265
+ * @throws HttpRequestException on network related issues
266
+ */
267
+ suspend inline fun <reified T : Any > update (
268
+ value : T ,
269
+ request : PostgrestRequestBuilder .() -> Unit = {}
270
+ ): PostgrestResult = update(
271
+ body = postgrest.serializer.encodeToJsonElement(value),
272
+ request = request
273
+ )
274
+
255
275
/* *
256
276
* Executes a delete operation on the [table].
257
277
*
0 commit comments