diff --git a/Postgrest/src/commonMain/kotlin/io/github/jan/supabase/postgrest/Postgrest.kt b/Postgrest/src/commonMain/kotlin/io/github/jan/supabase/postgrest/Postgrest.kt index 15ff8d86d..00ae099e6 100644 --- a/Postgrest/src/commonMain/kotlin/io/github/jan/supabase/postgrest/Postgrest.kt +++ b/Postgrest/src/commonMain/kotlin/io/github/jan/supabase/postgrest/Postgrest.kt @@ -53,7 +53,6 @@ sealed interface Postgrest : MainPlugin, CustomSerializationPl /** * Creates a new [PostgrestQueryBuilder] for the given schema and table - * @param schema The schema to use for the requests * @param table The table to use for the requests */ operator fun get(table: String): PostgrestQueryBuilder = from(table) diff --git a/Postgrest/src/commonMain/kotlin/io/github/jan/supabase/postgrest/PostgrestRpc.kt b/Postgrest/src/commonMain/kotlin/io/github/jan/supabase/postgrest/PostgrestRpc.kt index aa0d2d4a5..d4c97c21e 100644 --- a/Postgrest/src/commonMain/kotlin/io/github/jan/supabase/postgrest/PostgrestRpc.kt +++ b/Postgrest/src/commonMain/kotlin/io/github/jan/supabase/postgrest/PostgrestRpc.kt @@ -2,8 +2,10 @@ package io.github.jan.supabase.postgrest import io.github.jan.supabase.encodeToJsonElement +import io.github.jan.supabase.exceptions.RestException import io.github.jan.supabase.postgrest.executor.RestRequestExecutor import io.github.jan.supabase.postgrest.query.PostgrestRequestBuilder +import io.github.jan.supabase.postgrest.query.request.RpcPostgrestRequestBuilder import io.github.jan.supabase.postgrest.request.RpcRequest import io.github.jan.supabase.postgrest.result.PostgrestResult import io.ktor.http.HttpMethod @@ -34,29 +36,29 @@ enum class RpcMethod(val httpMethod: HttpMethod) { * * @param function The name of the function * @param parameters The parameters for the function - * @param method The HTTP method to use. Default is POST * @param request Filter the result * @throws RestException or one of its subclasses if the request failed */ suspend inline fun Postgrest.rpc( function: String, parameters: T, - method: RpcMethod = RpcMethod.POST, - request: PostgrestRequestBuilder.() -> Unit = {}, + request: RpcPostgrestRequestBuilder.() -> Unit = {}, ): PostgrestResult { val encodedParameters = if (parameters is JsonElement) parameters else serializer.encodeToJsonElement(parameters) - val requestBuilder = PostgrestRequestBuilder(config.propertyConversionMethod).apply(request) + val requestBuilder = RpcPostgrestRequestBuilder(config.defaultSchema, config.propertyConversionMethod).apply(request) val urlParams = buildMap { putAll(requestBuilder.params.mapToFirstValue()) - if(method != RpcMethod.POST) { + if(requestBuilder.method != RpcMethod.POST) { putAll(encodedParameters.jsonObject.mapValues { it.value.toString() }) } } val rpcRequest = RpcRequest( - method = method.httpMethod, + method = requestBuilder.method.httpMethod, count = requestBuilder.count, urlParams = urlParams, - body = encodedParameters + body = encodedParameters, + schema = requestBuilder.schema, + headers = requestBuilder.headers.build() ) return RestRequestExecutor.execute(postgrest = this, path = "rpc/$function", request = rpcRequest) } @@ -65,20 +67,20 @@ suspend inline fun Postgrest.rpc( * Executes a database function * * @param function The name of the function - * @param method The HTTP method to use. Default is POST * @param request Filter the result * @throws RestException or one of its subclasses if the request failed */ suspend inline fun Postgrest.rpc( function: String, - method: RpcMethod = RpcMethod.POST, - request: PostgrestRequestBuilder.() -> Unit = {} + request: RpcPostgrestRequestBuilder.() -> Unit = {} ): PostgrestResult { - val requestBuilder = PostgrestRequestBuilder(config.propertyConversionMethod).apply(request) + val requestBuilder = RpcPostgrestRequestBuilder(config.defaultSchema, config.propertyConversionMethod).apply(request) val rpcRequest = RpcRequest( - method = method.httpMethod, + method = requestBuilder.method.httpMethod, count = requestBuilder.count, - urlParams = requestBuilder.params.mapToFirstValue() + urlParams = requestBuilder.params.mapToFirstValue(), + schema = requestBuilder.schema, + headers = requestBuilder.headers.build() ) return RestRequestExecutor.execute(postgrest = this, path = "rpc/$function", request = rpcRequest) } \ No newline at end of file diff --git a/Postgrest/src/commonMain/kotlin/io/github/jan/supabase/postgrest/query/PostgrestQueryBuilder.kt b/Postgrest/src/commonMain/kotlin/io/github/jan/supabase/postgrest/query/PostgrestQueryBuilder.kt index 80e55ef92..264cda4d0 100644 --- a/Postgrest/src/commonMain/kotlin/io/github/jan/supabase/postgrest/query/PostgrestQueryBuilder.kt +++ b/Postgrest/src/commonMain/kotlin/io/github/jan/supabase/postgrest/query/PostgrestQueryBuilder.kt @@ -8,6 +8,9 @@ import io.github.jan.supabase.gotrue.PostgrestFilterDSL import io.github.jan.supabase.postgrest.Postgrest import io.github.jan.supabase.postgrest.executor.RestRequestExecutor import io.github.jan.supabase.postgrest.mapToFirstValue +import io.github.jan.supabase.postgrest.query.request.InsertPostgrestRequestBuilder +import io.github.jan.supabase.postgrest.query.request.SelectPostgrestRequestBuilder +import io.github.jan.supabase.postgrest.query.request.UpsertPostgrestRequestBuilder import io.github.jan.supabase.postgrest.request.DeleteRequest import io.github.jan.supabase.postgrest.request.InsertRequest import io.github.jan.supabase.postgrest.request.SelectRequest @@ -30,8 +33,7 @@ class PostgrestQueryBuilder( * Executes vertical filtering with select on [table] * * @param columns The columns to retrieve, defaults to [Columns.ALL]. You can also use [Columns.list], [Columns.type] or [Columns.raw] to specify the columns - * @param head If true, no body will be returned. Useful when using count. - * @param request Additional filtering to apply to the query + * @param request Additional configurations for the request including filters * @return PostgrestResult which is either an error, an empty JsonArray or the data you requested as an JsonArray * @throws RestException or one of its subclasses if receiving an error response * @throws HttpRequestTimeoutException if the request timed out @@ -39,14 +41,13 @@ class PostgrestQueryBuilder( */ suspend inline fun select( columns: Columns = Columns.ALL, - head: Boolean = false, - request: @PostgrestFilterDSL PostgrestRequestBuilder.() -> Unit = {} + request: @PostgrestFilterDSL SelectPostgrestRequestBuilder.() -> Unit = {} ): PostgrestResult { - val requestBuilder = postgrestRequest(postgrest.config.propertyConversionMethod) { + val requestBuilder = SelectPostgrestRequestBuilder(postgrest.config.propertyConversionMethod).apply { request(); params["select"] = listOf(columns.value) } val selectRequest = SelectRequest( - head = head, + head = requestBuilder.head, count = requestBuilder.count, urlParams = requestBuilder.params.mapToFirstValue(), schema = schema, @@ -57,38 +58,28 @@ class PostgrestQueryBuilder( /** * Perform an UPSERT on the table or view. Depending on the column(s) passed - * to [onConflict], [upsert] allows you to perform the equivalent of + * to [UpsertPostgrestRequestBuilder.onConflict], [upsert] allows you to perform the equivalent of * `[insert] if a row with the corresponding onConflict columns doesn't * exist, or if it does exist, perform an alternative action depending on - * [ignoreDuplicates]. + * [UpsertPostgrestRequestBuilder.ignoreDuplicates]. * * By default, upserted rows are not returned. To return it, call `[PostgrestRequestBuilder.select]`. * * @param values The values to insert, will automatically get serialized into json. - * @param request Additional filtering to apply to the query - * @param onConflict Comma-separated UNIQUE column(s) to specify how - * duplicate rows are determined. Two rows are duplicates if all the - * `onConflict` columns are equal. - * @param defaultToNull Make missing fields default to `null`. - * Otherwise, use the default value for the column. This only applies when - * inserting new rows, not when merging with existing rows under - * @param ignoreDuplicates If `true`, duplicate rows are ignored. If `false`, duplicate rows are merged with existing rows. + * @param request Additional configurations for the request including filters * @throws RestException or one of its subclasses if receiving an error response * @throws HttpRequestTimeoutException if the request timed out * @throws HttpRequestException on network related issues */ suspend inline fun upsert( values: List, - onConflict: String? = null, - defaultToNull: Boolean = true, - ignoreDuplicates: Boolean = false, - request: PostgrestRequestBuilder.() -> Unit = {} + request: UpsertPostgrestRequestBuilder.() -> Unit = {} ): PostgrestResult { - val requestBuilder = postgrestRequest(postgrest.config.propertyConversionMethod, request) + val requestBuilder = UpsertPostgrestRequestBuilder(postgrest.config.propertyConversionMethod).apply(request) val body = postgrest.serializer.encodeToJsonElement(values).jsonArray val columns = body.map { it.jsonObject.keys }.flatten().distinct() requestBuilder.params["columns"] = listOf(columns.joinToString(",")) - onConflict?.let { + requestBuilder.onConflict?.let { requestBuilder.params["on_conflict"] = listOf(it) } val insertRequest = InsertRequest( @@ -97,8 +88,8 @@ class PostgrestQueryBuilder( returning = requestBuilder.returning, count = requestBuilder.count, urlParams = requestBuilder.params.mapToFirstValue(), - defaultToNull = defaultToNull, - ignoreDuplicates = ignoreDuplicates, + defaultToNull = requestBuilder.defaultToNull, + ignoreDuplicates = requestBuilder.ignoreDuplicates, schema = schema, headers = requestBuilder.headers.build() ) @@ -107,52 +98,38 @@ class PostgrestQueryBuilder( /** * Perform an UPSERT on the table or view. Depending on the column(s) passed - * to [onConflict], [upsert] allows you to perform the equivalent of + * to [UpsertPostgrestRequestBuilder.onConflict], [upsert] allows you to perform the equivalent of * `[insert] if a row with the corresponding onConflict columns doesn't * exist, or if it does exist, perform an alternative action depending on - * [ignoreDuplicates]. + * [UpsertPostgrestRequestBuilder.ignoreDuplicates]. * * By default, upserted rows are not returned. To return it, call `[PostgrestRequestBuilder.select]`. * * @param value The value to insert, will automatically get serialized into json. * @param request Additional filtering to apply to the query - * @param onConflict Comma-separated UNIQUE column(s) to specify how - * duplicate rows are determined. Two rows are duplicates if all the - * `onConflict` columns are equal. - * @param defaultToNull Make missing fields default to `null`. - * Otherwise, use the default value for the column. This only applies when - * inserting new rows, not when merging with existing rows under - * @param ignoreDuplicates If `true`, duplicate rows are ignored. If `false`, duplicate rows are merged with existing rows. * @throws RestException or one of its subclasses if receiving an error response * @throws HttpRequestTimeoutException if the request timed out * @throws HttpRequestException on network related issues */ suspend inline fun upsert( value: T, - onConflict: String? = null, - defaultToNull: Boolean = true, - ignoreDuplicates: Boolean = false, - request: PostgrestRequestBuilder.() -> Unit = {} - ): PostgrestResult = upsert(listOf(value), onConflict, defaultToNull, ignoreDuplicates, request) + request: UpsertPostgrestRequestBuilder.() -> Unit = {} + ): PostgrestResult = upsert(listOf(value), request) /** * Executes an insert operation on the [table] * * @param values The values to insert, will automatically get serialized into json. * @param request Additional filtering to apply to the query - * @param defaultToNull Make missing fields default to `null`. - * Otherwise, use the default value for the column. This only applies when - * inserting new rows, not when merging with existing rows under * @throws RestException or one of its subclasses if receiving an error response * @throws HttpRequestTimeoutException if the request timed out * @throws HttpRequestException on network related issues */ suspend inline fun insert( values: List, - defaultToNull: Boolean = true, - request: PostgrestRequestBuilder.() -> Unit = {} + request: InsertPostgrestRequestBuilder.() -> Unit = {} ): PostgrestResult { - val requestBuilder = postgrestRequest(postgrest.config.propertyConversionMethod, request) + val requestBuilder = InsertPostgrestRequestBuilder(postgrest.config.propertyConversionMethod).apply(request) val body = postgrest.serializer.encodeToJsonElement(values).jsonArray val columns = body.map { it.jsonObject.keys }.flatten().distinct() requestBuilder.params["columns"] = listOf(columns.joinToString(",")) @@ -163,7 +140,7 @@ class PostgrestQueryBuilder( urlParams = requestBuilder.params.mapToFirstValue(), schema = schema, headers = requestBuilder.headers.build(), - defaultToNull = defaultToNull + defaultToNull = requestBuilder.defaultToNull ) return RestRequestExecutor.execute(postgrest = postgrest, path = table, request = insertRequest) } @@ -173,18 +150,14 @@ class PostgrestQueryBuilder( * * @param value The value to insert, will automatically get serialized into json. * @param request Additional filtering to apply to the query - * @param defaultToNull Make missing fields default to `null`. - * Otherwise, use the default value for the column. This only applies when - * inserting new rows, not when merging with existing rows under * @throws RestException or one of its subclasses if receiving an error response * @throws HttpRequestTimeoutException if the request timed out * @throws HttpRequestException on network related issues */ suspend inline fun insert( value: T, - defaultToNull: Boolean = true, - request: PostgrestRequestBuilder.() -> Unit = {} - ) = insert(listOf(value), defaultToNull, request) + request: InsertPostgrestRequestBuilder.() -> Unit = {} + ) = insert(listOf(value), request) /** * Executes an update operation on the [table]. @@ -201,7 +174,7 @@ class PostgrestQueryBuilder( crossinline update: PostgrestUpdate.() -> Unit = {}, request: PostgrestRequestBuilder.() -> Unit = {} ): PostgrestResult { - val requestBuilder = postgrestRequest(postgrest.config.propertyConversionMethod, request) + val requestBuilder = PostgrestRequestBuilder(postgrest.config.propertyConversionMethod).apply(request) val updateRequest = UpdateRequest( body = buildPostgrestUpdate(postgrest.config.propertyConversionMethod, postgrest.serializer, update), returning = requestBuilder.returning, @@ -228,7 +201,7 @@ class PostgrestQueryBuilder( value: T, request: PostgrestRequestBuilder.() -> Unit = {} ): PostgrestResult { - val requestBuilder = postgrestRequest(postgrest.config.propertyConversionMethod, request) + val requestBuilder = PostgrestRequestBuilder(postgrest.config.propertyConversionMethod).apply(request) val updateRequest = UpdateRequest( returning = requestBuilder.returning, count = requestBuilder.count, @@ -253,7 +226,7 @@ class PostgrestQueryBuilder( suspend inline fun delete( request: PostgrestRequestBuilder.() -> Unit = {} ): PostgrestResult { - val requestBuilder = postgrestRequest(postgrest.config.propertyConversionMethod, request) + val requestBuilder = PostgrestRequestBuilder(postgrest.config.propertyConversionMethod).apply(request) val deleteRequest = DeleteRequest( returning = requestBuilder.returning, count = requestBuilder.count, diff --git a/Postgrest/src/commonMain/kotlin/io/github/jan/supabase/postgrest/query/PostgrestRequestBuilder.kt b/Postgrest/src/commonMain/kotlin/io/github/jan/supabase/postgrest/query/PostgrestRequestBuilder.kt index d67e34880..e38a33e93 100644 --- a/Postgrest/src/commonMain/kotlin/io/github/jan/supabase/postgrest/query/PostgrestRequestBuilder.kt +++ b/Postgrest/src/commonMain/kotlin/io/github/jan/supabase/postgrest/query/PostgrestRequestBuilder.kt @@ -15,7 +15,7 @@ import kotlin.js.JsName * A builder for Postgrest requests. */ @PostgrestFilterDSL -class PostgrestRequestBuilder(@PublishedApi internal val propertyConversionMethod: PropertyConversionMethod) { +open class PostgrestRequestBuilder(@PublishedApi internal val propertyConversionMethod: PropertyConversionMethod) { /** * The [Count] algorithm to use to count rows in the table or view. @@ -163,11 +163,3 @@ class PostgrestRequestBuilder(@PublishedApi internal val propertyConversionMetho } -@SupabaseInternal -inline fun postgrestRequest(propertyConversionMethod: PropertyConversionMethod = PropertyConversionMethod.CAMEL_CASE_TO_SNAKE_CASE, block: PostgrestRequestBuilder.() -> Unit): PostgrestRequestBuilder { - val filter = PostgrestRequestBuilder(propertyConversionMethod) - filter.block() - return filter -} - - diff --git a/Postgrest/src/commonMain/kotlin/io/github/jan/supabase/postgrest/query/request/InsertPostgrestRequestBuilder.kt b/Postgrest/src/commonMain/kotlin/io/github/jan/supabase/postgrest/query/request/InsertPostgrestRequestBuilder.kt new file mode 100644 index 000000000..f0d07abce --- /dev/null +++ b/Postgrest/src/commonMain/kotlin/io/github/jan/supabase/postgrest/query/request/InsertPostgrestRequestBuilder.kt @@ -0,0 +1,19 @@ +package io.github.jan.supabase.postgrest.query.request + +import io.github.jan.supabase.postgrest.PropertyConversionMethod +import io.github.jan.supabase.postgrest.query.PostgrestQueryBuilder +import io.github.jan.supabase.postgrest.query.PostgrestRequestBuilder + +/** + * Request builder for [PostgrestQueryBuilder.insert] + */ +open class InsertPostgrestRequestBuilder(propertyConversionMethod: PropertyConversionMethod): PostgrestRequestBuilder(propertyConversionMethod) { + + /** + * Make missing fields default to `null`. + * Otherwise, use the default value for the column. This only applies when + * inserting new rows, not when merging with existing rows under + */ + var defaultToNull: Boolean = true + +} \ No newline at end of file diff --git a/Postgrest/src/commonMain/kotlin/io/github/jan/supabase/postgrest/query/request/RpcPostgrestRequestBuilder.kt b/Postgrest/src/commonMain/kotlin/io/github/jan/supabase/postgrest/query/request/RpcPostgrestRequestBuilder.kt new file mode 100644 index 000000000..69ce0f0c0 --- /dev/null +++ b/Postgrest/src/commonMain/kotlin/io/github/jan/supabase/postgrest/query/request/RpcPostgrestRequestBuilder.kt @@ -0,0 +1,24 @@ +package io.github.jan.supabase.postgrest.query.request + +import io.github.jan.supabase.postgrest.Postgrest +import io.github.jan.supabase.postgrest.PropertyConversionMethod +import io.github.jan.supabase.postgrest.RpcMethod +import io.github.jan.supabase.postgrest.query.PostgrestRequestBuilder +import io.github.jan.supabase.postgrest.rpc + +/** + * Request builder for [Postgrest.rpc] + */ +class RpcPostgrestRequestBuilder(defaultSchema: String, propertyConversionMethod: PropertyConversionMethod): PostgrestRequestBuilder(propertyConversionMethod) { + + /** + * The HTTP method to use. Default is POST + */ + var method: RpcMethod = RpcMethod.POST + + /** + * The database schema + */ + var schema: String = defaultSchema + +} \ No newline at end of file diff --git a/Postgrest/src/commonMain/kotlin/io/github/jan/supabase/postgrest/query/request/SelectPostgrestRequestBuilder.kt b/Postgrest/src/commonMain/kotlin/io/github/jan/supabase/postgrest/query/request/SelectPostgrestRequestBuilder.kt new file mode 100644 index 000000000..fbffce219 --- /dev/null +++ b/Postgrest/src/commonMain/kotlin/io/github/jan/supabase/postgrest/query/request/SelectPostgrestRequestBuilder.kt @@ -0,0 +1,17 @@ +package io.github.jan.supabase.postgrest.query.request + +import io.github.jan.supabase.postgrest.PropertyConversionMethod +import io.github.jan.supabase.postgrest.query.PostgrestQueryBuilder +import io.github.jan.supabase.postgrest.query.PostgrestRequestBuilder + +/** + * Request builder for [PostgrestQueryBuilder.select] + */ +class SelectPostgrestRequestBuilder(propertyConversionMethod: PropertyConversionMethod): PostgrestRequestBuilder(propertyConversionMethod) { + + /** + * If true, no body will be returned. Useful when using count. + */ + var head: Boolean = false + +} \ No newline at end of file diff --git a/Postgrest/src/commonMain/kotlin/io/github/jan/supabase/postgrest/query/request/UpsertPostgrestRequestBuilder.kt b/Postgrest/src/commonMain/kotlin/io/github/jan/supabase/postgrest/query/request/UpsertPostgrestRequestBuilder.kt new file mode 100644 index 000000000..2ec99f15d --- /dev/null +++ b/Postgrest/src/commonMain/kotlin/io/github/jan/supabase/postgrest/query/request/UpsertPostgrestRequestBuilder.kt @@ -0,0 +1,24 @@ +package io.github.jan.supabase.postgrest.query.request + +import io.github.jan.supabase.postgrest.PropertyConversionMethod +import io.github.jan.supabase.postgrest.query.PostgrestQueryBuilder +import io.github.jan.supabase.postgrest.query.PostgrestRequestBuilder + +/** + * Request builder for [PostgrestQueryBuilder.upsert] + */ +class UpsertPostgrestRequestBuilder(propertyConversionMethod: PropertyConversionMethod): InsertPostgrestRequestBuilder(propertyConversionMethod) { + + /** + * Comma-separated UNIQUE column(s) to specify how + * duplicate rows are determined. Two rows are duplicates if all the + * `onConflict` columns are equal. + */ + var onConflict: String? = null + + /** + * If `true`, duplicate rows are ignored. If `false`, duplicate rows are merged with existing rows. + */ + var ignoreDuplicates: Boolean = false + +} \ No newline at end of file diff --git a/Postgrest/src/commonMain/kotlin/io/github/jan/supabase/postgrest/request/RpcRequest.kt b/Postgrest/src/commonMain/kotlin/io/github/jan/supabase/postgrest/request/RpcRequest.kt index d4ab3dc0e..fdd9a3094 100644 --- a/Postgrest/src/commonMain/kotlin/io/github/jan/supabase/postgrest/request/RpcRequest.kt +++ b/Postgrest/src/commonMain/kotlin/io/github/jan/supabase/postgrest/request/RpcRequest.kt @@ -1,6 +1,7 @@ package io.github.jan.supabase.postgrest.request import io.github.jan.supabase.postgrest.query.Count +import io.ktor.http.Headers import io.ktor.http.HttpMethod import kotlinx.serialization.json.JsonElement @@ -10,9 +11,10 @@ internal class RpcRequest( val count: Count? = null, override val urlParams: Map, override val body: JsonElement? = null, + override val schema: String = "public", + override val headers: Headers = Headers.Empty ) : PostgrestRequest { - override val schema: String = "" override val prefer = if (count != null) listOf("count=${count.identifier}") else listOf() } \ No newline at end of file diff --git a/Postgrest/src/commonTest/kotlin/PostgrestRequestBuilderTest.kt b/Postgrest/src/commonTest/kotlin/PostgrestRequestBuilderTest.kt index b84e13548..1ddc65858 100644 --- a/Postgrest/src/commonTest/kotlin/PostgrestRequestBuilderTest.kt +++ b/Postgrest/src/commonTest/kotlin/PostgrestRequestBuilderTest.kt @@ -1,7 +1,6 @@ import io.github.jan.supabase.postgrest.query.Count import io.github.jan.supabase.postgrest.query.Order import io.github.jan.supabase.postgrest.query.Returning -import io.github.jan.supabase.postgrest.query.postgrestRequest import io.ktor.http.HttpHeaders import kotlin.test.Test import kotlin.test.assertEquals @@ -129,4 +128,4 @@ class PostgrestRequestBuilderTest { assertEquals("application/vnd.pgrst.plan+json; for=\"application/json\"; options=analyze|verbose|settings|buffers|wal;", request.headers[HttpHeaders.Accept]) } -} \ No newline at end of file +} diff --git a/Postgrest/src/commonTest/kotlin/Utils.kt b/Postgrest/src/commonTest/kotlin/Utils.kt new file mode 100644 index 000000000..b1db90d84 --- /dev/null +++ b/Postgrest/src/commonTest/kotlin/Utils.kt @@ -0,0 +1,10 @@ +import io.github.jan.supabase.annotations.SupabaseInternal +import io.github.jan.supabase.postgrest.PropertyConversionMethod +import io.github.jan.supabase.postgrest.query.PostgrestRequestBuilder + +@SupabaseInternal +inline fun postgrestRequest(propertyConversionMethod: PropertyConversionMethod = PropertyConversionMethod.CAMEL_CASE_TO_SNAKE_CASE, block: PostgrestRequestBuilder.() -> Unit): PostgrestRequestBuilder { + val filter = PostgrestRequestBuilder(propertyConversionMethod) + filter.block() + return filter +} \ No newline at end of file diff --git a/Postgrest/src/commonTest/kotlin/io.github.jan.supabase.postgrest/request/RpcRequestTest.kt b/Postgrest/src/commonTest/kotlin/io.github.jan.supabase.postgrest/request/RpcRequestTest.kt index ba24a0e52..43787aef5 100644 --- a/Postgrest/src/commonTest/kotlin/io.github.jan.supabase.postgrest/request/RpcRequestTest.kt +++ b/Postgrest/src/commonTest/kotlin/io.github.jan.supabase.postgrest/request/RpcRequestTest.kt @@ -19,6 +19,7 @@ class RpcRequestTest { count = Count.EXACT, body = JsonArray(listOf()), urlParams = mapOf("Key1" to "Value1"), + schema = "mySchema" ) val count = (sut as RpcRequest).count @@ -31,7 +32,7 @@ class RpcRequestTest { "count=exact" ), sut.prefer ) - assertEquals("", sut.schema) + assertEquals("mySchema", sut.schema) assertEquals(mapOf("Key1" to "Value1"), sut.urlParams) assertEquals(JsonArray(listOf()), sut.body) } @@ -43,6 +44,7 @@ class RpcRequestTest { count = Count.EXACT, body = JsonArray(listOf()), urlParams = mapOf("Key1" to "Value1"), + schema = "mySchema" ) val count = (sut as RpcRequest).count assertNotNull(count) @@ -53,7 +55,7 @@ class RpcRequestTest { "count=exact" ), sut.prefer ) - assertEquals("", sut.schema) + assertEquals("mySchema", sut.schema) assertEquals(mapOf("Key1" to "Value1"), sut.urlParams) assertEquals(JsonArray(listOf()), sut.body) } @@ -65,6 +67,7 @@ class RpcRequestTest { count = null, body = JsonArray(listOf()), urlParams = mapOf("Key1" to "Value1"), + schema = "mySchema" ) val count = (sut as RpcRequest).count @@ -74,7 +77,7 @@ class RpcRequestTest { listOf( ), sut.prefer ) - assertEquals("", sut.schema) + assertEquals("mySchema", sut.schema) assertEquals(mapOf("Key1" to "Value1"), sut.urlParams) assertEquals(JsonArray(listOf()), sut.body) } @@ -86,6 +89,7 @@ class RpcRequestTest { count = null, body = null, urlParams = mapOf("Key1" to "Value1"), + schema = "mySchema" ) assertEquals("HEAD", sut.method.value) @@ -93,7 +97,7 @@ class RpcRequestTest { listOf( ), sut.prefer ) - assertEquals("", sut.schema) + assertEquals("mySchema", sut.schema) assertEquals(mapOf("Key1" to "Value1"), sut.urlParams) assertNull(sut.body) } @@ -104,6 +108,7 @@ class RpcRequestTest { count = null, body = JsonArray(listOf()), urlParams = mapOf("Key1" to "Value1"), + schema = "mySchema" ) assertEquals("POST", sut.method.value) @@ -111,7 +116,7 @@ class RpcRequestTest { listOf( ), sut.prefer ) - assertEquals("", sut.schema) + assertEquals("mySchema", sut.schema) assertEquals(mapOf("Key1" to "Value1"), sut.urlParams) assertEquals(JsonArray(listOf()), sut.body) }